如何获得SCons来替换已安装的文本文件中的文本 [英] How can I get SCons to replace text in installed text files

查看:109
本文介绍了如何获得SCons来替换已安装的文本文件中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从scons安装一些python脚本时,我希望能够替换模板变量('$(SOFTWARE_VERSION)'). scons已经具有这样的功能吗?如果没有,那么挂入scons安装过程的最佳方法是什么,这样我就可以在安装过程中做到这一点?

I'd like to be able to replace a template variable ('$(SOFTWARE_VERSION)') while installing some python scripts from scons. Does scons already have such functionality? If not, what's the best way to hook into the scons install process so I can do this during install?

推荐答案

您可以使用Substfile方法.这将获取一个输入文件,并生成一个输出文件来替换标记的变量.因此,如果您有script.py.in:

You could use the Substfile method. This takes a input file and produces an output file substituting marked variables. So if you have script.py.in:

#!/usr/bin/python
print "$SOFTWARE_VERSION"

然后,您可以使用以下SConsctruct文件生成输出:

Then you can use the following SConsctruct file to generate an output:

env = Environment(tools=['textfile'])
script_dict = {'\$SOFTWARE_VERSION': '1.0'}
env.Substfile('script.py.in', SUBST_DICT = script_dict)

您需要对字符串'\$SOFTWARE_VERSION'中的$进行转义,否则SCons会将其解释为内部环境变量.结果将是具有以下内容的文件script.py:

You need to escape the $ in the string '\$SOFTWARE_VERSION' otherwise SCons interprets it as an internal environment variable. The result would be a file script.py with this contents:

#!/usr/bin/python
print "1.0"

然后您可以使用env.Install安装此生成的替换文件.

You can then install this resulting substituted file using env.Install.

这篇关于如何获得SCons来替换已安装的文本文件中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