gpt4 book ai didi

bazel - 在 bazel 构建中使用生成的代码

转载 作者:行者123 更新时间:2023-12-04 14:55:32 31 4
gpt4 key购买 nike

$ python gencpp.py 

此命令生成一个 cpp 文件 foo.cpp在工作目录中。

我想在 bazel 中运行此命令建之前可以包含 foo.cppcc_binarysrcs属性。

我试过的:
genrule(
name = 'foo',
outs = ['foo.cpp'],
cmd = 'python gencpp.py',
)

cc_library(
srcs = ['foo.cpp'], # tried also with :foo
...
)

declared output 'external/somelib/foo.cpp' was not created by genrule. This is probably because the genrule actually didn't create this output, or because the output was a directory and the genrule was run remotely (note that only the contents of declared file outputs are copied from genrules run remotely).



我知道有一个解决方案需要 gencpp.py稍作修改,但这不是我要找的。

最佳答案

This command generates a cpp file foo.cpp in the working directory.



我建议您更改此设置,以便:
  • 您将输出写入由命令行标志指定的文件
  • 您将输出写入标准输出,并将标准输出重定向到文件

  • 那么您的 genrule 命令可以是:
    python gencpp.py --outputFile=$@

    或者
    python gencpp.py > $@

    (我个人的一般偏好是后者,尽管在需要写入多个输出的情况下不能使用。)

    分别。

    Ulf Adams指出:

    Bazel runs multiple actions in parallel, and if the same rule is a dependency of a tool as well as of an app, it may try to run both at the same time, and they'd overwrite each other, with potentially very bad results.



    因此,最好避免编写 bazel 不直接了解的输出文件。

    关于bazel - 在 bazel 构建中使用生成的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42251106/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com