diff options
author | 2016-09-12 15:57:06 +0000 | |
---|---|---|
committer | 2016-09-12 17:09:41 +0000 | |
commit | 111006ea81de3cabf1ad30a3fcd83035f8f888a3 (patch) | |
tree | 144566b6cb41fbe0a2e651fbe49686fe5f0d5487 /src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java | |
parent | 4b0832808ab1260ba75c08342ec359cfdc2c313a (diff) |
Automatically detect the setting for --cpu.
In some cases, Bazel has already been doing this.
In other cases, Bazel tried to infer the default cpu from the CROSSTOOL, but it
did not do so consistently across different configuration fragments. I.e.,
Bazel ended up with an inconsistent set of toolchains for e.g., Python, C++,
and Java.
After this change, Bazel ignores any default_cpu setting in the CROSSTOOL.
Note that the Jvm is still inconsistent with all others, as it uses "default"
as the cpu value and ignores both command-line-specified and CROSSTOOL-specified
values.
--
MOS_MIGRATED_REVID=132879102
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java index 65ec00df24..aabf2dc130 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java @@ -101,12 +101,14 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { @Test public void testFilesToBuild() throws Exception { ConfiguredTarget hello = getConfiguredTarget("//hello:hello"); + String cpu = getTargetConfiguration().getCpu(); Artifact archive = getBinArtifact("libhello.a", hello); Artifact implSharedObject = getBinArtifact("libhello.so", hello); Artifact implInterfaceSharedObject = getBinArtifact("libhello.ifso", hello); - Artifact implSharedObjectLink = getSharedArtifact("_solib_k8/libhello_Slibhello.so", hello); + Artifact implSharedObjectLink = + getSharedArtifact("_solib_" + cpu + "/libhello_Slibhello.so", hello); Artifact implInterfaceSharedObjectLink = - getSharedArtifact("_solib_k8/libhello_Slibhello.ifso", hello); + getSharedArtifact("_solib_" + cpu + "/libhello_Slibhello.ifso", hello); assertThat(getFilesToBuild(hello)).containsExactly(archive, implSharedObject, implInterfaceSharedObject); assertThat(LinkerInputs.toLibraryArtifacts( @@ -157,11 +159,14 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { public void testFilesToBuildWithInterfaceSharedObjects() throws Exception { useConfiguration("--interface_shared_objects"); ConfiguredTarget hello = getConfiguredTarget("//hello:hello"); + String cpu = getTargetConfiguration().getCpu(); Artifact archive = getBinArtifact("libhello.a", hello); Artifact sharedObject = getBinArtifact("libhello.ifso", hello); Artifact implSharedObject = getBinArtifact("libhello.so", hello); - Artifact sharedObjectLink = getSharedArtifact("_solib_k8/libhello_Slibhello.ifso", hello); - Artifact implSharedObjectLink = getSharedArtifact("_solib_k8/libhello_Slibhello.so", hello); + Artifact sharedObjectLink = + getSharedArtifact("_solib_" + cpu + "/libhello_Slibhello.ifso", hello); + Artifact implSharedObjectLink = + getSharedArtifact("_solib_" + cpu + "/libhello_Slibhello.so", hello); assertThat(getFilesToBuild(hello)).containsExactly(archive, sharedObject, implSharedObject); assertThat(LinkerInputs.toLibraryArtifacts( hello.getProvider(CcNativeLibraryProvider.class).getTransitiveCcNativeLibraries())) @@ -367,6 +372,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { @Test public void testArtifactsToAlwaysBuild() throws Exception { + useConfiguration("--cpu=k8"); // ArtifactsToAlwaysBuild should apply both for static libraries. ConfiguredTarget helloStatic = getConfiguredTarget("//hello:hello_static"); assertEquals(ImmutableSet.of("bin hello/_objs/hello_static/hello/hello.pic.o"), @@ -384,6 +390,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { @Test public void testTransitiveArtifactsToAlwaysBuildStatic() throws Exception { + useConfiguration("--cpu=k8"); ConfiguredTarget x = scratchConfiguredTarget( "foo", "x", "cc_library(name = 'x', srcs = ['x.cc'], deps = [':y'], linkstatic = 1)", @@ -402,7 +409,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { AnalysisMock.get() .ccSupport() .setupCrosstool(mockToolsConfig, MockCcSupport.HEADER_MODULES_FEATURE_CONFIGURATION); - useConfiguration(); + useConfiguration("--cpu=k8"); ConfiguredTarget x = scratchConfiguredTarget( "foo", @@ -421,7 +428,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { AnalysisMock.get() .ccSupport() .setupCrosstool(mockToolsConfig, MockCcSupport.HEADER_MODULES_FEATURE_CONFIGURATION); - useConfiguration("--collect_code_coverage"); + useConfiguration("--cpu=k8", "--collect_code_coverage"); ConfiguredTarget x = scratchConfiguredTarget( "foo", @@ -509,7 +516,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { + "feature { name: 'header_modules' implies: 'use_header_modules' }" + "feature { name: 'module_maps' }" + "feature { name: 'use_header_modules' }"); - useConfiguration(); + useConfiguration("--cpu=k8"); scratch.file("module/BUILD", "package(features = ['header_modules'])", "cc_library(", @@ -614,7 +621,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { AnalysisMock.get() .ccSupport() .setupCrosstool(mockToolsConfig, MockCcSupport.HEADER_MODULES_FEATURE_CONFIGURATION); - useConfiguration(); + useConfiguration("--cpu=k8"); setupPackagesForModuleTests(/*useHeaderModules=*/false); // The //nomodule:f target only depends on non-module targets, thus it should be module-free. @@ -691,7 +698,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { mockToolsConfig, MockCcSupport.HEADER_MODULES_FEATURE_CONFIGURATION + "feature { name: 'transitive_module_maps' }"); - useConfiguration("--features=transitive_module_maps"); + useConfiguration("--cpu=k8", "--features=transitive_module_maps"); setupPackagesForModuleTests(/*useHeaderModules=*/true); getConfiguredTarget("//nomodule:f"); @@ -740,7 +747,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { AnalysisMock.get() .ccSupport() .setupCrosstool(mockToolsConfig, MockCcSupport.HEADER_MODULES_FEATURE_CONFIGURATION); - useConfiguration(); + useConfiguration("--cpu=k8"); setupPackagesForModuleTests( /*useHeaderModules=*/true); getConfiguredTarget("//nomodule:f"); @@ -781,7 +788,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { mockToolsConfig, MockCcSupport.HEADER_MODULES_FEATURE_CONFIGURATION + "feature { name: 'header_module_includes_dependencies' }"); - useConfiguration(); + useConfiguration("--cpu=k8"); setupPackagesForModuleTests(/*useHeaderModules=*/false); getConfiguredTarget("//module:j"); Artifact jObjectArtifact = getBinArtifact("_objs/j/module/j.pic.o", "//module:j"); @@ -804,7 +811,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { .ccSupport() .setupCrosstool(mockToolsConfig, "feature { name: 'no_legacy_features' }"); - useConfiguration(); + useConfiguration("--cpu=k8"); writeSimpleCcLibrary(); reporter.removeHandler(failFastHandler); getConfiguredTarget("//module:map"); @@ -1041,19 +1048,19 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { @Test public void testCompilationModeFeatures() throws Exception { List<String> flags; - flags = getCompilationModeFlags(); + flags = getCompilationModeFlags("--cpu=k8"); assertThat(flags).contains("-fastbuild"); assertThat(flags).containsNoneOf("-opt", "-dbg"); - flags = getCompilationModeFlags("-c", "fastbuild"); + flags = getCompilationModeFlags("--cpu=k8", "--compilation_mode=fastbuild"); assertThat(flags).contains("-fastbuild"); assertThat(flags).containsNoneOf("-opt", "-dbg"); - flags = getCompilationModeFlags("-c", "opt"); + flags = getCompilationModeFlags("--cpu=k8", "--compilation_mode=opt"); assertThat(flags).contains("-opt"); assertThat(flags).containsNoneOf("-fastbuild", "-dbg"); - flags = getCompilationModeFlags("-c", "dbg"); + flags = getCompilationModeFlags("--cpu=k8", "--compilation_mode=dbg"); assertThat(flags).contains("-dbg"); assertThat(flags).containsNoneOf("-fastbuild", "-opt"); } @@ -1063,7 +1070,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { .ccSupport() .setupCrosstool(mockToolsConfig, MockCcSupport.HOST_AND_NONHOST_CONFIGURATION); scratch.overwriteFile("mode/BUILD", "cc_library(name = 'a', srcs = ['a.cc'])"); - useConfiguration(); + useConfiguration("--cpu=k8"); ConfiguredTarget target; String objectPath; if (useHost) { |