bazel pypi宏自边缘
bazel pypi macro self-edge
我正在努力让 bazel 与 pypi 依赖项一起工作。
./pypi.bzl:
def _impl(ctx):
ctx.actions.run_shell(
command = "pip download %s" % ctx.package
)
_pypi_package = rule(
implementation=_impl,
attrs={"package": attr.label(mandatory=True)},
)
def pypi_package(package):
_pypi_package(name = package, package = package)
./构建:
py_binary(
name = "app",
srcs = ["app.py"],
deps = [":python-dateutil"]
)
load("//:pypi.bzl", "pypi_package")
pypi_package(
package="python-dateutil",
)
正在尝试构建:
$ bazel build app
ERROR: /path/to/cwd/BUILD:9:1: in _pypi_package rule //:python-dateutil: cycle in dependency graph:
//:app
.-> //:python-dateutil [self-edge]
`--
This cycle occurred because of a configuration option.
ERROR: Analysis of target '//:app' failed; build aborted.
INFO: Elapsed time: 0.219s
不知道这是否是处理外部依赖项的正确方法,但忽略了这一点,我不明白这里的 self-dep 是从哪里来的。事实上,我根本没有看到我在为 pypi_package
规则声明任何依赖项。怎么回事?
问题是 attr.label
:"label" 这里表示 BUILD 标签。我应该一直在使用 attr.string
.
我正在努力让 bazel 与 pypi 依赖项一起工作。
./pypi.bzl:
def _impl(ctx):
ctx.actions.run_shell(
command = "pip download %s" % ctx.package
)
_pypi_package = rule(
implementation=_impl,
attrs={"package": attr.label(mandatory=True)},
)
def pypi_package(package):
_pypi_package(name = package, package = package)
./构建:
py_binary(
name = "app",
srcs = ["app.py"],
deps = [":python-dateutil"]
)
load("//:pypi.bzl", "pypi_package")
pypi_package(
package="python-dateutil",
)
正在尝试构建:
$ bazel build app
ERROR: /path/to/cwd/BUILD:9:1: in _pypi_package rule //:python-dateutil: cycle in dependency graph:
//:app
.-> //:python-dateutil [self-edge]
`--
This cycle occurred because of a configuration option.
ERROR: Analysis of target '//:app' failed; build aborted.
INFO: Elapsed time: 0.219s
不知道这是否是处理外部依赖项的正确方法,但忽略了这一点,我不明白这里的 self-dep 是从哪里来的。事实上,我根本没有看到我在为 pypi_package
规则声明任何依赖项。怎么回事?
问题是 attr.label
:"label" 这里表示 BUILD 标签。我应该一直在使用 attr.string
.