2016-04-14 4 views
2

Neu im Bazel-Build-System.Bazel: Erstelle py_binary aus der Python-Datei in py_library

Ich möchte ein py_binary aus einer Datei in einer py_library erstellen, die aus einem http_archive erstellt wird.

Zur Zeit habe ich:

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" 
    ] 
) 

Der Pfad in srcs und main ist falsch und gibt "kein solches Paket 'cpplint/cpplint.py'", wenn ich bazel run src/lint ausführen. Ich kann nicht herausfinden, wie ich auf eine Datei in der Bibliothek verweisen soll.

Antwort

1

können Sie setzen die py_binary Regel direkt in cpplint.BUILD:

py_binary(
    name = "cpplint", 
    srcs = ["cpplint.py"], 
) 

und es dann so bauen:

$ 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 

Wenn Sie wirklich die py_binary Regel im Haupt-Repository sein wollen, Sie tun können:

cpplint.BUILD:

BUILD:

py_binary(
    name = "cpplint", 
    srcs = ["@cpplint_archive//:cpplint.py"], 
) 

Aber es ist in der Regel nicht so schön in Dateien aus anderen Paketen zu ziehen.

+0

Vielen Dank. Ich werde sehen, welche Option mir am besten passt, aber beide Ansätze funktionieren. – avanwyk

Verwandte Themen