Skip to content

Commit 2574818

Browse files
committed
Add --host_features
Previously there was no way to have a feature only apply to the entire transitive target closure without `--features` which also applied to the host / exec configuration. This is undesirable for many features such as C++ sanitizers where you often only need them to affect targets in the target configuration, and you don't want to invalidate all host tools when switching between these build configurations. RELNOTES[INC]: `--features` only applies to targets built in the target configuration, and `--host_features` is used for the host / exec configuration. Fixes #13839
1 parent 88c426e commit 2574818

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,13 +643,26 @@ public OutputDirectoryNamingSchemeConverter() {
643643
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
644644
effectTags = {OptionEffectTag.CHANGES_INPUTS, OptionEffectTag.AFFECTS_OUTPUTS},
645645
help =
646-
"The given features will be enabled or disabled by default for all packages. "
647-
+ "Specifying -<feature> will disable the feature globally. "
646+
"The given features will be enabled or disabled by default for targets "
647+
+ "built in the target configuration. "
648+
+ "Specifying -<feature> will disable the feature. "
648649
+ "Negative features always override positive ones. "
649-
+ "This flag is used to enable rolling out default feature changes without a "
650-
+ "Bazel release.")
650+
+ "See also --host_features")
651651
public List<String> defaultFeatures;
652652

653+
@Option(
654+
name = "host_features",
655+
allowMultiple = true,
656+
defaultValue = "null",
657+
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
658+
effectTags = {OptionEffectTag.CHANGES_INPUTS, OptionEffectTag.AFFECTS_OUTPUTS},
659+
help =
660+
"The given features will be enabled or disabled by default for targets "
661+
+ "built in the exec configuration. "
662+
+ "Specifying -<feature> will disable the feature. "
663+
+ "Negative features always override positive ones.")
664+
public List<String> hostFeatures;
665+
653666
@Option(
654667
name = "target_environment",
655668
converter = LabelListConverter.class,
@@ -986,7 +999,7 @@ public FragmentOptions getExec() {
986999
exec.checkLicenses = checkLicenses;
9871000

9881001
// === Pass on C++ compiler features.
989-
exec.defaultFeatures = ImmutableList.copyOf(defaultFeatures);
1002+
exec.defaultFeatures = ImmutableList.copyOf(hostFeatures);
9901003

9911004
// Save host options in case of a further exec->host transition.
9921005
exec.hostCpu = hostCpu;

src/test/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@ public void testFeatureEnabledOnCommandLine() throws Exception {
5151
assertThat(features).doesNotContain("other");
5252
}
5353

54+
@Test
55+
public void testTargetIgnoresHostFeatures() throws Exception {
56+
useConfiguration("--features=feature", "--host_features=other");
57+
scratch.file("a/BUILD",
58+
"cc_library(name = 'a')");
59+
ImmutableSet<String> features = getRuleContext(configure("//a")).getFeatures();
60+
assertThat(features).contains("feature");
61+
assertThat(features).doesNotContain("other");
62+
}
63+
64+
@Test
65+
public void testHostFeatures() throws Exception {
66+
useConfiguration("--features=feature", "--host_features=host_feature");
67+
scratch.file("a/BUILD",
68+
"cc_library(name = 'a')");
69+
ImmutableSet<String> features = getRuleContext(
70+
getConfiguredTarget("//a", getHostConfiguration())).getFeatures();
71+
assertThat(features).contains("host_feature");
72+
assertThat(features).doesNotContain("feature");
73+
}
74+
5475
@Test
5576
public void testFeatureDisabledOnCommandLine() throws Exception {
5677
useConfiguration("--features=-feature");

0 commit comments

Comments
 (0)