测试目标是否存在
我有一个 SCons 文件,它调用其他人构建程序的不同变体。 遗憾的是,其中一些变体(又名较低的 SConscript)需要通过调用外部程序来构建库。
# /SConstruct
<...>
subdirs = ['variant1', 'variant2', 'variant3']
for subdir in subdirs:
SConscript(dirs=subdir, src_dir=subdir)
# /variant1/SConscript
localEnv = env.Clone() # Duplicates the global Environment so we may modify it without problems
localEnv.Command('../libs/generated.so', '', 'someexternalscript')
<...>
# /variant2/SConscript
localEnv = env.Clone() # Duplicates the global Environment so we may modify it without problems
localEnv.Command('../libs/generated.so', '', 'someexternalscript')
<...>
这给出了警告:
scons: warning: Two different environments were specified for target ../libs/generated.so
but they appear to have the same action: someexternalscript
这当然是正确的,但我不知道如何检查变体 SConscripts 中是否存在目标。 由于其他人稍后可能会调用 SConscripts,因此我不能依赖全局变量的存在。
I have a SCons file which calls others to build different variants of a program.
Sadly a few of these variants (AKA lower SConscripts) need to build a library via invoking an external program.
# /SConstruct
<...>
subdirs = ['variant1', 'variant2', 'variant3']
for subdir in subdirs:
SConscript(dirs=subdir, src_dir=subdir)
# /variant1/SConscript
localEnv = env.Clone() # Duplicates the global Environment so we may modify it without problems
localEnv.Command('../libs/generated.so', '', 'someexternalscript')
<...>
# /variant2/SConscript
localEnv = env.Clone() # Duplicates the global Environment so we may modify it without problems
localEnv.Command('../libs/generated.so', '', 'someexternalscript')
<...>
This gives the warnings:
scons: warning: Two different environments were specified for target ../libs/generated.so
but they appear to have the same action: someexternalscript
Which is of course correct, but I don't know how I can check for a target's existence in the variant SConscripts.
And since others may call the SConscripts later on I cannot rely on global variables being present.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
很难知道您是否真的认为 ../libs/ generated.so 是构建的一部分。
如果这是一个您希望存在于构建之外的库,但您想确定一下。我建议您使用“配置”来确保该库存在,如果不存在,您可能会失败或运行某些外部脚本来纠正这种情况。
实际上如何 make_ generated_so() 取决于您想要如何执行它,您可以将其作为构建的一部分,或者只是在此处的配置阶段运行 shell 脚本。
另一方面,如果您将 ../libs/ generated.so 视为构建的一部分,则必须创建此目标一次,并使依赖目标依赖于此 .so 文件,您可以通过包含 generated.so 来做到这一点节点作为
env.Program("someprogram",target)
中目标的一部分,或者只是执行env.Depends(sometarget," generated.so")
It is hard to know if you really regard the ../libs/generated.so is a part of the build or not.
If this is a library you expect to exist outside of the build, but you want to make sure. I suggest you use the Configure to make sure that the library exist, and if not you might fail or run the someexternalscript to remedy the situation.
How you actually make_generated_so() depends on how you want to do it, you might make it a part of your build or just run the shell script during the config phase here.
If you on the other hand regard the ../libs/generated.so as a part of the build you must create this target once, and make the depending targets depend on this .so file you might do this by including the generated.so node as a part of targets in the
env.Program("someprogram",target)
or just doenv.Depends(sometarget,"generated.so")
因此,SConscript1 将构建:../libs/ generated.so,而 SConscript2 将构建相同的 ../libs/ generated.so - 相同的目标文件。
您不能使用 2 个相同的目标(SConscript1 和 SConscript2 中的 ../libs/ generated.so )。您必须为 SConscripts 中的命令之一指定不同的目标。例如,对于 SConscript2 命令(../libs/ generated2.so.
为什么需要检查它?如果 scons 检测到目标需要构建,则会构建它。如果任何源文件发生更改,您还可以为运行命令设置额外的依赖项来生成 .so。
为了测试现有目标,您可以使用 scons 类文件:
但是,我确信 - 如果您两次构建相同的目标,您会得到错误的 Sconscripts。
So, SConscript1 will build : ../libs/generated.so, and SConscript2 will build same ../libs/generated.so - same target file.
You can't use 2 same targets (../libs/generated.so in SConscript1 and SConscript2). You must specify different target for one of Command in SConscripts. For example for SConscript2 Command(../libs/generated2.so.
Why you need to check it? If scons detects target need to build it would be build. You also can set additional dependecy for run Command to generate .so if any of source files would be changed.
For test existing target you may use scons class File:
But, i'm sure - you have wrong Sconscripts if you build same target twice.
在这种情况下,我不会克隆该特定进程的环境。我认为您不需要在您的示例中这样做,因为该命令不会更改 env 中的任何内容。之后您可以克隆。
如果这个目标最终被不同的 SConscript 调用,并且它们的环境已经克隆,那么有一个可用于此目的的单一环境。
In this situation, I do not clone the environment for this particular process. And I don't think you need to in your example, as that Command does not change anything in env. You can clone afterwards.
If this target ends up being called from different SConscripts, with their env already cloned, have a single environment accessible for this purpose.
如果这确实是代码,我会看到两种删除警告的方法:
另请注意,实际上没有两个 SConscript(一个在variant1中,一个在variant2中,它是相同的SConscript。
第一个:在克隆之前调用一些外部脚本:
其次:添加一些条件逻辑并通过 SConscript 调用传递一个标志:
最后:如果您总是希望调用此脚本,则可以将调用放在在S构造中另外
,为什么将目标的源列为“”?
该目标永远不会改变,至少源应该是某个外部脚本。
If this is literally the code, I see two ways to remove the warning:
Also note, there really isn't two SConscripts (one in variant1, and one in variant2, its the same SConscript.
First: Call some externalscript before the clone:
Secondly: add some conditional logic and pass a flag via SConscript call:
Lastly: if you always want this script called, you can put the call in SConstruct itself.
Additionally, why list the source for the target as ''?
That target will never changed, at the very least the source should be someexternalscript