Bazel:看来“target\u compatible\u with”对py\u二进制文件不起作用

2024-06-07 09:28:20 发布

您现在位置:Python中文网/ 问答频道 /正文

src/sample/BUILD.bazel:

cc_binary(
  name = "example",
  srcs = ["main.cpp"],
  deps = select({
    "//:foo_0", ["mydeps"],
    "//:foo_1", None,
  }),
)

my_new_rule(
  name = "mydeps",
  src = glop("/**/*.dat"),
  target_compatible_with = ["//:foo_0"],
)

我的规则/废话/身材

load("@rules_python/python:defs.bzl", "py_binary")

py_binary(
  name = "gen",
  srcs = ["test.py"],
  main = ["test.py"],
  visibility = ["//visibility:public"],
)

我的规则/blah/defs.bzl

def _my_new_rule_impl(ctx):
  # some implementation...
  ctx.actions.run(
    mnemonic = "...",
    executable = ctx.executable._gen
    ...
  )

  return ....

my_new_rule = rule(
  implementation = _my_new_rule_impl,
  attrs = {
    "_gen": attr.label(
      default = Label("//blah:gen"),
      ...
    ),
  },
)

我尝试在两个平台上构建上述内容。一个平台有test.py,另一个平台没有test.py。 并且,具有test.py的平台用//:foo_0指定,另一个平台用//:foo_1指定。 在上面的例子中,即使我将配置指定为启用//:foo_0(并禁用//:foo_1),Bazel似乎也会尝试查找test.py是否存在。并且,操作(如build、cquery等)失败,如Not found test.py。 我该怎么办


Tags: namepytestsrcnewfoomainmy

热门问题