diff options
author | Greg Estren <gregce@google.com> | 2016-02-10 15:57:58 +0000 |
---|---|---|
committer | Dmitry Lomov <dslomov@google.com> | 2016-02-11 11:48:27 +0000 |
commit | 33ec191dba103474d95649ab3849cc37f00947f2 (patch) | |
tree | 4abd7ceb380eaec3497f29cc612381a357ead2c6 /src/main/java/com/google/devtools/build/lib/bazel/rules/cpp | |
parent | 79adf59e2973754c8c0415fcab45cd58c7c34697 (diff) |
Implement TODO from: https://github.com/bazelbuild/bazel/blo[]fbbd6a32b95ba746f09dae1eaeaccf675cd5b3/src/main/java/com/google/devtools/build/lib/packages/Attribute.java#L1045
This allows the default value computation for latebound attributes to consider
the values of configurable attributes. This is most directly useful for user-definable Skylark defaults, which have full access to the values of all non-latebound attributes.
Without this change, this kind of scenario crashes Bazel. For example:
------------------
select_rules.bzl:
------------------
def _impl(ctx):
ctx.file_action(
output=ctx.outputs.out_file,
content=ctx.attr.string_value,
)
return struct()
# Bug does not manifest without using this as a default.
def _derived_value(attrs, _):
return Label("//some:dep")
selector_rule = rule(
implementation=_impl,
attrs={
"string_value": attr.string(default=""),
"out_file": attr.output(),
"_derived": attr.label(default=_derived_value),
},
output_to_genfiles=True,
)
def selector_macro(name, out_file="", string_value=""):
# This will fail with selectors.
selector_rule(
name="%s_skylark" % name,
string_value=string_value,
out_file=out_file + ".skylark",
)
# This does not.
native.genrule(
name="%s_genrule" % name,
cmd="echo '" + string_value + "' > $@",
outs=[out_file + ".genrule"],
)
native.filegroup(
name=name,
srcs=[":%s_genrule" % name, "%s_skylark" % name],
)
------------------
BUILD.bzl:
------------------
config_setting(
name = "selector",
values = {"compilation_mode": "opt"},
)
selector_macro(
name = "this_rule",
string_value = """soup? """ + select({
":selector": "no, thank you.",
"//conditions:default": "yes, please!!",
}),
out_file = "this_rule.txt",
)
--
MOS_MIGRATED_REVID=114326474
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/bazel/rules/cpp')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java index 8b5171c2a6..748e1f73f0 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java @@ -159,7 +159,8 @@ public class BazelCppRuleClasses { public static final LateBoundLabel<BuildConfiguration> CC_TOOLCHAIN = new LateBoundLabel<BuildConfiguration>(CROSSTOOL_LABEL) { @Override - public Label getDefault(Rule rule, BuildConfiguration configuration) { + public Label getDefault(Rule rule, AttributeMap attributes, + BuildConfiguration configuration) { return configuration.getFragment(CppConfiguration.class).getCcToolchainRuleLabel(); } }; @@ -167,7 +168,8 @@ public class BazelCppRuleClasses { public static final LateBoundLabel<BuildConfiguration> DEFAULT_MALLOC = new LateBoundLabel<BuildConfiguration>() { @Override - public Label getDefault(Rule rule, BuildConfiguration configuration) { + public Label getDefault(Rule rule, AttributeMap attributes, + BuildConfiguration configuration) { return configuration.getFragment(CppConfiguration.class).customMalloc(); } }; @@ -175,7 +177,8 @@ public class BazelCppRuleClasses { public static final LateBoundLabel<BuildConfiguration> STL = new LateBoundLabel<BuildConfiguration>() { @Override - public Label getDefault(Rule rule, BuildConfiguration configuration) { + public Label getDefault(Rule rule, AttributeMap attributes, + BuildConfiguration configuration) { return getStl(rule, configuration); } }; @@ -186,7 +189,7 @@ public class BazelCppRuleClasses { public static final LateBoundLabel<BuildConfiguration> LIPO_CONTEXT_COLLECTOR = new LateBoundLabel<BuildConfiguration>() { @Override - public Label getDefault(Rule rule, BuildConfiguration configuration) { + public Label getDefault(Rule rule, AttributeMap attributes, BuildConfiguration configuration) { // This attribute connects a target to the LIPO context target configured with the // lipo input collector configuration. CppConfiguration cppConfiguration = configuration.getFragment(CppConfiguration.class); @@ -674,7 +677,7 @@ public class BazelCppRuleClasses { private static final LateBoundLabel<BuildConfiguration> LIPO_CONTEXT = new LateBoundLabel<BuildConfiguration>() { @Override - public Label getDefault(Rule rule, BuildConfiguration configuration) { + public Label getDefault(Rule rule, AttributeMap attributes, BuildConfiguration configuration) { Label result = configuration.getFragment(CppConfiguration.class).getLipoContextLabel(); return (rule == null || rule.getLabel().equals(result)) ? null : result; } |