How to run code after every build in scons?

I am looking for a way to register somthing as a build completion callback in scons. For example, now I am doing something like this:

def print_build_summary(): failures = SCons.Script.GetBuildFailures() notifyExe = 'notify-send ' if len(failures) > 0: notifyExe = notifyExe + ' --urgency=critical Build Failed' else: notifyExe = notifyExe + ' --urgency=normal Build Succeed' os.system(notifyExe) atexit.register(print_build_summary) 

This only works in non-interactive mode. I would like something like this to appear at the end of each build, in particular when I run several build commands in an interactive session.

The only suggestions that I found looking around seemed to be to use the dependency system or the AddPostAction call for glom this on. It seems to me that this is not so, because it is not a real dependency (it is not even part of the assembly, strictly speaking) - it is just a static bit of code that needs to be run at the end of each assembly.

Thanks!

+4
source share
2 answers

I do not think that something is wrong using the dependency system to solve this problem. So I usually do this:

 def finish( target, source, env ): raise Exception( 'DO IT' ) finish_command = Command( 'finish', [], finish ) Depends( finish_command, DEFAULT_TARGETS ) Default( finish_command ) 

This creates a command that depends on the default goals for its execution (so you know that it will always work last - see DEFAULT_TARGETS in the scons manual). Hope this helps.

+6
source

I looked at it and havent found that SCons offers everything that helps. This seems like a pretty useful feature, maybe SCons developers are watching these threads and will accept the offer ...

I looked at the source code and figured out how to do it. I will try to suggest this change to the SCons developers at scons.org.

If you are interested, the file is engine/SCons/Script/Main.py , and the function is _build_targets() . At the end of this function, you just need to add the call to the user-provided callback. Of course, this solution would not be very useful if you built several different machines on your network, since you will have to transfer the changes wherever you need it, but if you are building only one machine, maybe you can make changes for now / if SCons will not formally provide a solution.

Let me know if you need help implementing the change and I'll see what I can do.

Another option is to wrap the call for SCons and have the shell script complete the required actions, but this will not help in interactive mode of SCons.

Hope this helps,

Brady

EDIT

I am creating a function request for this: http://scons.tigris.org/issues/show_bug.cgi?id=2834

+1
source

Source: https://habr.com/ru/post/945087/


All Articles