From 29f2ba82ca7581a68b4cc760d15fc9f89b0ea9b9 Mon Sep 17 00:00:00 2001 From: ajmichael Date: Mon, 29 Jan 2018 13:43:24 -0800 Subject: Expose ApkInfo and AndroidInstrumentationInfo to Skylark. This will enable us to write testing rules in Skylark. RELNOTES: None PiperOrigin-RevId: 183719720 --- .../build/lib/rules/android/AarImportTest.java | 2 +- .../build/lib/rules/android/AndroidBinaryTest.java | 53 ++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) (limited to 'src/test') 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 @@ -3963,6 +3963,59 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { checkProguardLibJars(action, getAndroidJarPath()); } + @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( -- cgit v1.2.3