3 changed files with 52 additions and 3 deletions
@ -0,0 +1,9 @@ |
|||||
|
# Bazel playground |
||||
|
|
||||
|
## Play with ... |
||||
|
|
||||
|
- `bazel run main --//:favorite_flavor="BANANA"` |
||||
|
- `bazel run main --//:favorite_flavor="APPLE"` |
||||
|
- `bazel run main --//:favorite_flavor="ORANGE"` |
||||
|
- `bazel run main` |
||||
|
|
||||
@ -0,0 +1,18 @@ |
|||||
|
# https://docs.bazel.build/versions/2.1.0/skylark/config.html |
||||
|
|
||||
|
FlavorProvider = provider(fields = ['type']) |
||||
|
|
||||
|
flavors = ["APPLE", "BANANA", "ORANGE"] |
||||
|
|
||||
|
def _impl(ctx): |
||||
|
raw_flavor = ctx.build_setting_value |
||||
|
if raw_flavor not in flavors: |
||||
|
fail(str(ctx.label) + " build setting allowed to take values {" |
||||
|
+ ", ".join(flavors) + "} but was set to unallowed value " |
||||
|
+ raw_flavor) |
||||
|
return FlavorProvider(type = raw_flavor) |
||||
|
|
||||
|
flavor = rule( |
||||
|
implementation = _impl, |
||||
|
build_setting = config.string(flag = True) |
||||
|
) |
||||
Loading…
Reference in new issue