diff options
author | 2018-04-13 12:21:12 -0700 | |
---|---|---|
committer | 2018-04-13 12:24:31 -0700 | |
commit | 445fb097b82aae3b2e5736aea540ecb907d5f052 (patch) | |
tree | a69f7a22a042bd9cec3b01d5a567fcd9f376d59c /src/test/java/com/google/devtools | |
parent | 10d9155d6b1fad5c05c5872fb917cc77fbc61810 (diff) |
Resource-only merge action
Create wrapper for merged resources, and methods to make it from parsed
resources.
Currently just reuse the ResourceDependencies class to provide resource
dependencies; we could create an interface and another class, but this class is
good enough (and will be resource-specific once we finish decoupling assets,
resources, and manifests).
Note that, like the previous parse action, merging sometimes has a dependency
on the stamped manifest, so resources and manifests will only be mostly
decoupled.
Also, make the merge action not require an output manifest for cases like this.
RELNOTES: none
PiperOrigin-RevId: 192805891
Diffstat (limited to 'src/test/java/com/google/devtools')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/android/AndroidResourcesTest.java | 75 |
1 files changed, 73 insertions, 2 deletions
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 85d7e254b7..15c7eb8b88 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 @@ -45,7 +45,8 @@ public class AndroidResourcesTest extends ResourceTestBase { private static final ImmutableList<PathFragment> RESOURCES_ROOTS = ImmutableList.of(DEFAULT_RESOURCE_ROOT); - private static final ImmutableSet<String> TOOL_FILENAMES = ImmutableSet.of("aapt2", "empty.sh"); + private static final ImmutableSet<String> TOOL_FILENAMES = + ImmutableSet.of("aapt2", "empty.sh", "android_blaze.jar", "android.jar"); @Before @Test @@ -249,6 +250,76 @@ public class AndroidResourcesTest extends ResourceTestBase { parsed.getCompiledSymbols(), DataBinding.getSuffixedInfoFile(ruleContext, "_unused"))); } + @Test + public void testMergeDataBinding() throws Exception { + useConfiguration("--android_aapt=aapt"); + + RuleContext ruleContext = getRuleContext(/* useDataBinding = */ true); + ParsedAndroidResources parsed = assertParse(ruleContext); + MergedAndroidResources merged = parsed.merge(ruleContext, /* neverlink = */ false); + + // Besides processed manifest, inherited values should be equal + assertThat(parsed).isEqualTo(new ParsedAndroidResources(merged, parsed.getStampedManifest())); + + // There should be a new processed manifest + assertThat(merged.getManifest()).isNotEqualTo(parsed.getManifest()); + + assertThat(merged.getDataBindingInfoZip()).isNotNull(); + + assertActionArtifacts( + ruleContext, + /* inputs = */ ImmutableList.<Artifact>builder() + .addAll(merged.getResources()) + .add(merged.getSymbols()) + .add(parsed.getManifest()) + .build(), + /* outputs = */ ImmutableList.of( + merged.getMergedResources(), + merged.getClassJar(), + merged.getDataBindingInfoZip(), + merged.getManifest())); + } + + @Test + public void testMergeCompiled() throws Exception { + mockAndroidSdkWithAapt2(); + useConfiguration( + "--android_sdk=//sdk:sdk", "--android_aapt=aapt2", "--experimental_skip_parsing_action"); + + RuleContext ruleContext = getRuleContext(/* useDataBinding = */ false); + ParsedAndroidResources parsed = assertParse(ruleContext); + MergedAndroidResources merged = parsed.merge(ruleContext, /* neverlink = */ false); + + // Besides processed manifest, inherited values should be equal + assertThat(parsed).isEqualTo(new ParsedAndroidResources(merged, parsed.getStampedManifest())); + + // There should be a new processed manifest + assertThat(merged.getManifest()).isNotEqualTo(parsed.getManifest()); + + assertThat(merged.getDataBindingInfoZip()).isNull(); + assertThat(merged.getCompiledSymbols()).isNotNull(); + + // We use the compiled symbols file to build the resource class jar + assertActionArtifacts( + ruleContext, + /* inputs = */ ImmutableList.<Artifact>builder() + .addAll(merged.getResources()) + .add(merged.getCompiledSymbols()) + .add(parsed.getManifest()) + .build(), + /* outputs = */ ImmutableList.of(merged.getClassJar(), merged.getManifest())); + + // The old symbols file is still needed to build the merged resources zip + assertActionArtifacts( + ruleContext, + /* inputs = */ ImmutableList.<Artifact>builder() + .addAll(merged.getResources()) + .add(merged.getSymbols()) + .add(parsed.getManifest()) + .build(), + /* outputs = */ ImmutableList.of(merged.getMergedResources())); + } + /** * Assets that the action used to generate the given outputs has the expected inputs and outputs. */ @@ -297,7 +368,7 @@ public class AndroidResourcesTest extends ResourceTestBase { ParsedAndroidResources parsed = raw.parse(ruleContext, manifest); // Inherited values should be equal - assertThat(raw).isEqualTo(parsed); + assertThat(raw).isEqualTo(new AndroidResources(parsed)); // Label should be set from RuleContext assertThat(parsed.getLabel()).isEqualTo(ruleContext.getLabel()); |