scons

How to get path to the current SCons executable in a SCons script?


I'm trying to build an executable from another external SCons project to use it in my SCons build.

At first I tried to run:

Command('other_project_dir/executable', None, 'scons -C other_project_dir')

This doesn't work because SCons by default doesn't use the system PATH variable.

Even if it would work, another issue would be that is someone called my script with a custom path to SCons. The other script would still be built with the default SCons.

In conclusion, I need find out what is the path of the SCons that is currently running. Is there any method to get it, or an environment variable that stores it?


Solution

  • Currently (in version 4.3.0) SCons doesn't have a built in way to obtain its path.

    However, you don't really need any special functions. You can just use plain Python:

    import sys
    scons_path = sys.argv[0]
    
    Command('other_project_dir/executable', scons_path, '$SOURCE -C other_project_dir')
    

    Don't try to use the variable __file__. It is purposely removed by SCons.


    BTW, you should run AlwaysRun('other_project_dir/executable'). Otherwise, SCons may not rebuild the other project when it's necessary since it isn't aware of the dependencies in the other project.