Skip to content

Commit

Permalink
final minimal working example
Browse files Browse the repository at this point in the history
  • Loading branch information
ulysses4ever committed Aug 15, 2019
1 parent 8849b5d commit 02ba730
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 28 deletions.
6 changes: 5 additions & 1 deletion e1/BUILD → BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
load("//e1:build_settings.bzl", "flavor")
load("//:build_settings.bzl", "flavor")
flavor(
name = "favorite_flavor",
build_setting_default = False,
visibility = ["//visibility:public"],
)

load("//:rules.bzl", "drink_rule")
drink_rule(
name = "my_drink",
)
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
## Example of [build configurations](https://docs.bazel.build/versions/0.28.0/skylark/config.html)

This is to show off Bazel's ([recently added](https://docs.bazel.build/versions/0.28.0/skylark/config.html)) ability
This is to show a bug in Bazel's ([recently added](https://docs.bazel.build/versions/0.28.0/skylark/config.html)) ability
to employ user-defined build flags.

### The minimal working setup

If you do:

```bash
bazel clean && bazel build //e1:my_drink
bazel clean && bazel build //:my_drink
```
it will print:
```
DEBUG: .../e1/rules.bzl:7:9: Get the default (False)
DEBUG: .../rules.bzl:7:9: Get the default (False)
```

In contrast, if you do
```bash
bazel clean && bazel build //e1:my_drink --//e1:favorite_flavor=True
bazel clean && bazel build //:my_drink --//:favorite_flavor=True
```
it will print:

```
DEBUG: .../e1/rules.bzl:5:9: Get the opposite of default
DEBUG: .../rules.bzl:5:9: Get the opposite of default (True)
```

### The bug (branch: bug)

Same code, except using workspace prefix for referencing the build-sertting target. Both commands listed above yield the same result:
```
DEBUG: .../rules.bzl:7:9: Get the default (False)
```
That is, the flag set in the command-line has no effect.
It might make sense to modify the command to use the
workspace prefix too:
```bash
bazel clean && bazel build //:my_drink --@bsws//:favorite_flavor=True
```
Unfortunately (and surpriingly) this yields:
```
ERROR: Unrecognized option: --@bsws//:favorite_flavor=True
```
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#workspace(name = "bsws")
workspace(name = "bsws")
File renamed without changes.
16 changes: 0 additions & 16 deletions e1/rules.bzl

This file was deleted.

5 changes: 0 additions & 5 deletions e2/BUILD

This file was deleted.

16 changes: 16 additions & 0 deletions rules.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("//:build_settings.bzl", "FlavorProvider")
def _rule_impl(ctx):
type = ctx.attr.flavor[FlavorProvider].type
if type:
print("Get the opposite of default (True)")
else:
print("Get the default (False)")

drink_rule = rule(
implementation = _rule_impl,
attrs = {
"flavor": attr.label(
default = "//:favorite_flavor",
)
}
)

0 comments on commit 02ba730

Please sign in to comment.