Skip to content

Commit e116bae

Browse files
comiuscopybara-github
authored andcommitted
Make incompatible_enable_cc_toolchain_resolution a no-op
Make crosstool_top flag a no-op and remove the code used to retrieve toolchain from crosstool_top. Remove the tests related to crosstop or incompatible_enable_cc_toolchain_resolution. Those tests can't work anymore, becuase the functionality is removed. There are some further cleanups, like removing _cc_toolchain attribute from the rules. RELNOTES[INC]: incompatible_enable_cc_toolchain_resolution is a no-op, enabled by default (#7260) PiperOrigin-RevId: 588363296 Change-Id: I8af466628ce9c8d9175533255faef36968570aa4
1 parent c5493b9 commit e116bae

24 files changed

+257
-829
lines changed

src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,13 +1923,6 @@ private static <T> T nullIfNone(Object object, Class<T> type) {
19231923
return object != Starlark.NONE ? type.cast(object) : null;
19241924
}
19251925

1926-
@Override
1927-
public boolean isCcToolchainResolutionEnabled(
1928-
StarlarkRuleContext starlarkRuleContext, StarlarkThread thread) throws EvalException {
1929-
isCalledFromStarlarkCcCommon(thread);
1930-
return CppHelper.useToolchainResolution(starlarkRuleContext.getRuleContext());
1931-
}
1932-
19331926
@Override
19341927
public Tuple createLinkingContextFromCompilationOutputs(
19351928
StarlarkActionFactory starlarkActionFactoryApi,

src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,6 @@ private CcToolchainVariables getBuildVariables(
750750
AppleConfiguration appleConfiguration,
751751
String cpu)
752752
throws EvalException, InterruptedException {
753-
if (!cppConfiguration.enableCcToolchainResolution()) {
754-
return buildVariables;
755-
}
756753
// With platforms, cc toolchain is analyzed in the exec configuration, so we can only reuse the
757754
// same build variables instance if the inputs to the construction match.
758755
PathFragment sysroot = getSysrootPathFragment(cppConfiguration);

src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuite.java

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import com.google.common.base.Preconditions;
1919
import com.google.common.base.Strings;
20-
import com.google.common.collect.ImmutableList;
2120
import com.google.common.collect.ImmutableMap;
2221
import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
2322
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
@@ -34,8 +33,6 @@
3433
import java.util.HashMap;
3534
import java.util.Map;
3635
import javax.annotation.Nullable;
37-
import net.starlark.java.eval.Starlark;
38-
import net.starlark.java.eval.StarlarkFunction;
3936
import net.starlark.java.syntax.Location;
4037

4138
/**
@@ -77,48 +74,16 @@ public ConfiguredTarget create(RuleContext ruleContext)
7774
Label selectedCcToolchain = toolchains.get(key);
7875
CcToolchainProvider ccToolchainProvider;
7976

80-
if (CppHelper.useToolchainResolution(ruleContext)) {
81-
// This is a platforms build (and the user requested to build this suite explicitly).
82-
// Cc_toolchains provide CcToolchainInfo already. Let's select the CcToolchainProvider from
83-
// toolchains and provide it here as well.
84-
ccToolchainProvider =
85-
selectCcToolchain(
86-
CcToolchainProvider.PROVIDER,
87-
ruleContext,
88-
transformedCpu,
89-
compiler,
90-
selectedCcToolchain);
91-
} else {
92-
// This is not a platforms build, and cc_toolchain_suite is the one responsible for creating
93-
// and providing CcToolchainInfo.
94-
CcToolchainAttributesProvider selectedAttributes =
95-
selectCcToolchain(
96-
CcToolchainAttributesProvider.PROVIDER,
97-
ruleContext,
98-
transformedCpu,
99-
compiler,
100-
selectedCcToolchain);
101-
StarlarkFunction getCcToolchainProvider =
102-
(StarlarkFunction) ruleContext.getStarlarkDefinedBuiltin("get_cc_toolchain_provider");
103-
ruleContext.initStarlarkRuleContext();
104-
Object starlarkCcToolchainProvider =
105-
ruleContext.callStarlarkOrThrowRuleError(
106-
getCcToolchainProvider,
107-
ImmutableList.of(
108-
/* ctx */ ruleContext.getStarlarkRuleContext(),
109-
/* attributes */ selectedAttributes,
110-
/* has_apple_fragment */ true),
111-
ImmutableMap.of());
112-
ccToolchainProvider =
113-
starlarkCcToolchainProvider != Starlark.NONE
114-
? (CcToolchainProvider) starlarkCcToolchainProvider
115-
: null;
116-
117-
if (ccToolchainProvider == null) {
118-
// Skyframe restart
119-
return null;
120-
}
121-
}
77+
// This is a platforms build (and the user requested to build this suite explicitly).
78+
// Cc_toolchains provide CcToolchainInfo already. Let's select the CcToolchainProvider from
79+
// toolchains and provide it here as well.
80+
ccToolchainProvider =
81+
selectCcToolchain(
82+
CcToolchainProvider.PROVIDER,
83+
ruleContext,
84+
transformedCpu,
85+
compiler,
86+
selectedCcToolchain);
12287

