diff options
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules')
4 files changed, 41 insertions, 123 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 407ce6f69f..c65fe227c7 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 @@ -282,7 +282,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { .isEqualTo(action.getLinkCommandLine().getLinkTargetType().name()); assertThat(cppLinkInfo.getLinkStaticness()) .isEqualTo(action.getLinkCommandLine().getLinkStaticness().name()); - Iterable<String> linkstamps = Artifact.asExecPaths(action.getLinkstampObjects()); + Iterable<String> linkstamps = Artifact.asExecPaths(action.getLinkstamps().values()); assertThat(cppLinkInfo.getLinkStampList()).containsExactlyElementsIn(linkstamps); Iterable<String> buildInfoHeaderArtifacts = Artifact.asExecPaths(action.getBuildInfoHeaderArtifacts()); @@ -315,7 +315,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { .isEqualTo(action.getLinkCommandLine().getLinkTargetType().name()); assertThat(cppLinkInfo.getLinkStaticness()) .isEqualTo(action.getLinkCommandLine().getLinkStaticness().name()); - Iterable<String> linkstamps = Artifact.asExecPaths(action.getLinkstampObjects()); + Iterable<String> linkstamps = Artifact.asExecPaths(action.getLinkstamps().values()); assertThat(cppLinkInfo.getLinkStampList()).containsExactlyElementsIn(linkstamps); Iterable<String> buildInfoHeaderArtifacts = Artifact.asExecPaths(action.getBuildInfoHeaderArtifacts()); diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java index eae60c6c13..a0154f0bda 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java @@ -283,6 +283,7 @@ public class CppLinkActionTest extends BuildViewTestCase { private enum NonStaticAttributes { OUTPUT_FILE, + COMPILATION_INPUTS, NATIVE_DEPS, USE_TEST_ONLY_FLAGS, FAKE, @@ -300,6 +301,8 @@ public class CppLinkActionTest extends BuildViewTestCase { final PathFragment dynamicOutputPath = PathFragment.create("dummyRuleContext/output/path.so"); final Artifact staticOutputFile = getBinArtifactWithNoOwner(exeOutputPath.getPathString()); final Artifact dynamicOutputFile = getBinArtifactWithNoOwner(dynamicOutputPath.getPathString()); + final Artifact oFile = getSourceArtifact("cc/a.o"); + final Artifact oFile2 = getSourceArtifact("cc/a2.o"); final FeatureConfiguration featureConfiguration = getMockFeatureConfiguration(); ActionTester.runTest( @@ -319,6 +322,10 @@ public class CppLinkActionTest extends BuildViewTestCase { CppHelper.getFdoSupportUsingDefaultCcToolchainAttribute(ruleContext), featureConfiguration, MockCppSemantics.INSTANCE) {}; + builder.addCompilationInputs( + attributesToFlip.contains(NonStaticAttributes.COMPILATION_INPUTS) + ? ImmutableList.of(oFile) + : ImmutableList.of(oFile2)); if (attributesToFlip.contains(NonStaticAttributes.OUTPUT_FILE)) { builder.setLinkType(LinkTargetType.DYNAMIC_LIBRARY); builder.setLibraryIdentifier("foo"); @@ -343,6 +350,7 @@ public class CppLinkActionTest extends BuildViewTestCase { private enum StaticKeyAttributes { OUTPUT_FILE, + COMPILATION_INPUTS } /** @@ -356,6 +364,8 @@ public class CppLinkActionTest extends BuildViewTestCase { final PathFragment dynamicOutputPath = PathFragment.create("dummyRuleContext/output/path.so"); final Artifact staticOutputFile = getBinArtifactWithNoOwner(staticOutputPath.getPathString()); final Artifact dynamicOutputFile = getBinArtifactWithNoOwner(dynamicOutputPath.getPathString()); + final Artifact oFile = getSourceArtifact("cc/a.o"); + final Artifact oFile2 = getSourceArtifact("cc/a2.o"); final FeatureConfiguration featureConfiguration = getMockFeatureConfiguration(); ActionTester.runTest( @@ -375,6 +385,10 @@ public class CppLinkActionTest extends BuildViewTestCase { CppHelper.getFdoSupportUsingDefaultCcToolchainAttribute(ruleContext), featureConfiguration, MockCppSemantics.INSTANCE) {}; + builder.addCompilationInputs( + attributes.contains(StaticKeyAttributes.COMPILATION_INPUTS) + ? ImmutableList.of(oFile) + : ImmutableList.of(oFile2)); builder.setLinkType( attributes.contains(StaticKeyAttributes.OUTPUT_FILE) ? LinkTargetType.STATIC_LIBRARY diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelperTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelperTest.java deleted file mode 100644 index 086ce0ee85..0000000000 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelperTest.java +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -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.Artifact; -import com.google.devtools.build.lib.actions.util.ActionsTestUtil; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.util.AnalysisMock; -import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; -import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Tests that {@link CppLinkstampCompileHelper} creates sane compile actions for linkstamps */ -@RunWith(JUnit4.class) -public class CppLinkstampCompileHelperTest extends BuildViewTestCase { - - /** Tests that linkstamp compilation applies expected command line options. */ - @Test - public void testLinkstampCompileOptionsForExecutable() throws Exception { - AnalysisMock.get() - .ccSupport() - .setupCrosstool(mockToolsConfig, "builtin_sysroot: '/usr/local/custom-sysroot'"); - useConfiguration(); - scratch.file( - "x/BUILD", - "cc_binary(", - " name = 'foo',", - " deps = ['a'],", - ")", - "cc_library(", - " name = 'a',", - " srcs = [ 'a.cc' ],", - " linkstamp = 'ls.cc',", - ")"); - - ConfiguredTarget target = getConfiguredTarget("//x:foo"); - Artifact executable = getExecutable(target); - CppLinkAction generatingAction = (CppLinkAction) getGeneratingAction(executable); - - Artifact compiledLinkstamp = - ActionsTestUtil.getFirstArtifactEndingWith(generatingAction.getInputs(), "ls.o"); - CppCompileAction linkstampCompileAction = - (CppCompileAction) getGeneratingAction(compiledLinkstamp); - - List<String> arguments = linkstampCompileAction.getArguments(); - assertThatArgumentsAreValid( - arguments, - target.getConfiguration().getFragment(CppConfiguration.class).toString(), - target.getLabel().getCanonicalForm(), - executable.getFilename()); - } - - private void assertThatArgumentsAreValid( - List<String> arguments, String platform, String targetName, String buildTargetNameSuffix) { - assertThat(arguments).contains("--sysroot=/usr/local/custom-sysroot"); - assertThat(arguments).contains("-include"); - assertThat(arguments).contains("-DG3_VERSION_INFO=\"" + targetName + "\""); - assertThat(arguments).contains("-DG3_TARGET_NAME=\"" + targetName + "\""); - assertThat(arguments).contains("-DGPLATFORM=\"" + platform + "\""); - assertThat(arguments).contains("-I."); - String correctG3BuildTargetPattern = "-DG3_BUILD_TARGET=\".*" + buildTargetNameSuffix + "\""; - assertThat(Iterables.tryFind(arguments, (arg) -> arg.matches(correctG3BuildTargetPattern))) - .named("in " + arguments + " flag matching " + correctG3BuildTargetPattern) - .isPresent(); - } - - /** Tests that linkstamp compilation applies expected command line options. */ - @Test - public void testLinkstampCompileOptionsForSharedLibrary() throws Exception { - AnalysisMock.get() - .ccSupport() - .setupCrosstool(mockToolsConfig, "builtin_sysroot: '/usr/local/custom-sysroot'"); - useConfiguration(); - scratch.file( - "x/BUILD", - "cc_binary(", - " name = 'libfoo.so',", - " deps = ['a'],", - " linkshared = 1,", - ")", - "cc_library(", - " name = 'a',", - " srcs = [ 'a.cc' ],", - " linkstamp = 'ls.cc',", - ")"); - - ConfiguredTarget target = getConfiguredTarget("//x:libfoo.so"); - Artifact executable = getExecutable(target); - CppLinkAction generatingAction = (CppLinkAction) getGeneratingAction(executable); - Artifact compiledLinkstamp = - ActionsTestUtil.getFirstArtifactEndingWith(generatingAction.getInputs(), "ls.o"); - assertThat(generatingAction.getInputs()).contains(compiledLinkstamp); - - CppCompileAction linkstampCompileAction = - (CppCompileAction) getGeneratingAction(compiledLinkstamp); - - List<String> arguments = linkstampCompileAction.getArguments(); - assertThatArgumentsAreValid( - arguments, - target.getConfiguration().getFragment(CppConfiguration.class).toString(), - target.getLabel().getCanonicalForm(), - executable.getFilename()); - } -} 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 aa21798b4c..fea5b3d85b 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 @@ -34,6 +34,31 @@ import org.junit.runners.JUnit4; public class LinkBuildVariablesTest extends LinkBuildVariablesTestCase { @Test + public void testLinkstampBuildVariable() throws Exception { + scratch.file( + "x/BUILD", + "cc_binary(", + " name = 'bin',", + " srcs = ['a.cc'],", + " deps = [':lib'],", + ")", + "cc_library(", + " name = 'lib',", + " srcs = ['b.cc'],", + " linkstamp = 'c.cc',", + ")"); + scratch.file("x/a.cc"); + scratch.file("x/b.cc"); + scratch.file("x/c.cc"); + + ConfiguredTarget target = getConfiguredTarget("//x:bin"); + Variables variables = getLinkBuildVariables(target, Link.LinkTargetType.EXECUTABLE); + List<String> variableValue = + getSequenceVariableValue(variables, CppLinkActionBuilder.LINKSTAMP_PATHS_VARIABLE); + assertThat(Iterables.getOnlyElement(variableValue)).contains("c.o"); + } + + @Test public void testForcePicBuildVariable() throws Exception { useConfiguration("--force_pic"); scratch.file("x/BUILD", "cc_binary(name = 'bin', srcs = ['a.cc'])"); |