-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8849b5d
commit 02ba730
Showing
7 changed files
with
46 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
#workspace(name = "bsws") | ||
workspace(name = "bsws") |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) | ||
} | ||
) |