[Scons-users] Provide default Import to SConscript

Hua Yanghao huayanghao at gmail.com
Fri Feb 23 13:49:14 EST 2018


Hi Gary,

On Fri, Feb 23, 2018 at 3:42 PM, Gary Oberbrunner <garyo at oberbrunner.com> wrote:
> In case folks don't know this, here are two ways to get symbols into the
> namespace that SConscripts start with:
> 1. Add them to SCons.Script  (which is automatically imported into all
> SConscripts)

This doesn't work for me, I assigned "usw_files" to
SCons.Script.usw_files right before SConscript got called:
import SCons.Script
SCons.Script.usw_files = usw_files
SConscript(...)

and removed the import from one of the SConscript file, I got below error:
Running : ./tools/scons -Q config=configs/qemu_arm_vexpress.py
NameError: name 'usw_files' is not defined:
  File "/home/hua/git/usw/SConstruct", line 38:
    usw_config(config, usw_target, target_list, verbose=V)
  File "/home/hua/git/usw/configs/qemu_arm_vexpress.py", line 176:
    main = usw_target(path, "main", "elf", prepend("firmware",
main_list), main_config, output_list, depends=bios,
target_list=target_list, verbose=verbose)
  File "/home/hua/git/usw/site_scons/usw_tools.py", line 78:
    BuildObjList(env, scons_folder, cwd, build_dir)
  File "/home/hua/git/usw/site_scons/common.py", line 86:
    env.SConscript(true_scons_file, variant_dir=variant_dir)
  File "/home/hua/git/usw/tools/scons-3.0.1/scons-local-3.0.1/SCons/Script/SConscript.py",
line 551:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/home/hua/git/usw/tools/scons-3.0.1/scons-local-3.0.1/SCons/Script/SConscript.py",
line 256:
    call_stack[-1].globals)
  File "/home/hua/git/usw/build/configs/qemu_arm_vexpress/main/firmware/common/SConscript",
line 6:
    usw_files("elf_obj", obj_files)


> 2. Put them in site_init/site_scons.py
> The site init file logic (in src/engine/SCons/Script/Main.py) prepends
> site_scons to sys.path, imports site_init.py into the SCons.Script
> namespace, as well as prepending site_scons/site_tools to the default tool
> path.
>
> Also note that in any Python file you can do 'import SCons.Script' and use
> standard SCons functions like File, Dir, Program, etc.


I tried but failed to use this method, as my usw_files function needs
to be different for different configs. this is partially to
work-around removing the "Return()" part in the SConscript file.If I
have a way to return things implicitly from SConscript file then I can
make usw_files() as a static API which can be put in site_init.py.

I tried to put a dummy function in site_init.py and indeed my
SConscript can see it and call it properly! thanks a lot for the tip.
Do you have any suggestion to make it easier to implement implicit
Return() from SConscript?


More information about the Scons-users mailing list