aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-10-21 04:06:39 +0200
committerGravatar Dmitry Lomov <dslomov@google.com>2017-10-23 17:16:18 +0200
commit9cc97513839442ac13fe10ab84e103e127e36987 (patch)
treec3bc0aa44c7df12e85cc857d9d614b9a7ec12d8f /src/test/java/com/google
parent89d13b8810bfe9216ed1746a28b83d636183c1c7 (diff)
Add support for linker scripts in auto-linked Android native deps
Android's mechanism for automatically linking native deps does not currently support linker scripts. A dependency cc_library can specify the linker script in the linkopts and include it in its deps, but since the artifact is not provided as an input to the generated link action, this results in an error. This change provides the missing inputs and makes this work. RELNOTES: Support for linker scripts in NativeDepsHelper (e.g., android_binary) PiperOrigin-RevId: 172963605
Diffstat (limited to 'src/test/java/com/google')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java20
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java16
2 files changed, 36 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java
index a271b49446..df142ad7f3 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java
@@ -506,6 +506,26 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase {
.isEmpty();
}
+ @Test
+ public void testNativeLibrary_ProvidesLinkerScriptToLinkAction() throws Exception {
+ scratch.file("java/android/app/BUILD",
+ "cc_library(name = 'native',",
+ " srcs = ['native.cc'],",
+ " linkopts = ['-Wl,-version-script', '$(location jni.lds)'],",
+ " deps = ['jni.lds'],)",
+ "android_binary(name = 'app',",
+ " srcs = ['A.java'],",
+ " deps = [':native'],",
+ " manifest = 'AndroidManifest.xml',",
+ " )");
+
+ ConfiguredTarget app = getConfiguredTarget("//java/android/app:app");
+ Artifact copiedLib = getOnlyElement(getNativeLibrariesInApk(app));
+ Artifact linkedLib = getOnlyElement(getGeneratingAction(copiedLib).getInputs());
+ Iterable<Artifact> linkInputs = getGeneratingAction(linkedLib).getInputs();
+ assertThat(ActionsTestUtil.baseArtifactNames(linkInputs)).contains("jni.lds");
+ }
+
/** Regression test for http://b/33173461. */
@Test
public void testIncrementalDexingUsesDexArchives_binaryDependingOnAliasTarget()
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java
index 3bde118ad4..e966cc06c2 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java
@@ -825,6 +825,22 @@ public class CcCommonTest extends BuildViewTestCase {
}
@Test
+ public void testProvidesLinkerScriptToLinkAction() throws Exception {
+ scratch.file(
+ "a/BUILD",
+ "cc_binary(",
+ " name='bin',",
+ " srcs=['b.cc'],",
+ " linkopts=['-Wl,@$(location a.lds)'],",
+ " deps=['a.lds'])");
+ ConfiguredTarget target = getConfiguredTarget("//a:bin");
+ CppLinkAction action =
+ (CppLinkAction) getGeneratingAction(getOnlyElement(getFilesToBuild(target)));
+ Iterable<Artifact> linkInputs = action.getInputs();
+ assertThat(ActionsTestUtil.baseArtifactNames(linkInputs)).contains("a.lds");
+ }
+
+ @Test
public void testIncludeManglingSmoke() throws Exception {
scratch.file(
"third_party/a/BUILD",