diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppSysrootTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppSysrootTest.java index 2b0fc1207e292e..84114d54b7192c 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppSysrootTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppSysrootTest.java @@ -58,17 +58,16 @@ void testCCFlagsContainsSysroot( CcToolchainProvider getCcToolchainProvider(BuildConfigurationValue configuration) throws Exception { - CppConfiguration cppConfiguration = configuration.getFragment(CppConfiguration.class); - return Preconditions.checkNotNull( - getConfiguredTarget(cppConfiguration.getRuleProvidingCcToolchainProvider(), configuration) - .get(CcToolchainProvider.PROVIDER)); + // use dummy library to get C++ toolchain from toolchain resolution + RuleContext ruleContext = + getRuleContext(getConfiguredTarget(Label.parseCanonical("//dummy:library"), configuration)); + return Preconditions.checkNotNull(CppHelper.getToolchain(ruleContext)); } @Test public void testHostGrteTop() throws Exception { scratch.file("a/grte/top/BUILD", "filegroup(name='everything')", "cc_library(name='library')"); - useConfiguration( - "--host_grte_top=//a/grte/top", "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--host_grte_top=//a/grte/top"); BuildConfigurationValue target = getTargetConfiguration(); CcToolchainProvider targetCcProvider = getCcToolchainProvider(target); BuildConfigurationValue exec = getExecConfiguration(); @@ -82,10 +81,7 @@ public void testHostGrteTop() throws Exception { public void testOverrideHostGrteTop() throws Exception { scratch.file("a/grte/top/BUILD", "filegroup(name='everything')"); scratch.file("b/grte/top/BUILD", "filegroup(name='everything')"); - useConfiguration( - "--grte_top=//a/grte/top", - "--host_grte_top=//b/grte/top", - "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--grte_top=//a/grte/top", "--host_grte_top=//b/grte/top"); BuildConfigurationValue target = getTargetConfiguration(); CcToolchainProvider targetCcProvider = getCcToolchainProvider(target); BuildConfigurationValue exec = getExecConfiguration(); @@ -104,7 +100,7 @@ public void testOverrideHostGrteTop() throws Exception { public void testGrteTopAlias() throws Exception { scratch.file("a/grte/top/BUILD", "filegroup(name='everything')"); scratch.file("b/grte/top/BUILD", "alias(name='everything', actual='//a/grte/top:everything')"); - useConfiguration("--grte_top=//b/grte/top", "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--grte_top=//b/grte/top"); BuildConfigurationValue target = getTargetConfiguration(); CcToolchainProvider targetCcProvider = getCcToolchainProvider(target); @@ -117,16 +113,13 @@ public void testGrteTopAlias() throws Exception { @Test public void testSysroot() throws Exception { // BuildConfigurationValue shouldn't provide a sysroot option by default. - useConfiguration("--cpu=k8", "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--cpu=k8"); BuildConfigurationValue config = getTargetConfiguration(); testCCFlagsContainsSysroot(config, "/usr/grte/v1", true); scratch.file("a/grte/top/BUILD", "filegroup(name='everything')"); // BuildConfigurationValue should work with label grte_top options. - useConfiguration( - "--cpu=k8", - "--grte_top=//a/grte/top:everything", - "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--cpu=k8", "--grte_top=//a/grte/top:everything"); config = getTargetConfiguration(); testCCFlagsContainsSysroot(config, "a/grte/top", true); } @@ -139,8 +132,7 @@ public void testSysrootInFeatureConfigBlocksLegacySysroot() throws Exception { mockToolsConfig, CcToolchainConfig.builder().withActionConfigs("sysroot_in_action_config")); scratch.overwriteFile("a/grte/top/BUILD", "filegroup(name='everything')"); - useConfiguration( - "--grte_top=//a/grte/top:everything", "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--grte_top=//a/grte/top:everything"); RuleContext ruleContext = getRuleContext(getConfiguredTarget(Label.parseCanonical("//dummy:library"), targetConfig)); ConfigurationMakeVariableContext context = @@ -158,26 +150,20 @@ public void testSysrootInFeatureConfigBlocksLegacySysroot() throws Exception { public void testSysrootWithExecConfig() throws Exception { // The exec BuildConfigurationValue shouldn't provide a sysroot option by default. for (String cpu : new String[] {"piii", "k8"}) { - useConfiguration("--cpu=" + cpu, "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--cpu=" + cpu); BuildConfigurationValue config = getExecConfiguration(); testCCFlagsContainsSysroot(config, "/usr/grte/v1", true); } // The exec BuildConfigurationValue should work with label grte_top options. scratch.file("a/grte/top/BUILD", "filegroup(name='everything')"); for (String cpu : new String[] {"piii", "k8"}) { - useConfiguration( - "--cpu=" + cpu, - "--host_grte_top=//a/grte/top", - "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--cpu=" + cpu, "--host_grte_top=//a/grte/top"); BuildConfigurationValue config = getExecConfiguration(); testCCFlagsContainsSysroot(config, "a/grte/top", true); // "--grte_top" does *not* set the exec grte_top, // so we don't get "a/grte/top" here, but instead the default "/usr/grte/v1" - useConfiguration( - "--cpu=" + cpu, - "--grte_top=//a/grte/top", - "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--cpu=" + cpu, "--grte_top=//a/grte/top"); config = getExecConfiguration(); testCCFlagsContainsSysroot(config, "/usr/grte/v1", true); @@ -186,8 +172,7 @@ public void testSysrootWithExecConfig() throws Exception { useConfiguration( "--cpu=" + cpu, "--grte_top=//a/grte/top", - "--host_crosstool_top=" + analysisMock.ccSupport().getMockCrosstoolLabel(), - "--noincompatible_enable_cc_toolchain_resolution"); + "--host_crosstool_top=" + analysisMock.ccSupport().getMockCrosstoolLabel()); config = getExecConfiguration(); testCCFlagsContainsSysroot(config, "/usr/grte/v1", true); } @@ -209,15 +194,11 @@ public void testConfigurableSysroot() throws Exception { " '//conditions:default' : '//b/grte/top:everything'}", " )", ")"); - useConfiguration( - "--grte_top=//c/grte/top:everything", "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--grte_top=//c/grte/top:everything"); CcToolchainProvider ccProvider = getCcToolchainProvider(getTargetConfiguration()); assertThat(ccProvider.getSysroot()).isEqualTo("b/grte/top"); - useConfiguration( - "--grte_top=//c/grte/top:everything", - "--define=override_grte_top=1", - "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--grte_top=//c/grte/top:everything", "--define=override_grte_top=1"); ccProvider = getCcToolchainProvider(getTargetConfiguration()); assertThat(ccProvider.getSysroot()).isEqualTo("a/grte/top"); }