2

i am using scons build tool with renesas compiler.

I want to know the exit status of SCONS when the build terminated with an error.

When scons executed the project successfully it will return 0. How to get the exit status or number to check the erros.

Is there any function in python to get them.

Thanks

2
  • How do you call SCONS from your python code? Commented May 13, 2013 at 6:50
  • In Sconstruct file I was registered a exit function. atexit.register(printExitMessages) In that exit function i want to get the exit status. Commented May 13, 2013 at 6:57

1 Answer 1

1

There is SCons.Script.Main.exit_status and SCons.script.Main.exit_status.code, however I've found them to be unreliable in practice (i.e. they often differ from the actual return code).

The actual exit code is set by calling sys.exit with the appropriate argument. It seems that the only way to access it is by replacing the original sys.exit with a wrapper:

import atexit
import sys

exit_code = None
original_exit = None

def my_exit(code=0):
    global exit_code
    exit_code = code
    original_exit(code)

original_exit = sys.exit
sys.exit = my_exit

@atexit.register
def my_exit_handler():
    print "Exit code is", exit_code

if __name__ == '__main__':
    sys.exit(1)

If you need more information in case of an error you will probably also want to use a custom wrapper for sys.excepthook. There's also SCons.Script.GetBuildFailures.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.