diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules')
5 files changed, 62 insertions, 16 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceMergingActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceMergingActionBuilder.java index 70d70aca56..5aaf7b8991 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceMergingActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceMergingActionBuilder.java @@ -47,20 +47,20 @@ public class AndroidResourceMergingActionBuilder { .withArtifact(MergableAndroidData::getSymbols) .build(); - private static final AndroidDataConverter<ResourceContainer> + private static final AndroidDataConverter<CompiledMergableAndroidData> RESOURCE_CONTAINER_TO_ARG_FOR_COMPILED = - AndroidDataConverter.<ResourceContainer>builder(JoinerType.SEMICOLON_AMPERSAND) - .withRoots(ResourceContainer::getResourceRoots) - .withRoots(ResourceContainer::getAssetRoots) - .withLabel(ResourceContainer::getLabel) - .withArtifact(ResourceContainer::getCompiledSymbols) + AndroidDataConverter.<CompiledMergableAndroidData>builder(JoinerType.SEMICOLON_AMPERSAND) + .withRoots(CompiledMergableAndroidData::getResourceRoots) + .withRoots(CompiledMergableAndroidData::getAssetRoots) + .withLabel(CompiledMergableAndroidData::getLabel) + .withArtifact(CompiledMergableAndroidData::getCompiledSymbols) .build(); private final RuleContext ruleContext; private final AndroidSdkProvider sdk; // Inputs - private ResourceContainer primary; + private CompiledMergableAndroidData primary; private ResourceDependencies dependencies; // Outputs @@ -84,7 +84,7 @@ public class AndroidResourceMergingActionBuilder { * The primary resource for merging. This resource will overwrite any resource or data value in * the transitive closure. */ - public AndroidResourceMergingActionBuilder withPrimary(ResourceContainer primary) { + private AndroidResourceMergingActionBuilder withPrimary(CompiledMergableAndroidData primary) { this.primary = primary; return this; } @@ -245,7 +245,7 @@ public class AndroidResourceMergingActionBuilder { .build(context)); } - public ResourceContainer build(RuleContext context) { + private void build(RuleContext context) { CustomCommandLine.Builder parsedMergeBuilder = new CustomCommandLine.Builder().add("--tool").add("MERGE").add("--"); CustomCommandLine.Builder compiledMergeBuilder = @@ -290,9 +290,13 @@ public class AndroidResourceMergingActionBuilder { if (!parsedMergeOutputs.isEmpty()) { buildParsedResourceMergingAction(parsedMergeBuilder, parsedMergeOutputs, context); } + } + + public ResourceContainer build(RuleContext ruleContext, ResourceContainer resourceContainer) { + withPrimary(resourceContainer).build(ruleContext); // Return the full set of processed transitive dependencies. - ResourceContainer.Builder result = primary.toBuilder(); + ResourceContainer.Builder result = resourceContainer.toBuilder(); if (classJarOut != null) { // ensure the classJar is propagated if it exists. Otherwise, AndroidCommon tries to make it. // TODO(corysmith): Centralize the class jar generation. diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java index 54ad07e2de..62eb612a15 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java @@ -392,7 +392,6 @@ public final class ApplicationManifest { ResourceContainer merged = new AndroidResourceMergingActionBuilder(ruleContext) .setJavaPackage(resourceContainer.getJavaPackage()) - .withPrimary(resourceContainer) .withDependencies(resourceDeps) .setMergedResourcesOut(mergedResources) .setManifestOut(manifestOut) @@ -402,7 +401,7 @@ public final class ApplicationManifest { .getConfiguration() .getFragment(AndroidConfiguration.class) .throwOnResourceConflict()) - .build(ruleContext); + .build(ruleContext, resourceContainer); ResourceContainer processed = new AndroidResourceValidatorActionBuilder(ruleContext) @@ -658,7 +657,6 @@ public final class ApplicationManifest { ResourceContainer merged = new AndroidResourceMergingActionBuilder(ruleContext) .setJavaPackage(resourceContainer.getJavaPackage()) - .withPrimary(resourceContainer) .withDependencies(resourceDeps) .setThrowOnResourceConflict(androidConfiguration.throwOnResourceConflict()) .setUseCompiledMerge(skipParsingAction) @@ -667,7 +665,7 @@ public final class ApplicationManifest { .setManifestOut(manifestOut) .setClassJarOut(rJavaClassJar) .setDataBindingInfoZip(dataBindingInfoZip) - .build(ruleContext); + .build(ruleContext, resourceContainer); ResourceContainer processed = new AndroidResourceValidatorActionBuilder(ruleContext) diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/CompiledMergableAndroidData.java b/src/main/java/com/google/devtools/build/lib/rules/android/CompiledMergableAndroidData.java new file mode 100644 index 0000000000..a32fbf389a --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/android/CompiledMergableAndroidData.java @@ -0,0 +1,32 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.rules.android; + +import com.google.devtools.build.lib.actions.Artifact; +import javax.annotation.Nullable; + +/** + * A {@link MergableAndroidData} that may also contain a compiled symbols file. + * + * <p>TODO(b/76418178): Once resources and assets are completely decoupled and {@link + * ResourceContainer} is removed, this interface can be replaced with {@link ParsedAndroidResources} + */ +public interface CompiledMergableAndroidData extends MergableAndroidData { + @Nullable + Artifact getCompiledSymbols(); + + Iterable<Artifact> getArtifacts(); + + Artifact getManifest(); +} diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ParsedAndroidResources.java b/src/main/java/com/google/devtools/build/lib/rules/android/ParsedAndroidResources.java index 21a4a4ba25..a419b6b134 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/ParsedAndroidResources.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/ParsedAndroidResources.java @@ -22,7 +22,8 @@ import java.util.Objects; import javax.annotation.Nullable; /** Wraps parsed (and, if requested, compiled) android resources. */ -public class ParsedAndroidResources extends AndroidResources { +public class ParsedAndroidResources extends AndroidResources + implements CompiledMergableAndroidData { private final Artifact symbols; @Nullable private final Artifact compiledSymbols; private final Label label; @@ -80,19 +81,28 @@ public class ParsedAndroidResources extends AndroidResources { this.manifest = manifest; } + @Override public Artifact getSymbols() { return symbols; } + @Override @Nullable public Artifact getCompiledSymbols() { return compiledSymbols; } + @Override + public Iterable<Artifact> getArtifacts() { + return getResources(); + } + + @Override public Artifact getManifest() { return manifest.getManifest(); } + @Override public Label getLabel() { return label; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainer.java b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainer.java index 971fed1c3f..d1cf13a255 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainer.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainer.java @@ -42,7 +42,7 @@ import javax.annotation.Nullable; category = SkylarkModuleCategory.NONE, doc = "The Android resources contributed by a single target." ) -public abstract class ResourceContainer implements MergableAndroidData { +public abstract class ResourceContainer implements CompiledMergableAndroidData { /** The type of resource in question: either asset or a resource. */ public enum ResourceType { ASSETS("assets"), @@ -73,6 +73,7 @@ public abstract class ResourceContainer implements MergableAndroidData { doc = "Returns the manifest for the target.", structField = true ) + @Override public abstract Artifact getManifest(); @Nullable @@ -94,6 +95,7 @@ public abstract class ResourceContainer implements MergableAndroidData { : getResources().getResources(); } + @Override public Iterable<Artifact> getArtifacts() { return Iterables.concat(getAssets().getAssets(), getResources().getResources()); } |