2016-04-30 8 views
1

Mein Projekt wie die folgende Struktur:Fehler mit mehreren Bazel Dateien BUILD: "Target 'Bar' ist nicht sichtbar von Ziel 'foo'"

$ tree 
. 
├── bar 
│   ├── bar.cpp 
│   └── BUILD 
├── BUILD 
├── foo.cpp 
└── WORKSPACE 

Inhalt des ./BUILD:

cc_binary(
    name = "foo", 
    srcs = [ "foo.cpp" ], 
    deps = [ "//bar" ], 
) 

Inhalt von bar/BUILD:

cc_library(
    name = "bar", 
    srcs = ["bar.cpp"], 
) 

Wenn ich foo bauen, erhalte ich die folgende err oder:

Target '//bar:bar' is not visible from target '//:foo'. Check the visibility declaration of the former target if you think the dependency is legitimate. 

Was muss ich tun, damit die Abhängigkeit gelöst werden und foo erfolgreich gebaut?

Antwort

4

Vom Bazel docs:

However, by default, build rules are private. This means that they can only be referred to by rules in the same BUILD file. [...] You can make a rule visibile to rules in other BUILD files by adding a visibility = level attribute.

In diesem Fall bar/BUILD soll wie folgt aussehen:

cc_library(
    name = "bar", 
    srcs = ["bar.cpp"], 
    visibility = ["//__pkg__"], 
) 

Die zusätzliche Zeile visibility = ["//__pkg__"] alle BUILD Dateien im aktuellen Arbeitsbereich ermöglicht bar das Ziel zuzugreifen.