diff options
author | 2018-04-09 09:36:14 -0700 | |
---|---|---|
committer | 2018-04-09 09:37:40 -0700 | |
commit | bef08f66cdaf77e31b3fc44b398b4f8a6e5c0c0b (patch) | |
tree | 6b739cff808baab6042d1e80264079871d4fe46c /src/test/java/com/google | |
parent | 7131b2cb741ee4d62ee3235e0e570676bfc35549 (diff) |
Add tests for interface shared library build variables when lto indexing
Adding tests for unknown commit since the submission of the fix had to happen quickly.
RELNOTES: None
PiperOrigin-RevId: 192139135
Diffstat (limited to 'src/test/java/com/google')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java | 109 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTestCase.java | 6 |
2 files changed, 113 insertions, 2 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java index 5934538470..a7e515403b 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java @@ -17,8 +17,11 @@ package com.google.devtools.build.lib.rules.cpp; import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.Iterables; +import com.google.devtools.build.lib.actions.Action; +import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.util.AnalysisMock; +import com.google.devtools.build.lib.packages.util.MockCcSupport; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.LibraryToLinkValue; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariableValue; @@ -138,6 +141,54 @@ public class LinkBuildVariablesTest extends LinkBuildVariablesTestCase { } @Test + public void testNoIfsoBuildingWhenWhenThinLtoIndexing() throws Exception { + // Make sure the interface shared object generation is enabled in the configuration + // (which it is not by default for some windows toolchains) + AnalysisMock.get() + .ccSupport() + .setupCrosstool( + mockToolsConfig, + MockCcSupport.THIN_LTO_CONFIGURATION, + MockCcSupport.HOST_AND_NONHOST_CONFIGURATION, + "supports_interface_shared_objects: true", + "needsPic: true", + "supports_start_end_lib: true"); + useConfiguration("--features=thin_lto"); + + scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])"); + scratch.file("x/a.cc"); + + ConfiguredTarget target = getConfiguredTarget("//x:foo"); + CppLinkAction linkAction = getCppLinkAction(target, LinkTargetType.NODEPS_DYNAMIC_LIBRARY); + + LtoBackendAction backendAction = + (LtoBackendAction) + getPredecessorByInputName(linkAction, "x/libfoo.so.lto/x/_objs/foo/a.pic.o"); + assertThat(backendAction.getMnemonic()).isEqualTo("CcLtoBackendCompile"); + + CppLinkAction indexAction = + (CppLinkAction) + getPredecessorByInputName( + backendAction, "x/libfoo.so.lto/x/_objs/foo/a.pic.o.thinlto.bc"); + Variables variables = indexAction.getLinkCommandLine().getBuildVariables(); + + String interfaceLibraryBuilder = + getVariableValue(variables, LinkBuildVariables.INTERFACE_LIBRARY_BUILDER.getVariableName()); + String interfaceLibraryInput = + getVariableValue(variables, LinkBuildVariables.INTERFACE_LIBRARY_INPUT.getVariableName()); + String interfaceLibraryOutput = + getVariableValue(variables, LinkBuildVariables.INTERFACE_LIBRARY_OUTPUT.getVariableName()); + String generateInterfaceLibrary = + getVariableValue( + variables, LinkBuildVariables.GENERATE_INTERFACE_LIBRARY.getVariableName()); + + assertThat(generateInterfaceLibrary).isEqualTo("no"); + assertThat(interfaceLibraryInput).endsWith("ignored"); + assertThat(interfaceLibraryOutput).endsWith("ignored"); + assertThat(interfaceLibraryBuilder).endsWith("ignored"); + } + + @Test public void testInterfaceLibraryBuildingVariablesWhenGenerationNotAllowed() throws Exception { // Make sure the interface shared object generation is enabled in the configuration // (which it is not by default for some windows toolchains) @@ -169,6 +220,55 @@ public class LinkBuildVariablesTest extends LinkBuildVariablesTestCase { } @Test + public void testOutputExecpath() throws Exception { + // Make sure the interface shared object generation is enabled in the configuration + // (which it is not by default for some windows toolchains) + scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])"); + scratch.file("x/a.cc"); + + ConfiguredTarget target = getConfiguredTarget("//x:foo"); + Variables variables = getLinkBuildVariables(target, LinkTargetType.NODEPS_DYNAMIC_LIBRARY); + + assertThat(getVariableValue(variables, LinkBuildVariables.OUTPUT_EXECPATH.getVariableName())) + .endsWith("x/libfoo.so"); + } + + @Test + public void testOutputExecpathIsNotExposedWhenThinLtoIndexing() throws Exception { + // Make sure the interface shared object generation is enabled in the configuration + // (which it is not by default for some windows toolchains) + AnalysisMock.get() + .ccSupport() + .setupCrosstool( + mockToolsConfig, + MockCcSupport.THIN_LTO_CONFIGURATION, + MockCcSupport.HOST_AND_NONHOST_CONFIGURATION, + "needsPic: true", + "supports_start_end_lib: true"); + useConfiguration("--features=thin_lto"); + + scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])"); + scratch.file("x/a.cc"); + + ConfiguredTarget target = getConfiguredTarget("//x:foo"); + CppLinkAction linkAction = getCppLinkAction(target, LinkTargetType.NODEPS_DYNAMIC_LIBRARY); + + LtoBackendAction backendAction = + (LtoBackendAction) + getPredecessorByInputName(linkAction, "x/libfoo.so.lto/x/_objs/foo/a.pic.o"); + assertThat(backendAction.getMnemonic()).isEqualTo("CcLtoBackendCompile"); + + CppLinkAction indexAction = + (CppLinkAction) + getPredecessorByInputName( + backendAction, "x/libfoo.so.lto/x/_objs/foo/a.pic.o.thinlto.bc"); + Variables variables = indexAction.getLinkCommandLine().getBuildVariables(); + + assertThat(variables.isAvailable(LinkBuildVariables.OUTPUT_EXECPATH.getVariableName())) + .isFalse(); + } + + @Test public void testIsCcTestLinkActionBuildVariable() throws Exception { scratch.file("x/BUILD", "cc_test(name = 'foo_test', srcs = ['a.cc'])", @@ -253,4 +353,13 @@ public class LinkBuildVariablesTest extends LinkBuildVariablesTestCase { assertThat(testVariables.isAvailable(CcCommon.SYSROOT_VARIABLE_NAME)).isTrue(); } + + private Action getPredecessorByInputName(Action action, String str) { + for (Artifact a : action.getInputs()) { + if (a.getExecPathString().contains(str)) { + return getGeneratingAction(a); + } + } + return null; + } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTestCase.java index 880be4dec0..a6041401c9 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTestCase.java @@ -32,7 +32,7 @@ import java.util.List; **/ public class LinkBuildVariablesTestCase extends BuildViewTestCase { - private CppLinkAction getCppLinkAction(ConfiguredTarget target, Link.LinkTargetType type) { + protected CppLinkAction getCppLinkAction(ConfiguredTarget target, Link.LinkTargetType type) { Artifact linkerOutput = null; switch (type) { case STATIC_LIBRARY: @@ -44,9 +44,11 @@ public class LinkBuildVariablesTestCase extends BuildViewTestCase { linkerOutput = getBinArtifact("lib" + target.getLabel().getName() + "pic.a", target); break; case NODEPS_DYNAMIC_LIBRARY: - case DYNAMIC_LIBRARY: linkerOutput = getBinArtifact("lib" + target.getLabel().getName() + ".so", target); break; + case DYNAMIC_LIBRARY: + linkerOutput = getBinArtifact(target.getLabel().getName(), target); + break; case EXECUTABLE: linkerOutput = getExecutable(target); break; |