Bazel: rule_test does not use tags since bazel 0.27

Created on 26 Jun 2019  路  5Comments  路  Source: bazelbuild/bazel

Description of the problem / feature request:

Starting from bazel 0.27, a tags attribute on rule_test is not correctly taken into account when filtering with --build_tag_filters.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Create a workspace, with an empty WORKSPACE and the following BUILD file:

load("@bazel_tools//tools/build_rules:test_rules.bzl", "rule_test")

cc_binary(
    name = "bar",
    srcs = ["foo.cpp"],
    deps = ["@chien//:blip"],
    tags = ["nop"],
)

rule_test(
    name = "test-bar",
    generates = ["toto"],
    rule = ":bar",
    tags = ["nop"],
)

Here, the rule bar is broken because it references @chien which does not exists. The associated rule_test test-bar is broken too, by definition. However both have a tags = ["nop"] attribute, so they should not be runned if filtered using --build_tag_filters=-nop.

It works as expected with bazel 0.26.1:

[nix-shell:~/tweag/rules_haskell/test_bazel027]$ bazel info release
release 0.26.1- (@non-git)
[nix-shell:~/tweag/rules_haskell/test_bazel027]$ bazel build //... --build_tag_filters=-nop
INFO: Analyzed 0 targets (1 packages loaded, 0 targets configured).
INFO: Found 0 targets...
INFO: Elapsed time: 0.077s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action

But fails with bazel 0.27:

[nix-shell:~/tweag/rules_haskell/test_bazel027]$ bazel info release
Starting local Bazel server and connecting to it...
release 0.27.0- (@non-git)

[nix-shell:~/tweag/rules_haskell/test_bazel027]$ bazel build //... --build_tag_filters=-nop
ERROR: /home/guillaume/tweag/rules_haskell/test_bazel027/BUILD.bazel:3:1: no such package '@chien//': The repository '@chien' could not be resolved and referenced by '//:bar'
ERROR: Analysis of target '//:test-bar_impl' failed; build aborted: no such package '@chien//': The repository '@chien' could not be resolved
INFO: Elapsed time: 0.901s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (8 packages loaded, 28 targets configured)
    Fetching @local_config_cc; Restarting.

What operating system are you running Bazel on?

Nixos, but I also tried this in a docker container on debian.

What's the output of bazel info release?

  • release 0.27.0- (@non-git) and release 0.26.1- (@non-git) on nixos
  • release 0.27.0 and release 0.26.1 on debian.

If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.

Used the one from nixos.

P1 release blocker team-Starlark bug

All 5 comments

Some informations:

commit 77b987524ad0988dd0d21cd5e9dcadb897bedd26 introduced test_rule suffixed by _impl. If I'm running bazel with -- -//:test-bar_impl to ignore the _impl rule, I don't have the build failure.

Thanks for the repro and culprit identification.

With Bazel 0.27.0 rule_test became a macro, expanded to two rules: sh_test and _rule_test_rule. The culprit is, the sh_test gets all the **kwargs (including tags) but the other rule doesn't.

@laurentlb : do you think we need a patch release with this fix?

Thank you for your work on that.

I'm closing the PR opened 7 days ago (#8724) in favor of #8784.

You're welcome.
I didn't notice your PR, sorry about that.

Was this page helpful?
0 / 5 - 0 ratings