diff options
author | 2017-11-28 08:23:54 -0800 | |
---|---|---|
committer | 2017-11-28 08:25:25 -0800 | |
commit | c478aea4c872b7ce3395746fd86168376f909284 (patch) | |
tree | efdf1dad7feb2d6bdf28b6a4524a703d56ab1967 /src/test/java/com/google/devtools/build/lib/rules | |
parent | 0dcf425c840b9b263951b31a6d48965435b206f1 (diff) |
Migrate callsites of CppConfiguation#getCompiler, #getTargetLibc, #getCpu to
CcToolchainProvider. Toolchain information must be removed from
CppConfiguration to allow the c++ rules to use hermetic platforms.
PiperOrigin-RevId: 177163880
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules')
3 files changed, 91 insertions, 9 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/ToolchainTypeTest.java b/src/test/java/com/google/devtools/build/lib/rules/ToolchainTypeTest.java index e3e4fbad15..91ad343ce6 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/ToolchainTypeTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/ToolchainTypeTest.java @@ -17,9 +17,14 @@ import static com.google.common.truth.Truth.assertThat; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.TemplateVariableInfo; +import com.google.devtools.build.lib.analysis.ToolchainContext.ResolvedToolchainProviders; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; +import com.google.devtools.build.lib.analysis.util.ScratchAttributeWriter; +import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.packages.util.MockPlatformSupport; +import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider; import com.google.devtools.build.lib.testutil.TestConstants; +import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -59,4 +64,43 @@ public class ToolchainTypeTest extends BuildViewTestCase { assertThat(cc.get(TemplateVariableInfo.PROVIDER).getVariables()) .containsEntry("TARGET_CPU", "piii"); } + + @Test + public void testGlibcVersionSetInEnv() throws Exception { + MockPlatformSupport.addMockPiiiPlatform( + mockToolsConfig, analysisMock.ccSupport().getMockCrosstoolLabel()); + useConfiguration( + "--enabled_toolchain_types=" + + TestConstants.TOOLS_REPOSITORY + + "//tools/cpp:toolchain_type", + "--experimental_platforms=//mock_platform:mock-piii-platform", + "--extra_toolchains=//mock_platform:toolchain_cc-compiler-piii", + "--make_variables_source=toolchain"); + ConfiguredTarget toolchainType = + getConfiguredTarget(TestConstants.TOOLS_REPOSITORY + "//tools/cpp:toolchain_type"); + Map<String, String> makeVariables = + toolchainType.get(TemplateVariableInfo.PROVIDER).getVariables(); + + ConfiguredTarget target = + ScratchAttributeWriter.fromLabelString(this, "cc_library", "//lib") + .setList("srcs", "a.cc") + .write(); + + ResolvedToolchainProviders providers = + (ResolvedToolchainProviders) + getRuleContext(target).getToolchainContext().getResolvedToolchainProviders(); + CcToolchainProvider toolchainProvider = + (CcToolchainProvider) + providers.getForToolchainType( + Label.parseAbsolute(TestConstants.TOOLS_REPOSITORY + "//tools/cpp:toolchain_type")); + + String targetLibc = toolchainProvider.getTargetLibc(); + String glibcVersion = makeVariables.get("GLIBC_VERSION"); + assertThat(glibcVersion).isNotNull(); + if (targetLibc.startsWith("glibc-")) { + assertThat(glibcVersion).isEqualTo(targetLibc.substring("glibc-".length())); + } else { + assertThat(glibcVersion).isEqualTo(targetLibc); + } + } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java index d94be0f8cb..757c97d57f 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java @@ -446,6 +446,44 @@ public class CcToolchainTest extends BuildViewTestCase { } } + // Regression test for bug 2088255: + // "StringIndexOutOfBoundsException in BuildConfiguration.<init>()" + @Test + public void testShortLibcVersion() throws Exception { + scratch.file( + "a/BUILD", + "filegroup(", + " name='empty')", + "filegroup(", + " name = 'banana',", + " srcs = ['banana1', 'banana2'])", + "cc_toolchain(", + " name = 'b',", + " cpu = 'banana',", + " all_files = ':banana',", + " compiler_files = ':empty',", + " dwp_files = ':empty',", + " linker_files = ':empty',", + " strip_files = ':empty',", + " objcopy_files = ':empty',", + " dynamic_runtime_libs = [':empty'],", + " static_runtime_libs = [':empty'])"); + + getAnalysisMock() + .ccSupport() + .setupCrosstool( + mockToolsConfig, + CrosstoolConfig.CToolchain.newBuilder().setTargetLibc("2.3.6").buildPartial()); + + useConfiguration(); + + ConfiguredTarget target = getConfiguredTarget("//a:b"); + CcToolchainProvider toolchainProvider = + (CcToolchainProvider) target.get(ToolchainInfo.PROVIDER); + + assertThat(toolchainProvider.getTargetLibc()).isEqualTo("2.3.6"); + } + public void assertInvalidIncludeDirectoryMessage(String entry, String messageRegex) throws Exception { try { diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoaderTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoaderTest.java index d1029b84f7..c3e5a9c10f 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoaderTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoaderTest.java @@ -182,9 +182,9 @@ public class CrosstoolConfigurationLoaderTest extends AnalysisTestCase { assertThat(toolchain.getToolchainIdentifier()).isEqualTo("toolchain-identifier"); assertThat(ccProvider.getHostSystemName()).isEqualTo("host-system-name"); - assertThat(toolchain.getCompiler()).isEqualTo("compiler"); - assertThat(toolchain.getTargetLibc()).isEqualTo("target-libc"); - assertThat(toolchain.getTargetCpu()).isEqualTo("piii"); + assertThat(ccProvider.getCompiler()).isEqualTo("compiler"); + assertThat(ccProvider.getTargetLibc()).isEqualTo("target-libc"); + assertThat(ccProvider.getTargetCpu()).isEqualTo("piii"); assertThat(ccProvider.getTargetGnuSystemName()).isEqualTo("target-system-name"); assertThat(toolchain.getToolPathFragment(Tool.AR)).isEqualTo(getToolPath("/path-to-ar")); @@ -496,9 +496,9 @@ public class CrosstoolConfigurationLoaderTest extends AnalysisTestCase { assertThat(toolchainA.getToolchainIdentifier()).isEqualTo("toolchain-identifier-A"); assertThat(ccProviderA.getHostSystemName()).isEqualTo("host-system-name-A"); assertThat(ccProviderA.getTargetGnuSystemName()).isEqualTo("target-system-name-A"); - assertThat(toolchainA.getTargetCpu()).isEqualTo("piii"); - assertThat(toolchainA.getTargetLibc()).isEqualTo("target-libc-A"); - assertThat(toolchainA.getCompiler()).isEqualTo("compiler-A"); + assertThat(ccProviderA.getTargetCpu()).isEqualTo("piii"); + assertThat(ccProviderA.getTargetLibc()).isEqualTo("target-libc-A"); + assertThat(ccProviderA.getCompiler()).isEqualTo("compiler-A"); assertThat(ccProviderA.getAbi()).isEqualTo("abi-version-A"); assertThat(ccProviderA.getAbiGlibcVersion()).isEqualTo("abi-libc-version-A"); assertThat(toolchainA.getToolPathFragment(Tool.AR)).isEqualTo(getToolPath("path/to/ar-A")); @@ -628,9 +628,9 @@ public class CrosstoolConfigurationLoaderTest extends AnalysisTestCase { assertThat(toolchainC.getToolchainIdentifier()).isEqualTo("toolchain-identifier-C"); assertThat(ccProviderC.getHostSystemName()).isEqualTo("host-system-name-C"); assertThat(ccProviderC.getTargetGnuSystemName()).isEqualTo("target-system-name-C"); - assertThat(toolchainC.getTargetCpu()).isEqualTo("piii"); - assertThat(toolchainC.getTargetLibc()).isEqualTo("target-libc-C"); - assertThat(toolchainC.getCompiler()).isEqualTo("compiler-C"); + assertThat(ccProviderC.getTargetCpu()).isEqualTo("piii"); + assertThat(ccProviderC.getTargetLibc()).isEqualTo("target-libc-C"); + assertThat(ccProviderC.getCompiler()).isEqualTo("compiler-C"); assertThat(ccProviderC.getAbi()).isEqualTo("abi-version-C"); assertThat(ccProviderC.getAbiGlibcVersion()).isEqualTo("abi-libc-version-C"); // Don't bother with testing the list of tools again. |