How to add custom build report before and after the actual compilation in SCons?

190 views Asked by At

I am migrating the building of a reasonably large system to use SCons. I want to add custom build report functionality that will update a website about build status. It will post a custom message to the server indicating the starting of the job and post similar message after the finish of the job as well. But I am struggling to find the right place to place those calls.

The build system I implement should be generic, ie it should do this no matter what the build action is. It could be executing a command or running a custom function.

In the source code, I found out add custom function at _ActionAction() 's _ _call__ method will work. But I want to do this without modify the source code of SCons .

if execute:
    if chdir:
        os.chdir(chdir)
    try:
        # add custome before execution report function
        stat = self.execute(target, source, env, executor=executor)
        # add custome after execution report function 
        if isinstance(stat, SCons.Errors.BuildError):
            s = exitstatfunc(stat.status)
            if s:
                stat.status = s
            else:
                stat = s
        else:
            stat = exitstatfunc(stat)
    finally:
        if save_cwd:
            os.chdir(save_cwd)

I can probably do the pre-compile action report in PRINT_CMD_LINE_FUNC, but I didn't find anything similar for after-compile action report.

Also AddPreAction and AddAfterAction sort of do what I want, but in order for me to add report functionality for all actions, I need to know what the action objects are before I can call add pre-action and after-action for each one of them.

Thank you for your help!

1

There are 1 answers

0
dirkbaechle On BEST ANSWER

I am not a 100% sure that I'm getting what you want to accomplish. I assume that you want to define a Builder that you can call as "myenv.MyBuilder(...)", and it should go off and "do the main job". But before and after the actual command line, it should emit log/info messages.

In this case, you can try to define the "action =" keyword of your Builder as list of Actions, instead of being a single Action. The single items of your list can be either strings (the single command lines) or functions (callables), as for a single Action. The single actions are then executed sequentially, whenever the target has to get created by the Builder.