Skip to content

Commit

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

    RELNOTES: None.
    PiperOrigin-RevId: 233732318
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent 6dc4ddf commit fc96968
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.StarlarkSemantics;
import com.google.devtools.build.lib.syntax.SkylarkSemantics;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.util.Pair;
Expand Down Expand Up @@ -211,7 +211,7 @@ public static void checkRuleWhitelisted(SkylarkRuleContext skylarkRuleContext)
}

public static void checkLocationWhitelisted(
StarlarkSemantics semantics, Location location, String callPath) throws EvalException {
SkylarkSemantics semantics, Location location, String callPath) throws EvalException {
List<String> whitelistedPackagesList = semantics.experimentalCcSkylarkApiEnabledPackages();
if (whitelistedPackagesList.stream().noneMatch(path -> callPath.startsWith(path))) {
throwWhiteListError(location, callPath, whitelistedPackagesList);
Expand Down Expand Up @@ -800,10 +800,7 @@ public static FeatureConfiguration configureFeaturesOrReportRuleError(
CcToolchainProvider toolchain) {
try {
return configureFeaturesOrThrowEvalException(
requestedFeatures,
unsupportedFeatures,
toolchain,
ruleContext.getFragment(CppConfiguration.class));
requestedFeatures, unsupportedFeatures, toolchain);
} catch (EvalException e) {
ruleContext.ruleError(e.getMessage());
return FeatureConfiguration.EMPTY;
Expand All @@ -813,9 +810,9 @@ public static FeatureConfiguration configureFeaturesOrReportRuleError(
public static FeatureConfiguration configureFeaturesOrThrowEvalException(
ImmutableSet<String> requestedFeatures,
ImmutableSet<String> unsupportedFeatures,
CcToolchainProvider toolchain,
CppConfiguration cppConfiguration)
CcToolchainProvider toolchain)
throws EvalException {
CppConfiguration cppConfiguration = toolchain.getCppConfiguration();
ImmutableSet.Builder<String> allRequestedFeaturesBuilder = ImmutableSet.builder();
ImmutableSet.Builder<String> unsupportedFeaturesBuilder = ImmutableSet.builder();
unsupportedFeaturesBuilder.addAll(unsupportedFeatures);
Expand Down Expand Up @@ -843,9 +840,6 @@ public static FeatureConfiguration configureFeaturesOrThrowEvalException(
}

if (cppConfiguration.forcePic()) {
if (unsupportedFeatures.contains(CppRuleClasses.SUPPORTS_PIC)) {
throw new EvalException(/* location= */ null, PIC_CONFIGURATION_ERROR);
}
allRequestedFeaturesBuilder.add(CppRuleClasses.SUPPORTS_PIC);
}

Expand Down Expand Up @@ -1013,25 +1007,8 @@ private static String computeCcFlagForSysroot(CcToolchainProvider toolchainProvi

private static List<String> computeCcFlagsFromFeatureConfig(
RuleContext ruleContext, CcToolchainProvider toolchainProvider) {
FeatureConfiguration featureConfiguration = null;
CppConfiguration cppConfiguration =
toolchainProvider.getCppConfigurationEvenThoughItCanBeDifferentThatWhatTargetHas();
if (cppConfiguration.requireCtxInConfigureFeatures()) {
// When this is flipped, this whole method will go away. But I'm keeping it there
// so we can experiment with flags before they are flipped.
Preconditions.checkArgument(cppConfiguration.disableGenruleCcToolchainDependency());
cppConfiguration = ruleContext.getFragment(CppConfiguration.class);
}
try {
featureConfiguration =
configureFeaturesOrThrowEvalException(
ruleContext.getFeatures(),
ruleContext.getDisabledFeatures(),
toolchainProvider,
cppConfiguration);
} catch (EvalException e) {
ruleContext.ruleError(e.getMessage());
}
FeatureConfiguration featureConfiguration =
CcCommon.configureFeaturesOrReportRuleError(ruleContext, toolchainProvider);
if (featureConfiguration.actionIsConfigured(CppActionNames.CC_FLAGS_MAKE_VARIABLE)) {
CcToolchainVariables buildVariables = toolchainProvider.getBuildVariables();
return featureConfiguration.getCommandLine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ public boolean legacyWholeArchive() {
return cppOptions.legacyWholeArchive;
}

public boolean removeLegacyWholeArchive() {
return cppOptions.removeLegacyWholeArchive;
}

public boolean getInmemoryDotdFiles() {
return cppOptions.inmemoryDotdFiles;
}
Expand Down Expand Up @@ -544,6 +548,10 @@ public boolean disableLegacyCrosstoolFields() {
return cppOptions.disableLegacyCrosstoolFields;
}

public boolean disableExpandIfAllAvailableInFlagSet() {
return cppOptions.disableExpandIfAllAvailableInFlagSet;
}

public static String getLegacyCrosstoolFieldErrorMessage(String field) {
Preconditions.checkNotNull(field);
return field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,18 @@ public String getTypeDescription() {
public Label customMalloc;

@Option(
name = "legacy_whole_archive",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
effectTags = {OptionEffectTag.ACTION_COMMAND_LINES, OptionEffectTag.AFFECTS_OUTPUTS},
help =
"When on, use --whole-archive for cc_binary rules that have "
+ "linkshared=1 and either linkstatic=1 or '-static' in linkopts. "
+ "This is for backwards compatibility only. "
+ "A better alternative is to use alwayslink=1 where required."
)
name = "legacy_whole_archive",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
effectTags = {OptionEffectTag.ACTION_COMMAND_LINES, OptionEffectTag.AFFECTS_OUTPUTS},
metadataTags = {OptionMetadataTag.DEPRECATED},
help =
"Deprecated, superseded by --incompatible_remove_legacy_whole_archive "
+ "(see https://github.com/bazelbuild/bazel/issues/7362 for details). "
+ "When on, use --whole-archive for cc_binary rules that have "
+ "linkshared=1 and either linkstatic=1 or '-static' in linkopts. "
+ "This is for backwards compatibility only. "
+ "A better alternative is to use alwayslink=1 where required.")
public boolean legacyWholeArchive;

@Option(
Expand Down Expand Up @@ -712,6 +714,20 @@ public Label getFdoPrefetchHintsLabel() {
+ "(see https://github.com/bazelbuild/bazel/issues/6861 for migration instructions).")
public boolean disableLegacyCrosstoolFields;

@Option(
name = "incompatible_remove_legacy_whole_archive",
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 link library dependencies as whole archive by default "
+ "(see https://github.com/bazelbuild/bazel/issues/7362 for migration instructions).")
public boolean removeLegacyWholeArchive;

@Option(
name = "incompatible_remove_cpu_and_compiler_attributes_from_cc_toolchain",
defaultValue = "false",
Expand All @@ -727,6 +743,20 @@ public Label getFdoPrefetchHintsLabel() {
+ "(see https://github.com/bazelbuild/bazel/issues/7075 for migration instructions).")
public boolean removeCpuCompilerCcToolchainAttributes;

@Option(
name = "incompatible_disable_expand_if_all_available_in_flag_set",
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 allow specifying expand_if_all_available in flag_sets"
+ "(see https://github.com/bazelbuild/bazel/issues/7008 for migration instructions).")
public boolean disableExpandIfAllAvailableInFlagSet;

@Option(
name = "incompatible_disable_crosstool_file",
defaultValue = "false",
Expand Down Expand Up @@ -863,11 +893,13 @@ public FragmentOptions getHost() {
host.doNotUseCpuTransformer = doNotUseCpuTransformer;
host.disableGenruleCcToolchainDependency = disableGenruleCcToolchainDependency;
host.disableDepsetInUserFlags = disableDepsetInUserFlags;
host.disableExpandIfAllAvailableInFlagSet = disableExpandIfAllAvailableInFlagSet;
host.disableLegacyCcProvider = disableLegacyCcProvider;
host.removeCpuCompilerCcToolchainAttributes = removeCpuCompilerCcToolchainAttributes;
host.disableLegacyCrosstoolFields = disableLegacyCrosstoolFields;
host.disableCrosstool = disableCrosstool;
host.enableCcToolchainResolution = enableCcToolchainResolution;
host.removeLegacyWholeArchive = removeLegacyWholeArchive;
host.dontEnableHostNonhost = dontEnableHostNonhost;
return host;
}
Expand Down
Loading

0 comments on commit fc96968

Please sign in to comment.