Skip to content

Commit cba5cc2

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. Now `--features` only applies to targets built in the target configuration, and `--host_features` is used for the host / exec configuration. Fixes #13839
1 parent a67c823 commit cba5cc2

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,19 @@ public OutputDirectoryNamingSchemeConverter() {
624624
+ "Bazel release.")
625625
public List<String> defaultFeatures;
626626

627+
@Option(
628+
name = "host_features",
629+
allowMultiple = true,
630+
defaultValue = "null",
631+
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
632+
effectTags = {OptionEffectTag.CHANGES_INPUTS, OptionEffectTag.AFFECTS_OUTPUTS},
633+
help =
634+
"The given features will be enabled or disabled by default for packages "
635+
+ "built in the host or exec configurations. "
636+
+ "Specifying -<feature> will disable the feature globally. "
637+
+ "Negative features always override positive ones.")
638+
public List<String> hostFeatures;
639+
627640
@Option(
628641
name = "target_environment",
629642
converter = LabelListConverter.class,
@@ -948,7 +961,7 @@ public FragmentOptions getHost() {
948961
host.checkLicenses = checkLicenses;
949962

950963
// === Pass on C++ compiler features.
951-
host.defaultFeatures = ImmutableList.copyOf(defaultFeatures);
964+
host.defaultFeatures = ImmutableList.copyOf(hostFeatures);
952965

953966
// Save host options in case of a further exec->host transition.
954967
host.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)