如果配置文件更改,自动重新配置 waf 项目
Automatically reconfigure waf project, if configuration files change
我有一个 wscript
,它在配置步骤中读取一些文件,并基于此设置一些变量。
如果 配置 文件之一发生更改,当 运行 waf build
而不是 waf configure build
时,如何让 waf 自动重新配置项目?
考虑以下场景:
waf configure
waf build
- 配置文件
a.config
中的内容已更改
- 用户只是运行
waf build
,而不是 waf configure build
。
--> wscript
应该是什么样子,它在 运行 build
之前检查配置文件是否已更改,如果是,则在 运行 build
?
示例:
有一个文件 a.config
并且 wscript
看起来像这样:
# wscript
def configure(conf):
a = conf.path.find_node('a.config')
conf.env.config = a.read()
def build(bld):
# check the configuration files are up to date.
# actual build
pass
configure
不是真的。您可以使用相同的代码,但在 build
:
def build(bld):
a = bld.path.find_node('a.config')
bld.env.config = a.read()
bld(features = "myfeature", vars = ["config"], ...)
你可以直接使用configure with autoconfig
:
from waflib import Configure
def options(opt):
Configure.autoconfig = True
def configure(conf):
conf.env.config = "my_value"
def my_processing(task):
print "Processing..."
def build(bld):
bld(rule = my_processing, vars = ["config"])
对 conf.env.config
的任何更改都将触发重建。
如果需要单独的配置文件,可以使用load
:
def configure(conf):
pass
def my_processing(task):
print "Processing..."
def build(bld):
bld.load("my_config", tooldir="my_config_dir")
bld(rule = my_processing, vars = ["config1", "config2"])
使用这样的 my_config_dir/my_config.py
文件:
def build(bld):
bld.env.config1 = "one"
bld.env.config2 = "two"
# ...
bld.load()
会执行 my_config.
中的 build
函数
对 config1
或 config2
的任何更改都将触发重建
我有一个 wscript
,它在配置步骤中读取一些文件,并基于此设置一些变量。
如果 配置 文件之一发生更改,当 运行 waf build
而不是 waf configure build
时,如何让 waf 自动重新配置项目?
考虑以下场景:
waf configure
waf build
- 配置文件
a.config
中的内容已更改 - 用户只是运行
waf build
,而不是waf configure build
。
--> wscript
应该是什么样子,它在 运行 build
之前检查配置文件是否已更改,如果是,则在 运行 build
?
示例:
有一个文件 a.config
并且 wscript
看起来像这样:
# wscript
def configure(conf):
a = conf.path.find_node('a.config')
conf.env.config = a.read()
def build(bld):
# check the configuration files are up to date.
# actual build
pass
configure
不是真的。您可以使用相同的代码,但在 build
:
def build(bld):
a = bld.path.find_node('a.config')
bld.env.config = a.read()
bld(features = "myfeature", vars = ["config"], ...)
你可以直接使用configure with autoconfig
:
from waflib import Configure
def options(opt):
Configure.autoconfig = True
def configure(conf):
conf.env.config = "my_value"
def my_processing(task):
print "Processing..."
def build(bld):
bld(rule = my_processing, vars = ["config"])
对 conf.env.config
的任何更改都将触发重建。
如果需要单独的配置文件,可以使用load
:
def configure(conf):
pass
def my_processing(task):
print "Processing..."
def build(bld):
bld.load("my_config", tooldir="my_config_dir")
bld(rule = my_processing, vars = ["config1", "config2"])
使用这样的 my_config_dir/my_config.py
文件:
def build(bld):
bld.env.config1 = "one"
bld.env.config2 = "two"
# ...
bld.load()
会执行 my_config.
build
函数
对 config1
或 config2
的任何更改都将触发重建