Wednesday, January 9, 2008

How to run mktrigger in post_mkstream trigger

As we know that mktrigger must be fired in a view context. However, sometimes we need to run mktrigger even though there is no view yet. For example, in my post_mkstream trigger, I want to attach a no_mkactivity trigger to the newly created stream.

cleartool mktrtype -ucm -postop mkstream -nc -execu "cleartool mktrigger no_mkactivity stream:\$CLEARCASE_STREAM" -execw "cleartool mktrigger no_mkactivity stream:%CLEARCASE_STREAM%" post_mkstream

However, when a developer joins the project to create his development stream my_dev_str, the post_mkstream trigger reports "unable to determine view for my_dev_str: no such file or direcotry". That's because he does not have any view yet. Even if he has a view, the view may not be started, or the current directory may not be under the view root.


Workaround.
Create a view that is available to everyone. Set to the view before call mktrigger in post_mkstream trigger.

cleartool mktrtype -ucm -postop mkstream -nc -execw "ccperl \\\\scm\\admin\\post_mkstream.pl" -execu "/ccstore/admin/post_mkstream_unix.pl" post_mkstream


A simplified version of the post_mkstream.pl script.

#!/usr/bin/perl

$stream = $ENV{"CLEARCASE_STREAM"};

$rst = `cleartool mount \\CBFEProjects`;
$rst = `cleartool startview ccadmin_view`;
chdir "m:\\ccadmin_view\\CBFEProjects";
$rst = `cleartool mktrigger no_mkactivity@\\CBFEProjects stream:$stream`;
$rst = `cleartool endview ccadmin_view`;
exit 0;