aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com
diff options
context:
space:
mode:
authorGravatar Cal Peyser <cpeyser@google.com>2016-07-26 18:39:13 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-07-27 11:15:10 +0000
commit9fce7603ffd4f63b5b7e819e6699a603acda965c (patch)
treeaccc96ee605ce840f44614d029ca082ffbded9ea /src/test/java/com
parentcb5aa0067d5775c5ada1b751adc502ad2375352b (diff)
Linker outputs can optionally be configured from the CROSSTOOL. Introduces infrastructure to allow other artifact categories (such as debug symbols or compiler outputs) to be defined in other changes.
-- MOS_MIGRATED_REVID=128495797
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/google/devtools/build/lib/BUILD1
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java21
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java45
3 files changed, 67 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD
index 85e6514a35..55f7f5f0e1 100644
--- a/src/test/java/com/google/devtools/build/lib/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/BUILD
@@ -527,6 +527,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib:util",
"//src/main/java/com/google/devtools/build/lib:vfs",
"//src/main/java/com/google/devtools/build/lib/actions",
+ "//src/main/java/com/google/devtools/build/lib/rules/cpp",
"//src/main/java/com/google/devtools/build/skyframe",
"//src/main/java/com/google/devtools/common/options",
"//src/main/protobuf:build_java_proto",
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java
index 53e90d2a0c..a3c5af2bd7 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java
@@ -209,6 +209,27 @@ public abstract class MockCcSupport {
+ " }"
+ "}";
+ public static final String STATIC_LINK_AS_LIB_CONFIGURATION =
+ ""
+ + "artifact_name_pattern {"
+ + " category_name: 'static_library'"
+ + " pattern: '%{base_name}.lib'"
+ + "}";
+
+ public static final String STATIC_LINK_AS_DOT_A_CONFIGURATION =
+ ""
+ + "artifact_name_pattern {"
+ + " category_name: 'static_library'"
+ + " pattern: 'lib%{base_name}.a'"
+ + "}";
+
+ public static final String STATIC_LINK_BAD_TEMPLATE_CONFIGURATION =
+ ""
+ + "artifact_name_pattern {"
+ + " category_name: 'static_library'"
+ + " pattern: 'foo%{bad_variable}bar'"
+ + "}";
+
/** Filter to remove implicit dependencies of C/C++ rules. */
private final Predicate<Label> ccLabelFilter =
new Predicate<Label>() {
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 45c7bd5a74..a374dad06e 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
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
@@ -242,6 +243,50 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase {
}
@Test
+ public void testLinkActionCanConsumeArtifactExtensions() throws Exception {
+ AnalysisMock.get()
+ .ccSupport()
+ .setupCrosstool(mockToolsConfig, MockCcSupport.STATIC_LINK_AS_LIB_CONFIGURATION);
+ useConfiguration("--features=" + Link.LinkTargetType.STATIC_LIBRARY.getActionName());
+ ConfiguredTarget hello = getConfiguredTarget("//hello:hello");
+ Artifact archive =
+ FileType.filter(getFilesToBuild(hello), FileType.of(".lib")).iterator().next();
+
+ CppLinkAction action = (CppLinkAction) getGeneratingAction(archive);
+
+ assertThat(action.getArgv()).contains(archive.getExecPathString());
+ }
+
+ @Test
+ public void testArtifactSelectionBaseNameTemplating() throws Exception {
+ AnalysisMock.get()
+ .ccSupport()
+ .setupCrosstool(mockToolsConfig, MockCcSupport.STATIC_LINK_AS_DOT_A_CONFIGURATION);
+ useConfiguration("--features=" + Link.LinkTargetType.STATIC_LIBRARY.getActionName());
+ ConfiguredTarget hello = getConfiguredTarget("//hello:hello");
+ Artifact archive =
+ FileType.filter(getFilesToBuild(hello), CppFileTypes.ARCHIVE).iterator().next();
+ assertThat(archive.getExecPathString()).endsWith("libhello.a");
+ }
+
+ @Test
+ public void testArtifactSelectionErrorOnBadTemplateVariable() throws Exception {
+ AnalysisMock.get()
+ .ccSupport()
+ .setupCrosstool(mockToolsConfig, MockCcSupport.STATIC_LINK_BAD_TEMPLATE_CONFIGURATION);
+ useConfiguration("--features=" + Link.LinkTargetType.STATIC_LIBRARY.getActionName());
+ try {
+ getConfiguredTarget("//hello:hello");
+ fail("Should fail");
+ } catch (AssertionError e) {
+ assertThat(e.getMessage())
+ .contains(
+ "Invalid toolchain configuration: unknown variable 'bad_variable' "
+ + "can not be expanded.");
+ }
+ }
+
+ @Test
public void testArtifactsToAlwaysBuild() throws Exception {
// ArtifactsToAlwaysBuild should apply both for static libraries.
ConfiguredTarget helloStatic = getConfiguredTarget("//hello:hello_static");