diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java b/src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java index f4f83bb319ff78..9ce0ff0d4f300a 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java @@ -624,6 +624,19 @@ public OutputDirectoryNamingSchemeConverter() { + "Bazel release.") public List defaultFeatures; + @Option( + name = "host_features", + allowMultiple = true, + defaultValue = "null", + documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS, + effectTags = {OptionEffectTag.CHANGES_INPUTS, OptionEffectTag.AFFECTS_OUTPUTS}, + help = + "The given features will be enabled or disabled by default for packages " + + "built in the host or exec configurationsx. " + + "Specifying - will disable the feature globally. " + + "Negative features always override positive ones.") + public List hostFeatures; + @Option( name = "target_environment", converter = LabelListConverter.class, @@ -947,7 +960,7 @@ public FragmentOptions getHost() { host.checkLicenses = checkLicenses; // === Pass on C++ compiler features. - host.defaultFeatures = ImmutableList.copyOf(defaultFeatures); + host.defaultFeatures = ImmutableList.copyOf(hostFeatures); // Save host options in case of a further exec->host transition. host.hostCpu = hostCpu; diff --git a/src/test/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetTest.java index f379378004effc..6f8b1d5665beee 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetTest.java @@ -51,6 +51,27 @@ public void testFeatureEnabledOnCommandLine() throws Exception { assertThat(features).doesNotContain("other"); } + @Test + public void testTargetIgnoresHostFeatures() throws Exception { + useConfiguration("--features=feature", "--host_features=other"); + scratch.file("a/BUILD", + "cc_library(name = 'a')"); + ImmutableSet features = getRuleContext(configure("//a")).getFeatures(); + assertThat(features).contains("feature"); + assertThat(features).doesNotContain("other"); + } + + @Test + public void testHostFeatures() throws Exception { + useConfiguration("--features=feature", "--host_features=host_feature"); + scratch.file("a/BUILD", + "cc_library(name = 'a')"); + ImmutableSet features = getRuleContext( + getConfiguredTarget("//a", getHostConfiguration())).getFeatures(); + assertThat(features).contains("host_feature"); + assertThat(features).doesNotContain("feature"); + } + @Test public void testFeatureDisabledOnCommandLine() throws Exception { useConfiguration("--features=-feature");