2017-04-12 35 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