12388
CcCommon.reportInvalidOptions(ruleContext, cppConfiguration, ccToolchainProvider);
12489

src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,7 @@ public CppConfiguration(BuildOptions options) throws InvalidConfigurationExcepti
292292
defaultInToolRepository = true)
293293
@Nullable
294294
public Label getRuleProvidingCcToolchainProvider() {
295-
if (cppOptions.enableCcToolchainResolution) {
296-
// In case C++ toolchain resolution is enabled, crosstool_top flags are not used.
297-
// Returning null prevents additional work on the flags values and makes it possible to
298-
// remove `--crosstool_top` flags.
299295
return null;
300-
} else {
301-
return cppOptions.crosstoolTop;
302-
}
303296
}
304297

305298
@Nullable
@@ -753,20 +746,6 @@ public boolean collectCodeCoverage() {
753746
return collectCodeCoverage;
754747
}
755748

756-
@StarlarkMethod(
757-
name = "enable_cc_toolchain_resolution",
758-
documented = false,
759-
useStarlarkThread = true)
760-
public boolean enableCcToolchainResolutionForStarlark(StarlarkThread thread)
761-
throws EvalException {
762-
CcModule.checkPrivateStarlarkificationAllowlist(thread);
763-
return enableCcToolchainResolution();
764-
}
765-
766-
public boolean enableCcToolchainResolution() {
767-
return cppOptions.enableCcToolchainResolution;
768-
}
769-
770749
public boolean saveFeatureState() {
771750
return cppOptions.saveFeatureState;
772751
}

src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414

1515
package com.google.devtools.build.lib.rules.cpp;
1616

17-
import static com.google.devtools.build.lib.packages.BuildType.LABEL;
1817
import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
1918

20-
import com.google.common.base.Preconditions;
2119
import com.google.common.collect.ImmutableCollection;
2220
import com.google.common.collect.ImmutableList;
2321
import com.google.common.collect.ImmutableMap;
@@ -131,45 +129,9 @@ public static ImmutableList<String> getLinkopts(RuleContext ruleContext)
131129
return ImmutableList.of();
132130
}
133131

