2017-04-12 74 views
1

一种包装包装py_binary //foo具有py_binary带参数

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

foo.py接受2个位置命令行参数。

现在在一个包//bar我想创建一个“别名”来调用foo二进制与某些参数。

以下可悲的是不起作用:

py_binary(
    name = "bar", 
    deps = [ 
    "//foo:foo", 
    ], 
    args = [ 
    "$(location first_file)", 
    "$(location second_file)", 
    ], 
    data = [ 
    ":first_file", 
    ":second_file", 
    ], 
) 

的问题是,py_binary希望在当前包的src文件。有没有其他的或更好的做这项工作?

回答

1

我解决了这个通过创建//foo:bind.bzl

def bind_foo(name, **kwargs): 
    copy_file(
     name = "%s.py.create" % name, 
     src = "//foo:foo.py", 
     dst = "%s.py" % name, # Appease local main search 
    ) # Why is no copy_file action provided by Skylark??? 

    py_binary(
     name = name, 
     srcs = [ 
      "%s.py" % name, 
     ], 
     deps = [ 
      "//foo:foo", 
     ], 
     **kwargs 
    ) 

其中在//bar我可以SIM卡层使用:

load("//foo:bind.bzl", "bind_foo") 

bind_foo(
    name = "bar", 
    args = [ 
     "$(location first_file)", 
     "$(location second_file)", 
    ], 
    data = [ 
     ":first_file", 
     ":second_file", 
    ], 
) 

这也使得整个事情更富有表现力,所以耶:)

0

您必须使用main属性,如:

py_binary(
    name = "bar", 
    main = "//foo:foo.py", 
    srcs = ["//foo:foo"], 
... 

注意,这意味着你必须在富/ BUILD暴露foo.py:

exports_files(["foo.py"]) 
+0

AFAIT'main'忽略了只有相对目标的所有包信息和搜索。 – abergmeier

+0

如果是这样,我认为这是一个错误。 – kristina