[Scons-users] Provide default Import to SConscript

Jason Kenny dragon512 at live.com
Fri Feb 23 20:07:28 EST 2018


I added a note to the gist

Jason

From: Scons-users [mailto:scons-users-bounces at scons.org] On Behalf Of Bill Deegan
Sent: Friday, February 23, 2018 2:02 PM
To: SCons users mailing list <scons-users at scons.org>
Subject: Re: [Scons-users] Provide default Import to SConscript

Take a look at this:

https://gist.github.com/bdbaddog/1ddedecdfd13f6193c173e511e895b1f<https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgist.github.com%2Fbdbaddog%2F1ddedecdfd13f6193c173e511e895b1f&data=02%7C01%7C%7C9ba5a5679c7c4a5b9f0608d57af8502f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636550129266512092&sdata=m7ceCpui%2Bokl0dpAl4eHknRXS4my907berk28vtsiWA%3D&reserved=0>
That should work.
Forgot that by the time you're in SConstruct it's too late for this to work. (Or so it seems)
-Bill

On Fri, Feb 23, 2018 at 1:49 PM, Hua Yanghao <huayanghao at gmail.com<mailto:huayanghao at gmail.com>> wrote:
Hi Gary,

On Fri, Feb 23, 2018 at 3:42 PM, Gary Oberbrunner <garyo at oberbrunner.com<mailto: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?
_______________________________________________
Scons-users mailing list
Scons-users at scons.org<mailto:Scons-users at scons.org>
https://pairlist4.pair.net/mailman/listinfo/scons-users<https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpairlist4.pair.net%2Fmailman%2Flistinfo%2Fscons-users&data=02%7C01%7C%7C9ba5a5679c7c4a5b9f0608d57af8502f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636550129266512092&sdata=KKuECnGCQvuf3cNPOAqFj1CY84M%2B%2FYjfHj0lcK6ICwA%3D&reserved=0>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20180224/0d0cd9e6/attachment.html>


More information about the Scons-users mailing list