Skip to content

Instantly share code, notes, and snippets.

@deeglaze
Created October 23, 2019 23:58
Show Gist options
  • Save deeglaze/3bc92c79a6465f2ed4f372c7c2838b85 to your computer and use it in GitHub Desktop.
Save deeglaze/3bc92c79a6465f2ed4f372c7c2838b85 to your computer and use it in GitHub Desktop.
Reproduces a label_flag bug in bazel
#!/bin/bash
function executable() {
local name="$1"
cat > "${name}.cc" <<EOF
#include <cstdlib>
#include <iostream>
int main(int argc, char *argv[]) {
std::cout << "${name}\n";
return EXIT_SUCCESS;
}
EOF
}
function workspace() {
local name="$1"
local location="$2"
}
readonly tmp=$(mktemp -d)
pushd "${tmp}"
mkdir label
cat > "label/BUILD.tpl" <<EOF
cc_library(name = "placeholder")
label_flag(
name = "label",
build_setting_default = "@test_label//:placeholder",
visibility = ["//visibility:public"],
)
EOF
cat > "label/WORKSPACE.tpl" <<EOF
workspace(name = "test_label")
EOF
cat > "label/BUILD" <<EOF
exports_files(["BUILD.tpl", "WORKSPACE.tpl"])
EOF
cat > repo.bzl <<EOF
def _repo_impl(repository_ctx):
repository_ctx.template("BUILD", Label("@test//label:BUILD.tpl"))
repository_ctx.template("WORKSPACE", Label("@test//label:WORKSPACE.tpl"))
make_repo = repository_rule(implementation = _repo_impl)
EOF
cat > WORKSPACE <<EOF
workspace(name = "test")
load(":repo.bzl", "make_repo")
make_repo(name = "test_label")
EOF
executable "foo"
executable "bar"
cat > BUILD <<EOF
cc_library(name = "foo")
cc_binary(
name = "qux",
srcs = select({
":is_foo": ["foo.cc"],
"//conditions:default": ["bar.cc"],
}),
)
config_setting(
name = "is_foo",
flag_values = {"@test_label//:label": "//:foo"},
)
EOF
# Should print "foo", but is a command line parse error.
bazel build --@test_label:label=//:foo :qux
# Should print "foo", but is an error about a missing BUILD file?
bazel build --//external/test_label:label=//:foo :qux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment