Waf:如何输出生成的文件?

发布于 2024-12-20 13:43:04 字数 384 浏览 4 评论 0原文

我有一个文件,在通过 python 脚本推送后,我想将其发送到构建目录。我该如何在 waf 中执行此操作?

例如,如果我有一个这样的文件:

VERSION=%%VERSION%%
DATADIR=%%DATADIR%%

在将其输出到 waf 构建目录之前想要替换 %%VERSION%% 和 %%DATADIR%%,我该怎么做?

我知道这大概是这样的:

ctx(rule='???'
 source='versionfile.ver', 
 target='versionfile.out'
)

但我不知道规则是什么。

另外,一旦生成该文件,是否可以在其他任务中使用它?

I have a file I want to send to the build directory after it's been pushed through a python script. How would I do this in waf?

For example, if I had a file like this:

VERSION=%%VERSION%%
DATADIR=%%DATADIR%%

And wanted to replace %%VERSION%% and %%DATADIR%% before outputing that to the waf build directory, how would I do that?

I know it's something along the lines of:

ctx(rule='???'
 source='versionfile.ver', 
 target='versionfile.out'
)

But I don't know what the rule would be.

Also, once that file is generated, is it possible to use it in other tasks?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮生面具三千个 2024-12-27 13:43:04

如果您只是想替换输入文件,则 versionfile.ver 应该如下所示

VERSION=@VERSION@
DATADIR=@DATADIR@

现在您可以使用以下任务,以便替换值

bld.new_task_gen (
  features = "subst",
  source= "versionfile.ver",
  target= "versionfile.out",
  VERSION = bld.env['VERSION'],
  DATADIR = bld.env['DATADIR'])

要能够从 bld 访问版本,您必须在配置期间定义它

conf.env['VERSION'] = '0.7.0'

您可以找到此 waf正在执行的任务此处 的输出文件这个任务可以是用作其他任务的输入。

但是,当您想通过 python 脚本或任何可用命令传递源文件时,您可以使用以下命令:

lib_typelib = bld.new_task_gen(
  name = 'versionfile',
  source = 'versionfile.ver',
  target = 'versionfile.out',
  rule='/path/to/your/python/script ${SRC} -o ${TGT}')

还有一个可用的示例 here 在这种情况下使用 g-ir-compiler 在你的情况下将是一个 python 脚本。

If you simply want to substitute an input file your versionfile.ver should look like this

VERSION=@VERSION@
DATADIR=@DATADIR@

Now you can use the following task so the values will be substituted

bld.new_task_gen (
  features = "subst",
  source= "versionfile.ver",
  target= "versionfile.out",
  VERSION = bld.env['VERSION'],
  DATADIR = bld.env['DATADIR'])

To be able to access version from bld you have to define it during configure

conf.env['VERSION'] = '0.7.0'

You can find this waf task in action here Output files of this tasks can than be used as input for other tasks.

However when you want to pass on your source file through a python script or any command available you can use the following:

lib_typelib = bld.new_task_gen(
  name = 'versionfile',
  source = 'versionfile.ver',
  target = 'versionfile.out',
  rule='/path/to/your/python/script ${SRC} -o ${TGT}')

There is also a sample available here where in this case g-ir-compiler is used what in your case would be a python script.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文