Skip to content

Commit

Permalink
Add incompatible flag for it
Browse files Browse the repository at this point in the history
  • Loading branch information
keith committed Feb 13, 2023
1 parent 43efe41 commit 080d144
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,15 @@ public OutputDirectoryNamingSchemeConverter() {
+ "Negative features always override positive ones.")
public List<String> hostFeatures;

@Option(
name = "incompatible_use_host_features",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
effectTags = {OptionEffectTag.CHANGES_INPUTS, OptionEffectTag.AFFECTS_OUTPUTS},
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
help = "If true, use --features only for the target configuration and --host_features for the exec configuration.")
public boolean incompatibleUseHostFeatures;

@Option(
name = "target_environment",
converter = LabelListConverter.class,
Expand Down Expand Up @@ -1002,7 +1011,12 @@ public FragmentOptions getExec() {
exec.checkLicenses = checkLicenses;

// === Pass on C++ compiler features.
exec.defaultFeatures = ImmutableList.copyOf(hostFeatures);
exec.incompatibleUseHostFeatures = incompatibleUseHostFeatures;
if (incompatibleUseHostFeatures) {
exec.defaultFeatures = ImmutableList.copyOf(hostFeatures);
} else {
exec.defaultFeatures = ImmutableList.copyOf(defaultFeatures);
}

// Save host options in case of a further exec->host transition.
exec.hostCpu = hostCpu;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ public void testHostFeatures() throws Exception {
assertThat(features).doesNotContain("feature");
}

@Test
public void testHostFeaturesIncompatibleDisabled() throws Exception {
useConfiguration("--features=feature", "--host_features=host_feature",
"--incompatible_use_host_features=false");
scratch.file("a/BUILD", "cc_library(name = 'a')");
ImmutableSet<String> features = getRuleContext(
getConfiguredTarget("//a", getExecConfiguration())).getFeatures();
assertThat(features).contains("feature");
assertThat(features).doesNotContain("host_feature");
}

@Test
public void testFeatureDisabledOnCommandLine() throws Exception {
useConfiguration("--features=-feature");
Expand Down

0 comments on commit 080d144

Please sign in to comment.