Skip to content

Commit f2be11d

Browse files
hlopkokatre
authored andcommitted
Read the CROSSTOOL from the package of the current cc_toolchain, not from --crosstool_top
This will make the behavior work properly when using platforms, and it will fix recurring issues when cc_toolchain_suite and cc_toolchain are built as a top level targets, without setting --crosstool_top (that resulted in trying to associate cc_toolchain with an unrelated CROSSTOOL file and fail the build). This could also happen when using `bazel cquery` or `bazel aquery`. RELNOTES: CROSSTOOL file is now read from the package of cc_toolchain, not from the package of cc_toolchain_suite. This is not expected to break anybody since cc_toolchain_suite and cc_toolchain are commonly in the same package. PiperOrigin-RevId: 218516709
1 parent 7c31965 commit f2be11d

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ public SkyValue compute(SkyKey skyKey, Environment env)
6767
}
6868

6969
CrosstoolRelease crosstoolRelease = null;
70-
if (key.getCcToolchainSuiteLabel() != null) {
70+
if (key.getPackageWithCrosstoolInIt() != null) {
7171
try {
7272
// 1. Lookup the package to handle multiple package roots (PackageLookupValue)
73-
PackageIdentifier packageIdentifier = key.getCcToolchainSuiteLabel().getPackageIdentifier();
73+
PackageIdentifier packageIdentifier = key.getPackageWithCrosstoolInIt();
7474
PackageLookupValue crosstoolPackageValue =
7575
(PackageLookupValue) env.getValue(PackageLookupValue.key(packageIdentifier));
7676
if (env.valuesMissing()) {

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
package com.google.devtools.build.lib.rules.cpp;
1515

1616
import com.google.common.collect.Interner;
17-
import com.google.devtools.build.lib.cmdline.Label;
17+
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
1818
import com.google.devtools.build.lib.concurrent.BlazeInterners;
1919
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
2020
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
@@ -49,22 +49,22 @@ public static class Key implements SkyKey {
4949
private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
5050

5151
@Nullable private final PathFragment fdoZipPath;
52-
@Nullable private final Label ccToolchainSuiteLabel;
52+
@Nullable private final PackageIdentifier packageWithCrosstoolInIt;
5353

54-
private Key(PathFragment fdoZipPath, Label ccToolchainSuiteLabel) {
54+
private Key(PathFragment fdoZipPath, PackageIdentifier packageWithCrosstoolInIt) {
5555
this.fdoZipPath = fdoZipPath;
56-
this.ccToolchainSuiteLabel = ccToolchainSuiteLabel;
56+
this.packageWithCrosstoolInIt = packageWithCrosstoolInIt;
5757
}
5858

5959
@AutoCodec.Instantiator
6060
@AutoCodec.VisibleForSerialization
61-
static Key of(PathFragment fdoZipPath, Label ccToolchainSuiteLabel) {
62-
return interner.intern(new Key(fdoZipPath, ccToolchainSuiteLabel));
61+
static Key of(PathFragment fdoZipPath, PackageIdentifier packageWithCrosstoolInIt) {
62+
return interner.intern(new Key(fdoZipPath, packageWithCrosstoolInIt));
6363
}
6464

6565
@Nullable
66-
public Label getCcToolchainSuiteLabel() {
67-
return ccToolchainSuiteLabel;
66+
public PackageIdentifier getPackageWithCrosstoolInIt() {
67+
return packageWithCrosstoolInIt;
6868
}
6969

7070
@Nullable
@@ -82,13 +82,13 @@ public boolean equals(Object o) {
8282
}
8383
Key key = (Key) o;
8484
return Objects.equals(fdoZipPath, key.fdoZipPath)
85-
&& Objects.equals(ccToolchainSuiteLabel, key.ccToolchainSuiteLabel);
85+
&& Objects.equals(packageWithCrosstoolInIt, key.packageWithCrosstoolInIt);
8686
}
8787

8888
@Override
8989
public int hashCode() {
9090

91-
return Objects.hash(fdoZipPath, ccToolchainSuiteLabel);
91+
return Objects.hash(fdoZipPath, packageWithCrosstoolInIt);
9292
}
9393

9494
@Override
@@ -118,7 +118,7 @@ public CrosstoolRelease getCrosstoolRelease() {
118118
return crosstoolRelease;
119119
}
120120

121-
public static SkyKey key(PathFragment fdoZipPath, Label ccToolchainSuiteLabel) {
122-
return Key.of(fdoZipPath, ccToolchainSuiteLabel);
121+
public static SkyKey key(PathFragment fdoZipPath, PackageIdentifier packageWithCrosstoolInIt) {
122+
return Key.of(fdoZipPath, packageWithCrosstoolInIt);
123123
}
124124
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,12 @@ static CcToolchainProvider getCcToolchainProvider(
404404

405405
// Is there a toolchain proto available on the target directly?
406406
CToolchain toolchain = parseToolchainFromAttributes(ruleContext, attributes);
407-
Label ccToolchainSuiteLabelIfNeeded = null;
407+
PackageIdentifier packageWithCrosstoolInIt = null;
408408
if (toolchain == null && cppConfiguration.getCrosstoolFromCcToolchainProtoAttribute() == null) {
409-
ccToolchainSuiteLabelIfNeeded = cppConfiguration.getCrosstoolTop();
409+
packageWithCrosstoolInIt = ruleContext.getLabel().getPackageIdentifier();
410410
}
411411

412-
SkyKey ccSupportKey = CcSkyframeSupportValue.key(fdoZip, ccToolchainSuiteLabelIfNeeded);
412+
SkyKey ccSupportKey = CcSkyframeSupportValue.key(fdoZip, packageWithCrosstoolInIt);
413413

414414
SkyFunction.Environment skyframeEnv = ruleContext.getAnalysisEnvironment().getSkyframeEnv();
415415
CcSkyframeSupportValue ccSkyframeSupportValue;

src/test/java/com/google/devtools/build/lib/analysis/LicensingTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ public void testCcToolchainLicenseOverride() throws Exception {
468468
" all_files = ':every-file',",
469469
" dynamic_runtime_libs = ['dynamic-runtime-libs-cherry'],",
470470
" static_runtime_libs = ['static-runtime-libs-cherry'])");
471+
scratch.file("c/CROSSTOOL", AnalysisMock.get().ccSupport().readCrosstoolFile());
471472

472473
ConfiguredTarget target = getConfiguredTarget("//c:c");
473474
Map<Label, License> expected = licenses("//c:c", "notice");

src/test/java/com/google/devtools/build/lib/rules/cpp/CcHostToolchainAliasTest.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,16 @@ public void testCcHostToolchainAliasRuleHasHostConfiguration() throws Exception
4242

4343
@Test
4444
public void testThatHostCrosstoolTopCommandLineArgumentWorks() throws Exception {
45-
4645
scratch.file(
47-
"t/BUILD",
46+
"b/BUILD",
4847
"cc_toolchain_suite(",
4948
" name = 'my_custom_toolchain_suite',",
5049
" toolchains = {",
5150
" 'k8|gcc-4.4.0': '//b:toolchain_b',",
5251
" 'k8|compiler': '//b:toolchain_b',",
5352
" 'x64_windows|windows_msys64': '//b:toolchain_b',",
5453
" 'darwin|compiler': '//b:toolchain_b',",
55-
56-
"})");
57-
58-
scratch.file("t/CROSSTOOL", AnalysisMock.get().ccSupport().readCrosstoolFile());
59-
60-
scratch.file(
61-
"b/BUILD",
54+
"})",
6255
"cc_toolchain(",
6356
" name = 'toolchain_b',",
6457
" cpu = 'ED-E',",
@@ -72,9 +65,11 @@ public void testThatHostCrosstoolTopCommandLineArgumentWorks() throws Exception
7265
" objcopy_files = ':empty',",
7366
" dynamic_runtime_libs = [':empty'],",
7467
" static_runtime_libs = [':empty'])");
68+
scratch.file("b/CROSSTOOL", AnalysisMock.get().ccSupport().readCrosstoolFile());
69+
7570
scratch.file("a/BUILD", "cc_host_toolchain_alias(name='current_cc_host_toolchain')");
7671

77-
useConfiguration("--host_crosstool_top=//t:my_custom_toolchain_suite");
72+
useConfiguration("--host_crosstool_top=//b:my_custom_toolchain_suite");
7873
ConfiguredTarget target = getConfiguredTarget("//a:current_cc_host_toolchain");
7974

8075
assertThat(target.getLabel()).isEqualTo(Label.parseAbsoluteUnchecked("//b:toolchain_b"));

src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
2424
import com.google.devtools.build.lib.analysis.RuleContext;
2525
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
26+
import com.google.devtools.build.lib.analysis.util.AnalysisMock;
2627
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
2728
import com.google.devtools.build.lib.packages.util.MockCcSupport;
2829
import com.google.devtools.build.lib.packages.util.ResourceLoader;
@@ -341,6 +342,7 @@ public void testDynamicMode() throws Exception {
341342
" objcopy_files = ':empty',",
342343
" dynamic_runtime_libs = [':empty'],",
343344
" static_runtime_libs = [':empty'])");
345+
scratch.file("a/CROSSTOOL", AnalysisMock.get().ccSupport().readCrosstoolFile());
344346

345347
// Check defaults.
346348
useConfiguration();
@@ -682,6 +684,7 @@ public void testZipperInclusionDependsOnFdoOptimization() throws Exception {
682684
"fdo/BUILD",
683685
"exports_files(['my_profile.afdo'])",
684686
"fdo_profile(name = 'fdo', profile = ':my_profile.profdata')");
687+
scratch.file("a/CROSSTOOL", AnalysisMock.get().ccSupport().readCrosstoolFile());
685688

686689
useConfiguration();
687690
assertThat(getPrerequisites(getConfiguredTarget("//a:b"), ":zipper")).isEmpty();
@@ -768,6 +771,7 @@ public void testToolchainFromSkylarkRule() throws Exception {
768771
" dynamic_runtime_libs = [':empty'],",
769772
" static_runtime_libs = [':empty'],",
770773
" toolchain_config = ':toolchain_config')");
774+
scratch.file("a/CROSSTOOL", AnalysisMock.get().ccSupport().readCrosstoolFile());
771775

772776
scratch.file(
773777
"a/crosstool_rule.bzl",

0 commit comments

Comments
 (0)