Skip to content

Commit

Permalink
Flip the flag to move CcToolchainProvider creation to cc_toolchain_suite
Browse files Browse the repository at this point in the history
This way, we don't have to do any package loading in the CppConfiguration
(yay!). cc_toolchain now provides CcToolchainAttributesProvider, a lightweight
representation of its attributes, and cc_toolchain_suite will select one and use
it to create the full CcToolchainProvider.

This cl should be backwards compatible under normal use, but there are some
behavioral differences:

* Before, cc_toolchain_suite was not analyzed
* Before, only the selected cc_toolchain was analyzed
* Before, cc_toolchain_alias returned cc_toolchain target (observable from aspects)
* Now, cc_toolchain_suite is analyzed
* Now, all cc_toolchains of the cc_toolchain_suite are analyzed
* Before, cc_toolchain_alias returns cc_toolchain_suite target (observable from aspects)

Progress on #6072
Fixes #6537

RELNOTES: None.
PiperOrigin-RevId: 222289686
  • Loading branch information
hlopko authored and Copybara-Service committed Nov 20, 2018
1 parent 4a74c52 commit 0fbe465
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ public Label getFdoPrefetchHintsLabel() {

@Option(
name = "incompatible_provide_cc_toolchain_info_from_cc_toolchain_suite",
defaultValue = "false",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,11 @@ public void testHostCrosstoolTop() throws Exception {
BuildConfigurationCollection configs = createCollection("--cpu=piii");
BuildConfiguration config = Iterables.getOnlyElement(configs.getTargetConfigurations());
assertThat(config.getFragment(CppConfiguration.class).getRuleProvidingCcToolchainProvider())
.isEqualTo(
Label.parseAbsoluteUnchecked(
"//third_party/crosstool/mock:cc-compiler-piii-gcc-4.4.0"));
.isEqualTo(Label.parseAbsoluteUnchecked("//third_party/crosstool/mock:everything"));

BuildConfiguration hostConfig = configs.getHostConfiguration();
assertThat(hostConfig.getFragment(CppConfiguration.class).getRuleProvidingCcToolchainProvider())
.isEqualTo(
Label.parseAbsoluteUnchecked("//third_party/crosstool/mock:cc-compiler-k8-gcc-4.4.0"));
.isEqualTo(Label.parseAbsoluteUnchecked("//third_party/crosstool/mock:everything"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void testThatHostCrosstoolTopCommandLineArgumentWorks() throws Exception
useConfiguration("--host_crosstool_top=//b:my_custom_toolchain_suite", "--host_cpu=k8");
ConfiguredTarget target = getConfiguredTarget("//a:current_cc_host_toolchain");

assertThat(target.getLabel()).isEqualTo(Label.parseAbsoluteUnchecked("//b:toolchain_b"));
assertThat(target.getLabel())
.isEqualTo(Label.parseAbsoluteUnchecked("//b:my_custom_toolchain_suite"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ public void testOptionalGcovTool() throws Exception {
"a/BUILD",
"filegroup(",
" name='empty')",
"cc_toolchain(",
"cc_toolchain_suite(",
" name = 'a',",
" toolchains = { 'k8': ':b' },",
")",
"cc_toolchain(",
" name = 'b',",
" cpu = 'banana',",
" all_files = ':empty',",
" ar_files = ':empty',",
Expand Down Expand Up @@ -216,6 +220,7 @@ public void testOptionalGcovTool() throws Exception {
" target_libc: \"banana\"",
" \"\"\")");

useConfiguration("--cpu=k8", "--host_cpu=k8");
CcToolchainProvider ccToolchainProvider =
(CcToolchainProvider) getConfiguredTarget("//a:a").get(ToolchainInfo.PROVIDER);
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
Expand All @@ -227,6 +232,10 @@ public void testOptionalGcovTool() throws Exception {
"b/BUILD",
"filegroup(",
" name='empty')",
"cc_toolchain_suite(",
" name = 'a',",
" toolchains = { 'k8': ':b' },",
")",
"cc_toolchain(",
" name = 'b',",
" cpu = 'banana',",
Expand Down Expand Up @@ -262,7 +271,7 @@ public void testOptionalGcovTool() throws Exception {
" \"\"\")");

ccToolchainProvider =
(CcToolchainProvider) getConfiguredTarget("//b:b").get(ToolchainInfo.PROVIDER);
(CcToolchainProvider) getConfiguredTarget("//b:a").get(ToolchainInfo.PROVIDER);
builder = ImmutableMap.builder();
ccToolchainProvider.addGlobalMakeVariables(builder);
assertThat(builder.build().get("GCOVTOOL")).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ public void testCcToolchainLabelFromCpuCompilerAttributes() throws Exception {
useConfiguration("--crosstool_top=//cc:suite", "--cpu=k8", "--host_cpu=k8");
ConfiguredTarget c = getConfiguredTarget("//a:b");
CppConfiguration config = getConfiguration(c).getFragment(CppConfiguration.class);
assertThat(config.getRuleProvidingCcToolchainProvider().toString())
.isEqualTo("//cc:cc-compiler-fruitie");
assertThat(config.getRuleProvidingCcToolchainProvider().toString()).isEqualTo("//cc:suite");

useConfiguration(
"--crosstool_top=//cc:suite",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ public void testToolchainFromStarlarkRule() throws Exception {

useConfiguration("--cpu=k8", "--experimental_enable_cc_toolchain_config_info");

ConfiguredTarget target = getConfiguredTarget("//a:b");
ConfiguredTarget target = getConfiguredTarget("//a:a");
CcToolchainProvider toolchainProvider =
(CcToolchainProvider) target.get(ToolchainInfo.PROVIDER);

Expand All @@ -648,7 +648,7 @@ public void testToolPathsInToolchainFromStarlarkRule() throws Exception {

useConfiguration("--cpu=k8", "--experimental_enable_cc_toolchain_config_info");

ConfiguredTarget target = getConfiguredTarget("//a:b");
ConfiguredTarget target = getConfiguredTarget("//a:a");
CcToolchainProvider toolchainProvider =
(CcToolchainProvider) target.get(ToolchainInfo.PROVIDER);
assertThat(toolchainProvider.getToolPathFragment(Tool.AR).toString())
Expand All @@ -664,6 +664,10 @@ private void writeStarlarkRule() throws IOException {
"cc_toolchain_config_rule(name = 'toolchain_config')",
"filegroup(",
" name='empty')",
"cc_toolchain_suite(",
" name = 'a',",
" toolchains = { 'k8': ':b' },",
")",
"cc_toolchain(",
" name = 'b',",
" cpu = 'banana',",
Expand Down Expand Up @@ -917,6 +921,10 @@ public void testSysroot_fromCcToolchain() throws Exception {
"a/BUILD",
"filegroup(",
" name='empty')",
"cc_toolchain_suite(",
" name = 'a',",
" toolchains = { 'k8': ':b' },",
")",
"cc_toolchain(",
" name = 'b',",
" cpu = 'banana',",
Expand Down Expand Up @@ -952,7 +960,7 @@ public void testSysroot_fromCcToolchain() throws Exception {
mockToolsConfig,
CrosstoolConfig.CToolchain.newBuilder().setDefaultGrteTop("//libc1").buildPartial());
useConfiguration("--cpu=k8");
ConfiguredTarget target = getConfiguredTarget("//a:b");
ConfiguredTarget target = getConfiguredTarget("//a:a");
CcToolchainProvider ccToolchainProvider =
(CcToolchainProvider) target.get(CcToolchainProvider.PROVIDER);

Expand All @@ -965,6 +973,10 @@ public void testSysroot_fromFlag() throws Exception {
"a/BUILD",
"filegroup(",
" name='empty')",
"cc_toolchain_suite(",
" name = 'a',",
" toolchains = { 'k8': ':b' },",
")",
"cc_toolchain(",
" name = 'b',",
" cpu = 'banana',",
Expand Down Expand Up @@ -1003,7 +1015,7 @@ public void testSysroot_fromFlag() throws Exception {
CrosstoolConfig.CToolchain.newBuilder().setDefaultGrteTop("//libc1").buildPartial());
useConfiguration(
"--cpu=k8", "--grte_top=//libc3", "--incompatible_disable_sysroot_from_configuration");
ConfiguredTarget target = getConfiguredTarget("//a:b");
ConfiguredTarget target = getConfiguredTarget("//a:a");
CcToolchainProvider ccToolchainProvider =
(CcToolchainProvider) target.get(CcToolchainProvider.PROVIDER);

Expand Down

0 comments on commit 0fbe465

Please sign in to comment.