134-
@Nullable
135-
private static CcToolchainProvider getToolchainUsingDefaultCcToolchainAttribute(
136-
RuleContext ruleContext) throws RuleErrorException {
137-
if (ruleContext.attributes().has(CcToolchainRule.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME)) {
138-
return getToolchainUsingAttribute(
139-
ruleContext, CcToolchainRule.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME);
140-
} else if (ruleContext
141-
.attributes()
142-
.has(CcToolchainRule.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME_FOR_STARLARK)) {
143-
return getToolchainUsingAttribute(
144-
ruleContext, CcToolchainRule.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME_FOR_STARLARK);
145-
}
146-
return null;
147-
}
148-
149-
private static CcToolchainProvider getToolchainUsingAttribute(
150-
RuleContext ruleContext, String toolchainAttribute) throws RuleErrorException {
151-
if (!ruleContext.isAttrDefined(toolchainAttribute, LABEL)) {
152-
throw ruleContext.throwWithRuleError(
153-
String.format(
154-
"INTERNAL BLAZE ERROR: Tried to locate a cc_toolchain via the attribute %s, but it"
155-
+ " is not defined",
156-
toolchainAttribute));
157-
}
158-
TransitiveInfoCollection dep = ruleContext.getPrerequisite(toolchainAttribute);
159-
return getToolchainFromLegacyToolchain(ruleContext, dep);
160-
}
161-
162-
/** Returns C++ toolchain, using toolchain resolution or via default cc toolchain attribute */
132+
/** Returns C++ toolchain, using toolchain resolution */
163133
public static CcToolchainProvider getToolchain(RuleContext ruleContext)
164134
throws RuleErrorException {
165-
if (useToolchainResolution(ruleContext)) {
166-
return getToolchainFromPlatformConstraints(ruleContext);
167-
}
168-
return getToolchainUsingDefaultCcToolchainAttribute(ruleContext);
169-
}
170-
171-
private static CcToolchainProvider getToolchainFromPlatformConstraints(RuleContext ruleContext)
172-
throws RuleErrorException {
173135
ToolchainInfo toolchainInfo =
174136
ruleContext.getToolchainInfo(Label.parseCanonicalUnchecked("//tools/cpp:toolchain_type"));
175137
if (toolchainInfo == null) {
@@ -191,15 +153,6 @@ private static CcToolchainProvider getToolchainFromPlatformConstraints(RuleConte
191153
}
192154
}
193155

194-
private static CcToolchainProvider getToolchainFromLegacyToolchain(
195-
RuleContext ruleContext, TransitiveInfoCollection dep) throws RuleErrorException {
196-
// TODO(bazel-team): Consider checking this generally at the attribute level.
197-
if ((dep == null) || (dep.get(CcToolchainProvider.PROVIDER) == null)) {
198-
throw ruleContext.throwWithRuleError("The selected C++ toolchain is not a cc_toolchain rule");
199-
}
200-
return dep.get(CcToolchainProvider.PROVIDER);
201-
}
202-
203156
/** Returns the directory where object files are created. */
204157
public static PathFragment getObjDirectory(Label ruleLabel, boolean siblingRepositoryLayout) {
205158
return getObjDirectory(ruleLabel, false, siblingRepositoryLayout);
@@ -584,12 +537,4 @@ public static boolean useInterfaceSharedLibraries(
584537
return toolchain.supportsInterfaceSharedLibraries(featureConfiguration)
585538
&& cppConfiguration.getUseInterfaceSharedLibraries();
586539
}
587-
588-
static boolean useToolchainResolution(RuleContext ruleContext) {
589-
CppOptions cppOptions =
590-
Preconditions.checkNotNull(
591-
ruleContext.getConfiguration().getOptions().get(CppOptions.class));
592-
593-
return cppOptions.enableCcToolchainResolution;
594-
}
595540
}

src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,11 @@ public String getTypeDescription() {
108108
name = "crosstool_top",
109109
defaultValue = "@bazel_tools//tools/cpp:toolchain",
110110
converter = LabelConverter.class,
111-
documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
111+
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
112112
effectTags = {
113-
OptionEffectTag.LOADING_AND_ANALYSIS,
114-
OptionEffectTag.CHANGES_INPUTS,
115-
OptionEffectTag.AFFECTS_OUTPUTS
113+
OptionEffectTag.NO_OP,
116114
},
117-
help = "The label of the crosstool package to be used for compiling C++ code.")
115+
help = "No-op flag. Will be removed in a future release.")
118116
public Label crosstoolTop;
119117

120118
@Option(
@@ -130,9 +128,7 @@ public String getTypeDescription() {
130128
defaultValue = "null",
131129
documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
132130
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS, OptionEffectTag.EXECUTION},
133-
help =
134-
"The C++ compiler to use for host compilation. It is ignored if --host_crosstool_top "
135-
+ "is not set.")
131+
help = "No-op flag. Will be removed in a future release.")
136132
public String hostCppCompiler;
137133

138134
// This is different from --platform_suffix in that that one is designed to facilitate the
@@ -596,16 +592,9 @@ public Label getMemProfProfileLabel() {
596592
name = "host_crosstool_top",
597593
defaultValue = "null",
598594
converter = LabelConverter.class,
599-
documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
600-
effectTags = {
601-
OptionEffectTag.LOADING_AND_ANALYSIS,
602-
OptionEffectTag.CHANGES_INPUTS,
603-
OptionEffectTag.AFFECTS_OUTPUTS
604-
},
605-
help =
606-
"By default, the --crosstool_top and --compiler options are also used "
607-
+ "for the exec configuration. If this flag is provided, Bazel uses the default libc "
608-
+ "and compiler for the given crosstool_top.")
595+
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
596+
effectTags = {OptionEffectTag.NO_OP},
597+
help = "No-op flag. Will be removed in a future release.")
609598
public Label hostCrosstoolTop;
610599

