SCons配置文件和默认值
我有一个使用 SCons 构建的项目(以及 MinGW/gcc,具体取决于平台)。该项目依赖于其他几个库(我们称它们为 libfoo
和 libbar
),这些库可以安装在不同位置以供不同用户使用。
目前,我的 SConstruct
文件嵌入了这些库的硬编码路径(例如:C:\libfoo
)。
现在,我想向我的 SConstruct
文件添加一个配置选项,以便在另一个位置安装 libfoo
的用户(例如 C:\custom_path\libfoo
)可以执行以下操作:
> scons --configure --libfoo-prefix=C:\custom_path\libfoo
或者:
> scons --configure
scons: Reading SConscript files ...
scons: done reading SConscript files.
### Environment configuration ###
Please enter location of 'libfoo' ("C:\libfoo"): C:\custom_path\libfoo
Please enter location of 'libbar' ("C:\libfoo"): C:\custom_path\libbar
### Configuration over ###
一旦选择,这些配置选项应该写入某个文件,并在每次 scons
运行时自动重新读取。
scons
提供这样的机制吗?我将如何实现这种行为?我并没有完全掌握Python,所以即使是显而易见的(但完整的)解决方案也是受欢迎的。
谢谢。
I have a project which I build using SCons (and MinGW/gcc depending on the platform). This project depends on several other libraries (lets call them libfoo
and libbar
) which can be installed on different places for different users.
Currently, my SConstruct
file embeds hard-coded path to those libraries (say, something like: C:\libfoo
).
Now, I'd like to add a configuration option to my SConstruct
file so that a user who installed libfoo
at another location (say C:\custom_path\libfoo
) can do something like:
> scons --configure --libfoo-prefix=C:\custom_path\libfoo
Or:
> scons --configure
scons: Reading SConscript files ...
scons: done reading SConscript files.
### Environment configuration ###
Please enter location of 'libfoo' ("C:\libfoo"): C:\custom_path\libfoo
Please enter location of 'libbar' ("C:\libfoo"): C:\custom_path\libbar
### Configuration over ###
Once chosen, those configuration options should be written to some file and reread automatically every time scons
runs.
Does scons
provide such a mechanism ? How would I achieve this behavior ? I don't exactly master Python so even obvious (but complete) solutions are welcome.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SCons 有一个名为“变量”的功能。您可以对其进行设置,以便它可以轻松地从命令行参数变量中读取。因此,在您的情况下,您可以从命令行执行类似的操作:
...并且该变量将在运行之间被记住。因此,下次您只需运行 scons 时,它就会使用 LIBFOO 之前的值。
在代码中,您可以像这样使用它:
如果您确实想使用“--”样式选项,那么您可以将上面的内容与
AddOption
函数结合起来,但它更复杂。这个问题讨论了从 Variables 对象中获取值所涉及的问题而不让它们通过环境。
SCons has a feature called "Variables". You can set it up so that it reads from command line argument variables pretty easily. So in your case you would do something like this from the command line:
... and the variable would be remembered between runs. So next time you just run
scons
and it uses the previous value of LIBFOO.In code you use it like so:
If you really wanted to use "--" style options then you could combine the above with the
AddOption
function, but it is more complicated.This SO question talks about the issues involved in getting values out of the Variables object without passing them through an Environment.