atom feed3 messages in org.tigris.scons.usersRe: [scons-users] Executing commands ...
FromSent OnAttachments
Michael KoehmstedtJan 18, 2005 7:22 pm 
Laurent BirtzJan 18, 2005 10:22 pm 
Michael KoehmstedtJan 19, 2005 11:27 pm 
Subject:Re: [scons-users] Executing commands post-build
From:Michael Koehmstedt (myki@gmail.com)
Date:Jan 19, 2005 11:27:55 pm
List:org.tigris.scons.users

Thank you my good fellow.

On Wed, 19 Jan 2005 01:23:01 -0500, Laurent Birtz <Laur@usherbrooke.ca> wrote:

Hi,

Is it possible to execute commands post-build? I have a command line option 'test' that when set, say as test=saw, will run the SConscript for the tests directory and build the 'saw' test.

I'd also like to be able to run the test automatically once the build is finished, but I can't seem to find a way to delay the command until after everything has been built. Can this be done?

Yes, it can. I do that to install once the build is finished. Here's a snippet of my script, I'll comment after.

Default(None);

### This function populates the build list and returns it. It's OK to call this function ### many times, it will only populate the list once. ### Flag that is true if everything should be included, regardless of the configuration. def get_build_list(all_flag):

global build_list; global build_list_init;

if build_list_init: return build_list;

build_list_init = 1;

### Include programs as needed. if (all_flag or want_snowservcore) and (not spec_build_flag or part == 'snowservcore'): SConscript('src/snowservcore/SConscript'); SConscript('src/snowservtask/SConscript'); Import('SNOWSERVCORE_TARGET', 'SNOWSERVTASK_TARGET'); build_list.append([SNOWSERVCORE_TARGET, SNOWSERVTASK_TARGET]);

if (all_flag or want_snowclicore) and (not spec_build_flag or part == 'snowclicore'): SConscript('src/snowclicore/SConscript'); SConscript('src/snowclitask/SConscript'); SConscript('src/snowclistart/SConscript'); Import('SNOWCLICORE_TARGET', 'SNOWCLITASK_TARGET', 'SNOWCLISTART_TARGET'); build_list.append([SNOWCLICORE_TARGET, SNOWCLITASK_TARGET, SNOWCLISTART_TARGET]); ...

### The list of targets to build/clean/install/uninstall. build_list = [];

### True if the build_list has been initiailized. build_list_init = 0;

...

########################################################################### ### PHONY TARGETS ######################################################### ###########################################################################

...

### Build: build targets according to configuration. elif 'build' in COMMAND_LINE_TARGETS: Alias("build", get_build_list(0));

### Clean: clean built targets. elif 'clean' in COMMAND_LINE_TARGETS: Alias("clean", get_build_list(1) + get_unix_install_target()); SetOption("clean", 1); do_clean_up(0);

### Install: install targets at the location specified. elif 'install' in COMMAND_LINE_TARGETS:

### Use this when CVS version gets out. #AlwaysBuild(Alias("install", dep_list, installer));

### Temporary hack. dep_list = get_build_list(0) + get_unix_install_target(); Command("install", dep_list, installer);

...

### No targets specified. elif len(COMMAND_LINE_TARGETS) == 0:

### part=something specialized build. if 'part' in ARGUMENTS: Default(Alias(ARGUMENTS['part'], get_build_list(0)));

### Just print help, or build... else: Default(Command("no-target", get_build_list(0), Action("echo At the very end"))); #sys.stdout.write("\n%s\n" % help_text); #Exit(0);

scons

scons: Entering directory `/root/work/cnetcomp71' scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... g++ -o src/snowservcore/snowservcore ... echo At the very end At the very end scons: done building targets.

I use aliases to implement phony targets. That allows me to selectively include the targets I need. The get_build_list() function returns the list of targets to build. You can set the targets in that list as dependencies to the dummy target you want to build last, allowing you to execute a command at the very end.

With the CVS version of scons, AlwaysBuild(Alias("test", get_build_list(0), Action("echo At the very end"))); would do what you want I think.

With scons 0.96, it is not possible yet. I use Command in the mean time: Default(Command("test", get_build_list(0), Action("echo At the very end")));

So 'scons test' would build then run the command/function you want. It's also possible to trap the case where no target is specified, like I do above.