Skip to content

Commit

Permalink
Add --incompatible_dont_enable_host_nonhost_crosstool_features
Browse files Browse the repository at this point in the history
#7407

RELNOTES: None.
PiperOrigin-RevId: 233732318
  • Loading branch information
hlopko authored and Copybara-Service committed Feb 13, 2019
1 parent d5c1eee commit 8814b6c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,12 @@ public static FeatureConfiguration configureFeaturesOrThrowEvalException(
.addAll(requestedFeatures)
.addAll(toolchain.getFeatures().getDefaultFeaturesAndActionConfigs());

if (toolchain.isHostConfiguration()) {
allFeatures.add("host");
} else {
allFeatures.add("nonhost");
if (!cppConfiguration.dontEnableHostNonhost()) {
if (toolchain.isHostConfiguration()) {
allFeatures.add("host");
} else {
allFeatures.add("nonhost");
}
}

if (toolchain.useFission() && !cppConfiguration.disableLegacyCrosstoolFields()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,4 +597,8 @@ public boolean enableLegacyCcProvider() {
public boolean disableCrosstool() {
return cppOptions.disableCrosstool;
}

public boolean dontEnableHostNonhost() {
return cppOptions.dontEnableHostNonhost;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,20 @@ public Label getFdoPrefetchHintsLabel() {
)
public boolean useLLVMCoverageMapFormat;

@Option(
name = "incompatible_dont_enable_host_nonhost_crosstool_features",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help =
"If true, Bazel will not enable 'host' and 'nonhost' features in the c++ toolchain "
+ "(see https://github.com/bazelbuild/bazel/issues/7407 for more information).")
public boolean dontEnableHostNonhost;

@Option(
name = "incompatible_disable_legacy_crosstool_fields",
oldName = "experimental_disable_legacy_crosstool_fields",
Expand Down Expand Up @@ -886,6 +900,7 @@ public FragmentOptions getHost() {
host.disableCrosstool = disableCrosstool;
host.enableCcToolchainResolution = enableCcToolchainResolution;
host.removeLegacyWholeArchive = removeLegacyWholeArchive;
host.dontEnableHostNonhost = dontEnableHostNonhost;
return host;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1230,12 +1230,17 @@ public void testCompilationModeFeatures() throws Exception {
assertThat(flags).containsNoneOf("-fastbuild", "-opt");
}

private List<String> getHostAndTargetFlags(boolean useHost) throws Exception {
private List<String> getHostAndTargetFlags(boolean useHost, boolean isDisabledByFlag)
throws Exception {
AnalysisMock.get()
.ccSupport()
.setupCrosstool(mockToolsConfig, MockCcSupport.HOST_AND_NONHOST_CONFIGURATION);
scratch.overwriteFile("mode/BUILD", "cc_library(name = 'a', srcs = ['a.cc'])");
useConfiguration("--cpu=k8");
useConfiguration(
"--cpu=k8",
isDisabledByFlag
? "--incompatible_dont_enable_host_nonhost_crosstool_features"
: "--noincompatible_dont_enable_host_nonhost_crosstool_features");
ConfiguredTarget target;
String objectPath;
if (useHost) {
Expand All @@ -1255,15 +1260,28 @@ private List<String> getHostAndTargetFlags(boolean useHost) throws Exception {
public void testHostAndNonHostFeatures() throws Exception {
List<String> flags;

flags = getHostAndTargetFlags(true);
flags = getHostAndTargetFlags(/* useHost= */ true, /* isDisabledByFlag= */ false);
assertThat(flags).contains("-host");
assertThat(flags).doesNotContain("-nonhost");

flags = getHostAndTargetFlags(false);
flags = getHostAndTargetFlags(/* useHost= */ false, /* isDisabledByFlag= */ false);
assertThat(flags).contains("-nonhost");
assertThat(flags).doesNotContain("-host");
}

@Test
public void testHostAndNonHostFeaturesDisabledByTheFlag() throws Exception {
List<String> flags;

flags = getHostAndTargetFlags(/* useHost= */ true, /* isDisabledByFlag= */ true);
assertThat(flags).doesNotContain("-host");
assertThat(flags).doesNotContain("-nonhost");

flags = getHostAndTargetFlags(/* useHost= */ false, /* isDisabledByFlag= */ true);
assertThat(flags).doesNotContain("-nonhost");
assertThat(flags).doesNotContain("-host");
}

@Test
public void testIncludePathsOutsideExecutionRoot() throws Exception {
scratchRule(
Expand Down

0 comments on commit 8814b6c

Please sign in to comment.