diff options
author | plf <plf@google.com> | 2018-05-28 01:08:04 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-28 01:09:36 -0700 |
commit | 2ad044cbc0214ad1e1d7a30350e8b428dcd29bf4 (patch) | |
tree | f8237a2f1f02a26503e29f877eb7c9dbdc58fa6d | |
parent | a7e05846f75cc38de58a392ee61d69aea5598ed7 (diff) |
Skylark: Exposes disabled features from rule context to Skylark
WANT_LGTM=all
RELNOTES:none
PiperOrigin-RevId: 198269370
3 files changed, 19 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java index 6d440191dd..4e424bbc60 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java @@ -595,6 +595,12 @@ public final class SkylarkRuleContext implements SkylarkRuleContextApi { } @Override + public ImmutableList<String> getDisabledFeatures() throws EvalException { + checkMutable("disabled_features"); + return ImmutableList.copyOf(ruleContext.getDisabledFeatures()); + } + + @Override public ArtifactRoot getBinDirectory() throws EvalException { checkMutable("bin_dir"); return getConfiguration().getBinDirectory(ruleContext.getRule().getRepository()); diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkRuleContextApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkRuleContextApi.java index ca23f57fc3..2350429680 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkRuleContextApi.java +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkRuleContextApi.java @@ -240,11 +240,17 @@ public interface SkylarkRuleContextApi extends SkylarkValue { @SkylarkCallable( name = "features", structField = true, - doc = "Returns the set of features that are enabled for this rule." + doc = "Returns the set of features that are explicitly enabled by the user for this rule." ) public ImmutableList<String> getFeatures() throws EvalException; @SkylarkCallable( + name = "disabled_features", + structField = true, + doc = "Returns the set of features that are explicitly disabled by the user for this rule.") + ImmutableList<String> getDisabledFeatures() throws EvalException; + + @SkylarkCallable( name = "bin_dir", structField = true, doc = "The root corresponding to bin directory." diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java index e449ed1ceb..4d86a34413 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java @@ -774,6 +774,12 @@ public class SkylarkRuleContextTest extends SkylarkTestCase { assertThat((SkylarkList<?>) result).containsExactly("cc_include_scanning", "f1", "f2"); } + @Test + public void testDisabledFeatures() throws Exception { + SkylarkRuleContext ruleContext = createRuleContext("//foo:cc_with_features"); + Object result = evalRuleContextCode(ruleContext, "ruleContext.disabled_features"); + assertThat((SkylarkList<?>) result).containsExactly("f3"); + } @Test public void testHostConfiguration() throws Exception { |