aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar ajmichael <ajmichael@google.com>2018-01-29 13:43:24 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-29 13:47:36 -0800
commit29f2ba82ca7581a68b4cc760d15fc9f89b0ea9b9 (patch)
treea652563efbdea7e433959406780cd00706c5054b /src/test
parent131189ebce1454578abf0b669807af4cc5f3b1b6 (diff)
Expose ApkInfo and AndroidInstrumentationInfo to Skylark.
This will enable us to write testing rules in Skylark. RELNOTES: None PiperOrigin-RevId: 183719720
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AarImportTest.java2
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java53
2 files changed, 54 insertions, 1 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AarImportTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AarImportTest.java
index b8616517e8..681f893d09 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AarImportTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AarImportTest.java
@@ -281,7 +281,7 @@ public class AarImportTest extends BuildViewTestCase {
@Test
public void testExportsManifest() throws Exception {
Artifact binaryMergedManifest =
- getConfiguredTarget("//java:app").getProvider(ApkProvider.class).getMergedManifest();
+ getConfiguredTarget("//java:app").get(ApkInfo.PROVIDER).getMergedManifest();
// Compare root relative path strings instead of artifacts due to difference in configuration
// caused by the Android split transition.
assertThat(
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 49da7c32cd..914dc8a906 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
@@ -3964,6 +3964,59 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase {
}
@Test
+ public void testApkInfoAccessibleFromSkylark() throws Exception {
+ scratch.file(
+ "java/com/google/android/BUILD",
+ "load(':postprocess.bzl', 'postprocess')",
+ "android_binary(name = 'b1',",
+ " srcs = ['b1.java'],",
+ " manifest = 'AndroidManifest.xml')",
+ "postprocess(name = 'postprocess', dep = ':b1')");
+ scratch.file(
+ "java/com/google/android/postprocess.bzl",
+ "def _impl(ctx):",
+ " return [DefaultInfo(files=depset([ctx.attr.dep[ApkInfo].signed_apk]))]",
+ "postprocess = rule(implementation=_impl,",
+ " attrs={'dep': attr.label(providers=[ApkInfo])})");
+ ConfiguredTarget postprocess = getConfiguredTarget("//java/com/google/android:postprocess");
+ assertThat(postprocess).isNotNull();
+ assertThat(
+ ActionsTestUtil.prettyArtifactNames(
+ postprocess.getProvider(FilesToRunProvider.class).getFilesToRun()))
+ .containsExactly("java/com/google/android/b1.apk");
+ }
+
+ @Test
+ public void testInstrumentationInfoAccessibleFromSkylark() throws Exception {
+ scratch.file(
+ "java/com/google/android/instr/BUILD",
+ "load(':instr.bzl', 'instr')",
+ "android_binary(name = 'b1',",
+ " srcs = ['b1.java'],",
+ " instruments = ':b2',",
+ " manifest = 'AndroidManifest.xml')",
+ "android_binary(name = 'b2',",
+ " srcs = ['b2.java'],",
+ " manifest = 'AndroidManifest.xml')",
+ "instr(name = 'instr', dep = ':b1')");
+ scratch.file(
+ "java/com/google/android/instr/instr.bzl",
+ "def _impl(ctx):",
+ " target = ctx.attr.dep[AndroidInstrumentationInfo].target_apk",
+ " instr = ctx.attr.dep[AndroidInstrumentationInfo].instrumentation_apk",
+ " return [DefaultInfo(files=depset([target,instr]))]",
+ "instr = rule(implementation=_impl,",
+ " attrs={'dep': attr.label(providers=[AndroidInstrumentationInfo])})");
+ ConfiguredTarget instr = getConfiguredTarget("//java/com/google/android/instr");
+ assertThat(instr).isNotNull();
+ assertThat(
+ ActionsTestUtil.prettyArtifactNames(
+ instr.getProvider(FilesToRunProvider.class).getFilesToRun()))
+ .containsExactly(
+ "java/com/google/android/instr/b1.apk", "java/com/google/android/instr/b2.apk");
+ }
+
+ @Test
public void testInstrumentationInfoProviderHasApks() throws Exception {
scratch.file(
"java/com/google/android/instr/BUILD",