我在這個場景中有一個「Parent」Bazel項目,其中包含一些shell腳本&宏。該項目必須由「兒童」項目重複使用。最小的 「工作」 的例子來重現問題定義如下:爲父項目和子項目導出的shell腳本
目錄結構
├── Child
│ ├── BUILD
│ └── WORKSPACE
└── Parent
├── a_command.bzl
├── a_script.sh
├── BUILD
└── WORKSPACE
父項目文件
父/ a_script.sh
#!/bin/bash
date
父/ a_command.bzl
def a_command(name):
native.genrule(
name = name,
srcs = [],
outs = [name+".txt"],
cmd = "$(location :a_script_sh) > [email protected]",
tools = [":a_script_sh"],
)
父/ BUILD
sh_binary(
name = "a_script_sh",
srcs = ["a_script.sh"],
visibility = ["//visibility:public"],
)
父/工作區
# empty file
兒童的項目文件
兒童/工作區
local_repository(
name = "Parent",
path = "../Parent/",
)
兒童/ BUILD
load("@Parent//:a_command.bzl","a_command")
# Uncomment me for a working solution
# alias(name="a_script_sh",actual="@Parent//:a_script_sh")
a_command("use_script")
現在我的問題
如果我在兒童項目目錄鍵入
bazel build //...
我得到
INFO: Found 1 target...
ERROR: missing input file '//:a_script_sh'.
ERROR: PATH/Child/BUILD:5:1: //:use_script: missing input file '//:a_script_sh'.
Target //:use_script failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: PATH/Child/BUILD:5:1 1 input file(s) do not exist.
INFO: Elapsed time: 0.162s, Critical Path: 0.00s
現在,如果我取消對該行
alias(name="a_script_sh",actual="@Parent//:a_script_sh")
在
兒童
/BUILD文件,一切正常:
INFO: Found 2 targets...
INFO: Elapsed time: 0.191s, Critical Path: 0.03s
而文件use_script.txt已正確生成兒童/ bazel-genfiles目錄。
我的問題是:
是否使用的
alias(name="a_script_sh",actual="@Parent//:a_script_sh")
是正確的方式做的事情嗎?
我曾期待這是巴澤爾的工作,以解決這種依賴。
我沒想到有明確重新定義其中a_script.sh文件。我認爲這很尷尬,多餘且容易出錯。
我懷疑我沒有做正確的事情,我會非常感謝任何能清楚地向我們解釋如何正確做到這一點的人。
感謝您的積極反饋和解釋。正如你自己寫的那樣:宏被擴展到使用它的地方(它畢竟只是一個宏:-)),並且我們不能在//::a_script_sh前綴,因爲我們不知道Child項目中的未來邊界。就像我在學習巴澤爾一樣,我擔心我錯過了什麼......再次感謝 –