diff options
author | asteinb <asteinb@google.com> | 2018-05-03 08:09:09 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-03 08:10:55 -0700 |
commit | 158dda74f4d6d33b88be4ab4c40322eca5f1c2fd (patch) | |
tree | 9d666848416b0b59328c2e6e3b11e221be1f3905 /src/test/java | |
parent | 70821069b0e39249eb0f23cf16ca4438c9703a7b (diff) |
Fix up newly discovered bugs in decoupled Android data processing
- Always generate a symbols file - the new resource processing pipeline likes
knowing that this is non-null, and it shouldn't cost much extra to create.
- A misleading method signature (which I made) led to me forgetting about
Proguard artifacts. Properly propogate them into the ResourceApk object.
- Don't get Aapt version directly from AndroidConfiguration - there's some
additional logic in AndroidAaptVersion not exposed elsewhere
- Split library tests that expect resources and assets to be processed together
to have a new version where they're processed seperately.
- Tests use ValidatedAndroidData interface rather than ResourceContainer object
- Properly move some LocalTest magic around resource JAR out of the old
pipeline only, as it should apply to both old and new pipelines.
- Processing action defaults to empty resource and asset deps rather than null
RELNOTES: none
PiperOrigin-RevId: 195253161
Diffstat (limited to 'src/test/java')
5 files changed, 359 insertions, 43 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 4e5f05e1d7..54ca21a176 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 @@ -91,7 +91,9 @@ public class AarImportTest extends BuildViewTestCase { } @Test - public void testResourcesProvided() throws Exception { + public void testResourcesProvided_NotDecoupled() throws Exception { + useConfiguration("--noandroid_decouple_data_processing"); + ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:foo"); NestedSet<ValidatedAndroidData> directResources = @@ -113,7 +115,37 @@ public class AarImportTest extends BuildViewTestCase { } @Test - public void testResourcesExtractor() throws Exception { + public void testResourcesProvided() throws Exception { + useConfiguration("--android_decouple_data_processing"); + + ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:foo"); + + NestedSet<ValidatedAndroidData> directResources = + aarImportTarget.get(AndroidResourcesInfo.PROVIDER).getDirectAndroidResources(); + assertThat(directResources).hasSize(1); + + ValidatedAndroidData resourceContainer = directResources.iterator().next(); + assertThat(resourceContainer.getManifest()).isNotNull(); + + Artifact resourceTreeArtifact = Iterables.getOnlyElement(resourceContainer.getResources()); + assertThat(resourceTreeArtifact.isTreeArtifact()).isTrue(); + assertThat(resourceTreeArtifact.getExecPathString()).endsWith("_aar/unzipped/resources/foo"); + + NestedSet<ParsedAndroidAssets> directAssets = + aarImportTarget.get(AndroidAssetsInfo.PROVIDER).getDirectParsedAssets(); + assertThat(directAssets).hasSize(1); + + ParsedAndroidAssets assets = directAssets.iterator().next(); + assertThat(assets.getSymbols()).isNotNull(); + + Artifact assetsTreeArtifact = Iterables.getOnlyElement(assets.getAssets()); + assertThat(assetsTreeArtifact.isTreeArtifact()).isTrue(); + assertThat(assetsTreeArtifact.getExecPathString()).endsWith("_aar/unzipped/assets/foo"); + } + + @Test + public void testResourcesExtractor_NotDecoupled() throws Exception { + useConfiguration("--noandroid_decouple_data_processing"); ValidatedAndroidData resourceContainer = getConfiguredTarget("//a:foo") .get(AndroidResourcesInfo.PROVIDER) @@ -125,9 +157,9 @@ public class AarImportTest extends BuildViewTestCase { Artifact assetsTreeArtifact = resourceContainer.getAssets().get(0); Artifact aarResourcesExtractor = getHostConfiguredTarget( - ruleClassProvider.getToolsRepository() + "//tools/android:aar_resources_extractor") - .getProvider(FilesToRunProvider.class) - .getExecutable(); + ruleClassProvider.getToolsRepository() + "//tools/android:aar_resources_extractor") + .getProvider(FilesToRunProvider.class) + .getExecutable(); assertThat(getGeneratingSpawnAction(resourceTreeArtifact).getArguments()) .containsExactly( @@ -141,8 +173,45 @@ public class AarImportTest extends BuildViewTestCase { } @Test - public void testDepsCheckerActionExistsForLevelError() throws Exception { - useConfiguration("--experimental_import_deps_checking=ERROR"); + public void testResourcesExtractor() throws Exception { + useConfiguration("--android_decouple_data_processing"); + ValidatedAndroidData resourceContainer = + getConfiguredTarget("//a:foo") + .get(AndroidResourcesInfo.PROVIDER) + .getDirectAndroidResources() + .toList() + .get(0); + + Artifact resourceTreeArtifact = resourceContainer.getResources().get(0); + Artifact aarResourcesExtractor = + getHostConfiguredTarget( + ruleClassProvider.getToolsRepository() + "//tools/android:aar_resources_extractor") + .getProvider(FilesToRunProvider.class) + .getExecutable(); + + ParsedAndroidAssets assets = + getConfiguredTarget("//a:foo") + .get(AndroidAssetsInfo.PROVIDER) + .getDirectParsedAssets() + .toList() + .get(0); + Artifact assetsTreeArtifact = assets.getAssets().get(0); + + assertThat(getGeneratingSpawnAction(resourceTreeArtifact).getArguments()) + .containsExactly( + aarResourcesExtractor.getExecPathString(), + "--input_aar", + "a/foo.aar", + "--output_res_dir", + resourceTreeArtifact.getExecPathString(), + "--output_assets_dir", + assetsTreeArtifact.getExecPathString()); + } + + @Test + public void testDepsCheckerActionExistsForLevelErrorNotDecoupled() throws Exception { + useConfiguration( + "--experimental_import_deps_checking=ERROR", "--noandroid_decouple_data_processing"); ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:last"); OutputGroupInfo outputGroupInfo = aarImportTarget.get(OutputGroupInfo.SKYLARK_CONSTRUCTOR); NestedSet<Artifact> outputGroup = @@ -172,8 +241,50 @@ public class AarImportTest extends BuildViewTestCase { } @Test - public void testDepsCheckerActionExistsForLevelStrictError() throws Exception { - useConfiguration("--experimental_import_deps_checking=STRICT_ERROR"); + public void testDepsCheckerActionExistsForLevelError() throws Exception { + useConfiguration( + "--experimental_import_deps_checking=ERROR", "--android_decouple_data_processing"); + ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:last"); + OutputGroupInfo outputGroupInfo = aarImportTarget.get(OutputGroupInfo.SKYLARK_CONSTRUCTOR); + NestedSet<Artifact> outputGroup = + outputGroupInfo.getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); + assertThat(outputGroup).hasSize(2); + + // We should force asset merging to happen + Artifact mergedAssetsZip = + aarImportTarget.get(AndroidAssetsInfo.PROVIDER).getValidationResult(); + assertThat(outputGroup).contains(mergedAssetsZip); + + // Get the other artifact from the output group + Artifact artifact = ActionsTestUtil.getFirstArtifactEndingWith(outputGroup, ".txt"); + + assertThat(artifact.isTreeArtifact()).isFalse(); + assertThat(artifact.getExecPathString()) + .endsWith("_aar/last/aar_import_deps_checker_result.txt"); + + SpawnAction checkerAction = getGeneratingSpawnAction(artifact); + List<String> arguments = checkerAction.getArguments(); + assertThat(arguments) + .containsAllOf( + "--bootclasspath_entry", + "--classpath_entry", + "--input", + "--output", + "--fail_on_errors"); + ensureArgumentsHaveClassEntryOptionWithSuffix(arguments, "/bar/classes_and_libs_merged.jar"); + ensureArgumentsHaveClassEntryOptionWithSuffix(arguments, "/baz/java/baz-ijar.jar"); + ensureArgumentsHaveClassEntryOptionWithSuffix(arguments, "/baz/classes_and_libs_merged.jar"); + ensureArgumentsHaveClassEntryOptionWithSuffix(arguments, "/foo/classes_and_libs_merged.jar"); + ensureArgumentsHaveClassEntryOptionWithSuffix( + arguments, "/intermediate/classes_and_libs_merged.jar"); + assertThat(arguments.stream().filter(arg -> "--classpath_entry".equals(arg)).count()) + .isEqualTo(5); + } + + @Test + public void testDepsCheckerActionExistsForLevelStrictError_NotDecoupled() throws Exception { + useConfiguration( + "--experimental_import_deps_checking=STRICT_ERROR", "--noandroid_decouple_data_processing"); ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:last"); OutputGroupInfo outputGroupInfo = aarImportTarget.get(OutputGroupInfo.SKYLARK_CONSTRUCTOR); NestedSet<Artifact> outputGroup = @@ -199,13 +310,84 @@ public class AarImportTest extends BuildViewTestCase { } @Test - public void testDepsCheckerActionExistsForLevelWarning() throws Exception { - useConfiguration("--experimental_import_deps_checking=WARNING"); + public void testDepsCheckerActionExistsForLevelStrictError() throws Exception { + useConfiguration( + "--experimental_import_deps_checking=STRICT_ERROR", "--android_decouple_data_processing"); + ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:last"); + OutputGroupInfo outputGroupInfo = aarImportTarget.get(OutputGroupInfo.SKYLARK_CONSTRUCTOR); + NestedSet<Artifact> outputGroup = + outputGroupInfo.getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); + assertThat(outputGroup).hasSize(2); + + // We should force asset merging to happen + Artifact mergedAssetsZip = + aarImportTarget.get(AndroidAssetsInfo.PROVIDER).getValidationResult(); + assertThat(outputGroup).contains(mergedAssetsZip); + + // Get the other artifact from the output group + Artifact artifact = ActionsTestUtil.getFirstArtifactEndingWith(outputGroup, ".txt"); + assertThat(artifact.isTreeArtifact()).isFalse(); + assertThat(artifact.getExecPathString()) + .endsWith("_aar/last/aar_import_deps_checker_result.txt"); + + SpawnAction checkerAction = getGeneratingSpawnAction(artifact); + List<String> arguments = checkerAction.getArguments(); + assertThat(arguments) + .containsAllOf( + "--bootclasspath_entry", + "--classpath_entry", + "--input", + "--output", + "--fail_on_errors"); + ensureArgumentsHaveClassEntryOptionWithSuffix( + arguments, "/intermediate/classes_and_libs_merged.jar"); + assertThat(arguments.stream().filter(arg -> "--classpath_entry".equals(arg)).count()) + .isEqualTo(1); + } + + @Test + public void testDepsCheckerActionExistsForLevelWarning_NotDecoupled() throws Exception { + useConfiguration( + "--experimental_import_deps_checking=WARNING", "--noandroid_decouple_data_processing"); ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:bar"); OutputGroupInfo outputGroupInfo = aarImportTarget.get(OutputGroupInfo.SKYLARK_CONSTRUCTOR); NestedSet<Artifact> outputGroup = outputGroupInfo.getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); Artifact artifact = Iterables.getOnlyElement(outputGroup); + + assertThat(artifact.isTreeArtifact()).isFalse(); + assertThat(artifact.getExecPathString()) + .endsWith("_aar/bar/aar_import_deps_checker_result.txt"); + + SpawnAction checkerAction = getGeneratingSpawnAction(artifact); + List<String> arguments = checkerAction.getArguments(); + assertThat(arguments) + .containsAllOf( + "--bootclasspath_entry", + "--classpath_entry", + "--input", + "--output", + "--nofail_on_errors"); + } + + @Test + public void testDepsCheckerActionExistsForLevelWarning() throws Exception { + useConfiguration( + "--experimental_import_deps_checking=WARNING", "--android_decouple_data_processing"); + ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:bar"); + OutputGroupInfo outputGroupInfo = aarImportTarget.get(OutputGroupInfo.SKYLARK_CONSTRUCTOR); + NestedSet<Artifact> outputGroup = + outputGroupInfo.getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); + assertThat(outputGroup).hasSize(2); + + // We should force asset merging to happen + Artifact mergedAssetsZip = + aarImportTarget.get(AndroidAssetsInfo.PROVIDER).getValidationResult(); + assertThat(outputGroup).contains(mergedAssetsZip); + + // Get the other artifact from the output group + Artifact artifact = ActionsTestUtil.getFirstArtifactEndingWith(outputGroup, ".txt"); + assertThat(artifact.isTreeArtifact()).isFalse(); assertThat(artifact.getExecPathString()) .endsWith("_aar/bar/aar_import_deps_checker_result.txt"); @@ -246,8 +428,9 @@ public class AarImportTest extends BuildViewTestCase { } @Test - public void testDepsCheckerActionNotExistsForLevelOff() throws Exception { - useConfiguration("--experimental_import_deps_checking=OFF"); + public void testDepsCheckerActionNotExistsForLevelOff_NotDecoupled() throws Exception { + useConfiguration( + "--experimental_import_deps_checking=OFF", "--noandroid_decouple_data_processing"); ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:bar"); OutputGroupInfo outputGroupInfo = aarImportTarget.get(OutputGroupInfo.SKYLARK_CONSTRUCTOR); NestedSet<Artifact> outputGroup = @@ -256,6 +439,21 @@ public class AarImportTest extends BuildViewTestCase { } @Test + public void testDepsCheckerActionNotExistsForLevelOff() throws Exception { + useConfiguration( + "--experimental_import_deps_checking=OFF", "--android_decouple_data_processing"); + ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:bar"); + OutputGroupInfo outputGroupInfo = aarImportTarget.get(OutputGroupInfo.SKYLARK_CONSTRUCTOR); + + // The deps checker action should not exist, but we should still create an action for asset + // merging + NestedSet<Artifact> outputGroup = + outputGroupInfo.getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); + assertThat(outputGroup).hasSize(1); + assertThat(outputGroup.toList().get(0).getFilename()).isEqualTo("assets.zip"); + } + + @Test public void testNativeLibsProvided() throws Exception { ConfiguredTarget androidLibraryTarget = getConfiguredTarget("//java:lib"); 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 d24f2dc8e3..1dd3e80eed 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 @@ -1062,7 +1062,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { "java/com/google/android/neversayneveragain/libb1.jar_desugared.jar"); assertThat( resourceInputPaths( - "java/com/google/android/neversayneveragain", getResourceContainer(b1))) + "java/com/google/android/neversayneveragain", getValidatedData(b1))) .doesNotContain("res/values/resource.xml"); ConfiguredTarget b2 = getConfiguredTarget("//java/com/google/android/neversayneveragain:b2"); @@ -1079,7 +1079,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { "java/com/google/android/neversayneveragain/libb2.jar_desugared.jar"); assertThat( resourceInputPaths( - "java/com/google/android/neversayneveragain", getResourceContainer(b2))) + "java/com/google/android/neversayneveragain", getValidatedData(b2))) .doesNotContain("res/values/resource.xml"); ConfiguredTarget b3 = getConfiguredTarget("//java/com/google/android/neversayneveragain:b3"); @@ -1096,7 +1096,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { .doesNotContain("java/com/google/android/neversayneveragain/libl2.jar_desugared.jar"); assertThat( resourceInputPaths( - "java/com/google/android/neversayneveragain", getResourceContainer(b3))) + "java/com/google/android/neversayneveragain", getValidatedData(b3))) .contains("res/values/resource.xml"); } @@ -1189,7 +1189,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { // Ensure that the args are present ConfiguredTarget binary = getConfiguredTarget("//java/com/google/android:b"); - List<String> args = resourceArguments(getResourceContainer(binary)); + List<String> args = resourceArguments(getValidatedData(binary)); assertThat(flagValue("--resourceConfigs", args)).contains("en,fr"); } @@ -1243,7 +1243,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { " aapt_version = 'aapt2',", " densities = ['hdpi, , ', 'xhdpi'],", " resource_files = ['" + Joiner.on("', '").join(resources) + "'])"); - ResourceContainer directResources = getResourceContainer(binary, /* transitive= */ false); + ValidatedAndroidData directResources = getValidatedData(binary, /* transitive= */ false); // Validate that the AndroidResourceProvider for this binary contains all values. assertThat(resourceContentsPaths(dir, directResources)).containsExactlyElementsIn(resources); @@ -1592,7 +1592,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { .getOutputDirectoryName()) .isNull(); - ResourceContainer directResources = getResourceContainer(binary, /* transitive= */ false); + ValidatedAndroidData directResources = getValidatedData(binary, /* transitive= */ false); // Validate that the AndroidResourceProvider for this binary contains only the filtered values. assertThat(resourceContentsPaths(dir, directResources)) @@ -1649,8 +1649,8 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { " deps = [':lib'],", " resource_configuration_filters = ['en'])"); - ResourceContainer directResources = getResourceContainer(binary, /* transitive= */ false); - ResourceContainer transitiveResources = getResourceContainer(binary, /* transitive= */ true); + ValidatedAndroidData directResources = getValidatedData(binary, /* transitive= */ false); + ValidatedAndroidData transitiveResources = getValidatedData(binary, /* transitive= */ true); assertThat(resourceContentsPaths(dir, directResources)).isEmpty(); @@ -1698,7 +1698,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { " 'multiple/res/drawable-en-mdpi/foo.png'],", ")"); - ResourceContainer directResources = getResourceContainer(binary, /* transitive= */ false); + ValidatedAndroidData directResources = getValidatedData(binary, /* transitive= */ false); // All of the resources are transitive assertThat(resourceContentsPaths(dir, directResources)).isEmpty(); @@ -1752,7 +1752,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { " ])"); List<String> resourceProcessingArgs = - getGeneratingSpawnActionArgs(getResourceContainer(binary).getRTxt()); + getGeneratingSpawnActionArgs(getValidatedData(binary).getRTxt()); assertThat( Iterables.filter( @@ -1784,7 +1784,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { " manifest = 'AndroidManifest.xml')"); List<String> resourceProcessingArgs = - getGeneratingSpawnActionArgs(getResourceContainer(binary).getRTxt()); + getGeneratingSpawnActionArgs(getValidatedData(binary).getRTxt()); assertThat(resourceProcessingArgs).containsAllOf("--resourceConfigs", "ar-rXB,en,en-rXA"); } @@ -1801,7 +1801,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { useConfiguration("--experimental_android_throw_on_resource_conflict"); ConfiguredTarget binary = getConfiguredTarget("//java/r/android:r"); - List<String> resourceProcessingArgs = resourceArguments(getResourceContainer(binary)); + List<String> resourceProcessingArgs = resourceArguments(getValidatedData(binary)); assertThat(resourceProcessingArgs).contains("--throwOnResourceConflict"); } @@ -1813,7 +1813,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { * @return the paths to all artifacts from the input that are contained within the given * directory, relative to that directory. */ - private List<String> resourceContentsPaths(String dir, ResourceContainer resource) { + private List<String> resourceContentsPaths(String dir, ValidatedAndroidData resource) { return pathsToArtifacts(dir, resource.getArtifacts()); } @@ -1826,7 +1826,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { * @return the paths to all artifacts used as inputs to resource processing that are contained * within the given directory, relative to that directory. */ - private List<String> resourceInputPaths(String dir, ResourceContainer resource) { + private List<String> resourceInputPaths(String dir, ValidatedAndroidData resource) { return pathsToArtifacts(dir, resourceGeneratingAction(resource).getInputs()); } @@ -3250,7 +3250,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { " nocompress_extensions = ['.apk', '.so'],", ")"); ConfiguredTarget binary = getConfiguredTarget("//java/r/android:r"); - ResourceContainer resource = getResourceContainer(binary); + ValidatedAndroidData resource = getValidatedData(binary); List<String> args = resourceArguments(resource); Artifact inputManifest = getFirstArtifactEndingWith( @@ -4211,7 +4211,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { ConfiguredTarget b = getDirectPrerequisite(a, "//java/b:b"); List<String> resourceProcessingArgs = - getGeneratingSpawnActionArgs(getResourceContainer(a).getRTxt()); + getGeneratingSpawnActionArgs(getValidatedData(a).getRTxt()); assertThat(resourceProcessingArgs).contains("AAPT2_PACKAGE"); String directData = @@ -4222,7 +4222,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { assertThat(resourceProcessingArgs).contains("--useCompiledResourcesForMerge"); List<String> resourceMergingArgs = - getGeneratingSpawnActionArgs(getResourceContainer(b).getJavaClassJar()); + getGeneratingSpawnActionArgs(getValidatedData(b).getJavaClassJar()); assertThat(resourceMergingArgs).contains("MERGE_COMPILED"); } @@ -4255,7 +4255,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { ConfiguredTarget b = getDirectPrerequisite(a, "//java/b:b"); List<String> resourceProcessingArgs = - getGeneratingSpawnActionArgs(getResourceContainer(a).getRTxt()); + getGeneratingSpawnActionArgs(getValidatedData(a).getRTxt()); assertThat(resourceProcessingArgs).contains("PACKAGE"); String directData = @@ -4265,7 +4265,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { assertThat(directData).contains("merged.bin"); List<String> compiledResourceMergingArgs = - getGeneratingSpawnActionArgs(getResourceContainer(b).getJavaClassJar()); + getGeneratingSpawnActionArgs(getValidatedData(b).getJavaClassJar()); assertThat(compiledResourceMergingArgs).contains("MERGE_COMPILED"); diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java index e85c1c1bcf..2848520e2f 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java @@ -115,12 +115,12 @@ public abstract class AndroidBuildViewTestCase extends BuildViewTestCase { .isNotNull(); } - protected List<String> resourceArguments(ResourceContainer resource) + protected List<String> resourceArguments(ValidatedAndroidData resource) throws CommandLineExpansionException { return getGeneratingSpawnActionArgs(resource.getApk()); } - protected SpawnAction resourceGeneratingAction(ResourceContainer resource) { + protected SpawnAction resourceGeneratingAction(ValidatedAndroidData resource) { return getGeneratingSpawnAction(resource.getApk()); } @@ -130,15 +130,22 @@ public abstract class AndroidBuildViewTestCase extends BuildViewTestCase { protected static ResourceContainer getResourceContainer( ConfiguredTarget target, boolean transitive) { + ValidatedAndroidData validated = getValidatedData(target, transitive); + assertThat(validated).isInstanceOf(ResourceContainer.class); + return (ResourceContainer) validated; + } + + protected static ValidatedAndroidData getValidatedData(ConfiguredTarget target) { + return getValidatedData(target, /* transitive = */ false); + } + protected static ValidatedAndroidData getValidatedData( + ConfiguredTarget target, boolean transitive) { Preconditions.checkNotNull(target); final AndroidResourcesInfo info = target.get(AndroidResourcesInfo.PROVIDER); assertThat(info).named("No android resources exported from the target.").isNotNull(); - ValidatedAndroidData validated = - getOnlyElement( - transitive ? info.getTransitiveAndroidResources() : info.getDirectAndroidResources()); - assertThat(validated).isInstanceOf(ResourceContainer.class); - return (ResourceContainer) validated; + return getOnlyElement( + transitive ? info.getTransitiveAndroidResources() : info.getDirectAndroidResources()); } protected Artifact getResourceClassJar(final ConfiguredTargetAndData target) { @@ -233,6 +240,11 @@ public abstract class AndroidBuildViewTestCase extends BuildViewTestCase { .getJavaClassJar(); } + // Returns an artifact that will be generated when a rule has assets that are processed seperately + static Artifact getDecoupledAssetArtifact(ConfiguredTarget target) { + return target.get(AndroidAssetsInfo.PROVIDER).getValidationResult(); + } + protected static Set<Artifact> getNonToolInputs(Action action) { return Sets.difference( ImmutableSet.copyOf(action.getInputs()), ImmutableSet.copyOf(action.getTools())); diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidLibraryTest.java index 3b97bcbe96..4acc3483b2 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidLibraryTest.java @@ -1233,6 +1233,8 @@ public class AndroidLibraryTest extends AndroidBuildViewTestCase { @Test public void testMultipleDirectDependentResourceDirectories_LocalResources() throws Exception { + useConfiguration("--noandroid_decouple_data_processing"); + scratch.file("java/android/resources/d1/BUILD", "android_library(name = 'd1',", " manifest = 'AndroidManifest.xml',", @@ -1256,10 +1258,44 @@ public class AndroidLibraryTest extends AndroidBuildViewTestCase { assertNoEvents(); } + @Test + public void testMultipleDirectDependentResourceDirectories_DecoupledLocalResources() + throws Exception { + useConfiguration("--android_decouple_data_processing"); + + scratch.file( + "java/android/resources/d1/BUILD", + "android_library(name = 'd1',", + " manifest = 'AndroidManifest.xml',", + " resource_files = ['d1-res/values/strings.xml'],", + " assets = ['assets-d1/some/random/file'],", + " assets_dir = 'assets-d1',", + " deps = ['//java/android/resources/d2:d2'])"); + scratch.file( + "java/android/resources/d2/BUILD", + "android_library(name = 'd2',", + " manifest = 'AndroidManifest.xml',", + " assets = ['assets-d2/some/random/file'],", + " assets_dir = 'assets-d2',", + " resource_files = ['d2-res/values/strings.xml'],", + " )"); + ConfiguredTarget resource = getConfiguredTarget("//java/android/resources/d1:d1"); + List<String> args = getGeneratingSpawnActionArgs(getResourceArtifact(resource)); + assertPrimaryResourceDirs(ImmutableList.of("java/android/resources/d1/d1-res"), args); + assertThat(getDirectDependentResourceDirs(args)).contains("java/android/resources/d2/d2-res"); + + List<String> assetArgs = getGeneratingSpawnActionArgs(getDecoupledAssetArtifact(resource)); + assertThat(getDependentAssetDirs("--directData", assetArgs)) + .contains("java/android/resources/d2/assets-d2"); + + assertNoEvents(); + } @Test public void testTransitiveDependentResourceDirectories_LocalResources() throws Exception { + useConfiguration("--noandroid_decouple_data_processing"); + scratch.file("java/android/resources/d1/BUILD", "android_library(name = 'd1',", " manifest = 'AndroidManifest.xml',", @@ -1298,6 +1334,54 @@ public class AndroidLibraryTest extends AndroidBuildViewTestCase { } @Test + public void testTransitiveDependentResourceDirectories_DecoupledLocalResources() + throws Exception { + useConfiguration("--android_decouple_data_processing"); + + scratch.file( + "java/android/resources/d1/BUILD", + "android_library(name = 'd1',", + " manifest = 'AndroidManifest.xml',", + " resource_files = ['d1-res/values/strings.xml'],", + " assets = ['assets-d1/some/random/file'],", + " assets_dir = 'assets-d1',", + " deps = ['//java/android/resources/d2:d2'])"); + scratch.file( + "java/android/resources/d2/BUILD", + "android_library(name = 'd2',", + " manifest = 'AndroidManifest.xml',", + " assets = ['assets-d2/some/random/file'],", + " assets_dir = 'assets-d2',", + " resource_files = ['d2-res/values/strings.xml'],", + " deps = ['//java/android/resources/d3:d3'],", + " )"); + scratch.file( + "java/android/resources/d3/BUILD", + "android_library(name = 'd3',", + " manifest = 'AndroidManifest.xml',", + " assets = ['assets-d3/some/random/file'],", + " assets_dir = 'assets-d3',", + " resource_files = ['d3-res/values/strings.xml'],", + " )"); + + ConfiguredTarget resource = getConfiguredTarget("//java/android/resources/d1:d1"); + List<String> args = getGeneratingSpawnActionArgs(getResourceArtifact(resource)); + assertPrimaryResourceDirs(ImmutableList.of("java/android/resources/d1/d1-res"), args); + Truth.assertThat(getDirectDependentResourceDirs(args)) + .contains("java/android/resources/d2/d2-res"); + Truth.assertThat(getTransitiveDependentResourceDirs(args)) + .contains("java/android/resources/d3/d3-res"); + + List<String> assetArgs = getGeneratingSpawnActionArgs(getDecoupledAssetArtifact(resource)); + Truth.assertThat(getDependentAssetDirs("--directData", assetArgs)) + .contains("java/android/resources/d2/assets-d2"); + Truth.assertThat(getDependentAssetDirs("--data", assetArgs)) + .contains("java/android/resources/d3/assets-d3"); + + assertNoEvents(); + } + + @Test public void testCustomJavacopts() throws Exception { scratch.file("java/android/BUILD", "android_library(name = 'a',", diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidResourcesTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidResourcesTest.java index 6e8a32a84d..1ab8083626 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidResourcesTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidResourcesTest.java @@ -430,7 +430,9 @@ public class AndroidResourcesTest extends ResourceTestBase { ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_JAVA_SOURCE_JAR), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_APK), /* dataBindingInfoZip = */ null, - ResourceDependencies.fromRuleDeps(ruleContext, /* neverlink = */ false)); + ResourceDependencies.fromRuleDeps(ruleContext, /* neverlink = */ false), + null, + null); ValidatedAndroidData validated = processedData.generateRClass(ruleContext).getValidatedResources(); @@ -442,6 +444,18 @@ public class AndroidResourcesTest extends ResourceTestBase { /* outputs = */ ImmutableList.of(validated.getJavaClassJar())); } + @Test + public void testProcessBinaryDataGeneratesProguardOutput() throws Exception { + RuleContext ruleContext = getRuleContext("android_binary", "manifest='AndroidManifest.xml',"); + + ResourceApk resourceApk = + ProcessedAndroidData.processBinaryDataFrom(ruleContext, getManifest(), false) + .generateRClass(ruleContext); + + assertThat(resourceApk.getResourceProguardConfig()).isNotNull(); + assertThat(resourceApk.getMainDexProguardConfig()).isNotNull(); + } + /** * Validates that a parse action was invoked correctly. Returns the {@link ParsedAndroidResources} * for further validation. @@ -484,13 +498,21 @@ public class AndroidResourcesTest extends ResourceTestBase { /** Gets a dummy rule context object by creating a dummy target. */ private RuleContext getRuleContext(boolean useDataBinding) throws Exception { + return getRuleContext("android_library", useDataBinding ? " enable_data_binding = True" : ""); + } + + /** Gets a dummy rule context object by creating a dummy target. */ + private RuleContext getRuleContext(String kind, String... additionalLines) throws Exception { ConfiguredTarget target = scratchConfiguredTarget( "java/foo", "target", - "android_library(name = 'target',", - useDataBinding ? " enable_data_binding = True" : "", - ")"); + ImmutableList.<String>builder() + .add(kind + "(name = 'target',") + .add(additionalLines) + .add(")") + .build() + .toArray(new String[0])); return getRuleContextForActionTesting(target); } } |