简体   繁体   English

在scons中使用python模块

[英]using python module in scons

I am trying to use to scons for my build environment, and the directory structure resembles something like : 我试图用scons来构建环境,并且目录结构类似于:

main_dir
main_dir/dir_A
main_dir/dir_B
main_dir/dir_C
main_dir/dirB/dir_b1
main_dir/dirB/dir_b2
main_dir/dirB/dir_b3

I have SConstruct file in the main_dir and corresponding SConscript in the subsequent directories. 我的main_dir中有SConstruct文件,后续目录中有相应的SConscript。 Inside dir_b1, dir_b2 and dir_b3 much of the build env setting is common, so i am trying to import a common python module do all that stuff and here lies the dilemma. 在dir_b1,dir_b2和dir_b3内部,很多构建环境设置都很常见,因此我试图导入一个通用的python模块来完成所有这些工作,这就是两难的地方。 Lets say dir_b1, currently i do : 可以说dir_b1,目前我正在这样做:

Import('my_env')
env = my_env.Clone()
env['ENV']['LIB_NAME'] = xxx    #unique to each dir
env['ENV']['CXX_COMPILER'] = 'yyy' #common to all

I want to move all such common stuff into my python module and leave anything specific in the dir to SConscript file. 我想将所有这些常见的东西移动到我的python模块中,并将dir中的任何特定内容保留到SConscript文件中。

How should i manage the environment variable here ? 我应该在这里如何管理环境变量?

If i clone the env variable in python module as well and set values in both the module and SConscript, will changes in both will taken by scons when doing the build ? 如果我也在python模块中克隆env变量,并在模块和SConscript中都设置了值,那么在进行构建时scons是否会同时改变两者?

The build descriptions of SCons in the SConstructs/SConscripts are read in a first "parse" phase. 在第一个“解析”阶段阅读SConstructs / SConscripts中SCons的构建说明。 In this phase, SCons collects all the informations about which Nodes to build and which Environments to use for this. 在此阶段,SCons收集所有有关要构建哪个节点以及要使用哪个环境的信息。 An Environment behaves pretty much like a dictionary (=map), in the sense that it supports the setting of certain values via a key each. 从某种意义上说,环境支持通过每个键来设置某些值,因此它的行为与字典(= map)非常相似。 For a single Environment like " my_env " in your example above, it doesn't matter where exactly this happens. 对于上面示例中的“ my_env ”这样的单个环境,确切发生在哪里都没有关系。 Regarding the Actions in the final "build" phase, assignments to the Environment are independent of whether they happen in your top-level SConstruct or some SConscript in a deeply buried subdirectory. 关于最后“构建”阶段中的操作,对环境的分配与它们是在顶级SConstruct还是在深埋子目录中的某些SConscript中发生无关。 If you assign to the same key, the last assignment wins. 如果您分配给相同的键,则最后一个分配获胜。 Only when the "parse" phase is complete, the actual "build" starts. 仅在“解析”阶段完成时,才开始实际的“构建”。

Finally, and most important, the "build" doesn't follow the order of your definitions as you gave them in the SConstructs/SConscripts, it follows the dependencies between target and source files that you defined. 最后,最重要的是,“构建”不遵循您在SConstructs / SConscripts中给出的定义顺序,而是遵循您定义的目标文件与源文件之间的依赖关系。

So you should be able to setup your common variables in the top-level SConstruct and then pass this Environment on to the SConscripts where you can Clone them, and add/change other values for this clone d Environments if required. 因此,您应该能够在顶级SConstruct中设置公用变量,然后将此环境传递给SConscripts,在其中可以Clone它们,并在需要时添加/更改此clone d Environments的其他值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM