Bazel构建系统的新功能。
我想从py_library中的文件创建一个py_binary,它是从http_archive创建的。
目前我有:
WORKSPACE
:
new_http_archive(
name = "cpplint_archive",
url = "https://pypi.python.org/packages/source/c/cpplint/cpplint-1.2.2.tar.gz",
sha256 = "b2979ff630299293f23c52096e408f2b359e2e26cb5cdf24aed4ce53e4293468",
build_file = "cpplint.BUILD",
strip_prefix = "cpplint-1.2.2"
)
cpplint.BUILD
:
py_library(
name = "cpplint",
srcs = glob(["*.py"]),
visibility = ['//visibility:public']
)
src/BUILD
:
py_binary(
name = "lint",
main = ":cpplint/cpplint.py",
srcs = [":cpplint/cpplint.py"],
deps = [
"@cpplint_archive//:cpplint"
]
)
srcs中的路径是一个主要的错误,给出了#34;没有这样的包&c; cpplint / cpplint.py'"当我跑bazel run src/lint
时。我无法弄清楚如何引用库中包含的文件。
答案 0 :(得分:2)
您可以将py_binary
规则直接放入cpplint.BUILD
:
py_binary(
name = "cpplint",
srcs = ["cpplint.py"],
)
然后像这样构建它:
$ bazel build @cpplint_archive//:cpplint
INFO: Found 1 target...
Target @cpplint_archive//:cpplint up-to-date:
bazel-bin/external/cpplint_archive/cpplint
INFO: Elapsed time: 2.327s, Critical Path: 0.01s
如果您确实希望py_binary
规则位于主存储库中,您可以执行以下操作:
cpplint.BUILD
:
exports_files(["cpplint.py"])
BUILD
:
py_binary(
name = "cpplint",
srcs = ["@cpplint_archive//:cpplint.py"],
)
但从其他软件包中提取文件通常不太好。