【发布时间】:2019-09-20 22:24:16
【问题描述】:
我正在尝试在 bazel 项目中构建子模块的 Makefile。我看到 bazel 确实提供了 genrule 来执行 bash 命令。我目前面临两个问题 -
1.如何在执行命令之前进入目录,例如 -
genrule(
name = "hello-make",
srcs = ["hello"] + glob(["hello/**"]),
outs = ["hello/main"],
cmd = "(cd $(location :hello) && make)",
)
2。如何在执行 genrule 之前更新更新子模块?
添加cmd = "(git submodule init && git submodule update)" 得到fatal: Not a git repository (or any of the parent directories): .git
重现步骤:
git clone git@github.com:bazelbuild/examples.gitcd examples/ && git submodule add git@github.com:mucsi96/cpp-hello-world.git cpp-tutorial/stage1/main/hellocd cpp-tutorial/stage1/ && bazel build //main:hello-world
在这一步之后,我想添加一个允许我初始化、更新和制作 hello 子模块的规则。
有没有比将git@github.com:mucsi96/cpp-hello-world.git 创建为git clone git@github.com:bazelbuild/examples.git 的子模块更好的方法来构建git@github.com:mucsi96/cpp-hello-world.git?
实际项目比较复杂,为 cpp-hello-world.git 创建 BUILD 文件是不可行的。
【问题讨论】:
-
也许this 是一个半有用的例子——有些东西
$(location ...)? -
谢谢,是的,我希望逐步解决这个问题。我得到
$(location) expression is not a declared prerequisite of this rule使用cd ./$(location hello) -
您需要引用已声明的名称之一——例如如果您有
srcs = ["foo.txt"] + glob(["*.json]),,那么您可以参考$(location :foo.txt)等。也许明确列出您的来源,或者至少列出其中一个(Makefile)?