611600
@Option(
@@ -864,8 +853,8 @@ public Label getMemProfProfileLabel() {
864853
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
865854
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
866855
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
867-
help = "If true, cc rules use toolchain resolution to find the cc_toolchain.")
868-
public boolean enableCcToolchainResolution;
856+
help = "No-op flag. Will be removed in a future release.")
857+
public boolean enableCcToolchainResolutionNoOp;
869858

870859
@Option(
871860
name = "experimental_save_feature_state",
@@ -1090,14 +1079,6 @@ public FragmentOptions getNormalized() {
10901079
newOptions.targetLibcTopLabel = libcTopLabel;
10911080
changed = true;
10921081
}
1093-
if (hostCrosstoolTop == null) {
1094-
// Default to the initial target crosstoolTop.
1095-
newOptions.hostCrosstoolTop = crosstoolTop;
1096-
// Reset this, also, to maintain the invariant that host_compiler is ignored if
1097-
// host_crosstool_top is unset.
1098-
newOptions.hostCppCompiler = cppCompiler;
1099-
changed = true;
1100-
}
11011082
if (changed) {
11021083
return newOptions;
11031084
}

src/main/java/com/google/devtools/build/lib/rules/cpp/FdoHelper.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,9 @@ private static Artifact convertLLVMRawProfileToIndexed(
355355
// Get the zipper binary for unzipping the profile.
356356
Artifact zipperBinaryArtifact = attributes.getZipper();
357357
if (zipperBinaryArtifact == null) {
358-
if (CppHelper.useToolchainResolution(ruleContext)) {
359-
ruleContext.ruleError(
360-
"Zipped profiles are not supported with platforms/toolchains before "
361-
+ "toolchain-transitions are implemented.");
362-
} else {
363-
ruleContext.ruleError("Cannot find zipper binary to unzip the profile");
364-
}
358+
ruleContext.ruleError(
359+
"Zipped profiles are not supported with platforms/toolchains before "
360+
+ "toolchain-transitions are implemented.");
365361
return null;
366362
}
367363

@@ -490,13 +486,9 @@ private static Artifact getMemProfProfileArtifact(
490486
// Get the zipper binary for unzipping the profile.
491487
Artifact zipperBinaryArtifact = attributes.getZipper();
492488
if (zipperBinaryArtifact == null) {
493-
if (CppHelper.useToolchainResolution(ruleContext)) {
494-
ruleContext.ruleError(
495-
"Zipped profiles are not supported with platforms/toolchains before "
496-
+ "toolchain-transitions are implemented.");
497-
} else {
498-
ruleContext.ruleError("Cannot find zipper binary to unzip the profile");
499-
}
489+
ruleContext.ruleError(
490+
"Zipped profiles are not supported with platforms/toolchains before "
491+
+ "toolchain-transitions are implemented.");
500492
return null;
501493
}
502494

src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,16 +1420,6 @@ CppModuleMapT createCppModuleMap(
14201420
String legacyCcFlagsMakeVariable(CcToolchainProviderT ccToolchain, StarlarkThread thread)
14211421
throws EvalException;
14221422

1423-
@StarlarkMethod(
1424-
name = "is_cc_toolchain_resolution_enabled_do_not_use",
1425-
documented = false,
1426-
parameters = {
1427-
@Param(name = "ctx", positional = false, named = true, doc = "The rule context."),
1428-
},
1429-
doc = "Returns true if the --incompatible_enable_cc_toolchain_resolution flag is enabled.",
1430-
useStarlarkThread = true)
1431-
boolean isCcToolchainResolutionEnabled(StarlarkRuleContextT ruleContext, StarlarkThread thread)
1432-
throws EvalException;
14331423

14341424
@StarlarkMethod(
14351425
name = "create_cc_toolchain_config_info",

src/main/starlark/builtins_bzl/common/cc/cc_common.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,9 @@ def _legacy_cc_flags_make_variable_do_not_use(*, cc_toolchain):
524524
return cc_common_internal.legacy_cc_flags_make_variable_do_not_use(cc_toolchain = cc_toolchain)
525525

526526
def _is_cc_toolchain_resolution_enabled_do_not_use(*, ctx):
527-
return cc_common_internal.is_cc_toolchain_resolution_enabled_do_not_use(ctx = ctx)
527+
# Supports public is_cc_toolchain_resolution_enabled_do_not_use
528+
# TODO(b/218795674): remove once uses are cleaned up
529+
return True
528530

529531
def _create_cc_toolchain_config_info(
530532
*,

0 commit comments

Comments
 (0)