aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceMergingActionBuilder.java18
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceParsingActionBuilder.java22
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java19
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java31
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkApiProvider.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/LibraryRGeneratorActionBuilder.java105
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ProcessedAndroidManifest.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java29
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainer.java352
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceDependencies.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ValidatedAndroidResources.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java3
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java10
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/BUILD1
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/ResourceFilterFactoryTest.java35
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java58
18 files changed, 74 insertions, 639 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 23be43f152..055990bebd 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
@@ -201,24 +201,6 @@ public class AndroidResourceMergingActionBuilder {
buildParsedResourceMergingAction(parsedMergeBuilder);
}
- public ResourceContainer build(
- AndroidDataContext dataContext, ResourceContainer resourceContainer) {
- withPrimary(resourceContainer).build(dataContext);
-
- // Return the full set of processed transitive dependencies.
- ResourceContainer.Builder result = resourceContainer.toBuilder();
-
- result.setJavaClassJar(classJarOut);
-
- if (manifestOut != null) {
- result.setManifest(manifestOut);
- }
- if (mergedResourcesOut != null) {
- result.setMergedResources(mergedResourcesOut);
- }
- return result.build();
- }
-
public MergedAndroidResources build(
AndroidDataContext dataContext, ParsedAndroidResources parsed) {
withPrimary(parsed).build(dataContext);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceParsingActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceParsingActionBuilder.java
index e5fe55a0db..f152265a37 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceParsingActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceParsingActionBuilder.java
@@ -145,26 +145,4 @@ public class AndroidResourceParsingActionBuilder {
return ParsedAndroidAssets.of(assets, output, compiledSymbols, dataContext.getLabel());
}
-
- /**
- * Builds and registers the action, and updates the given resourceContainer with the output
- * symbols.
- */
- public ResourceContainer buildAndUpdate(
- AndroidDataContext dataContext, ResourceContainer resourceContainer) {
- build(dataContext);
-
- ResourceContainer.Builder builder =
- resourceContainer
- .toBuilder()
- .setSymbols(output)
- .setAndroidAssets(assets)
- .setAndroidResources(resources);
-
- if (compiledSymbols != null) {
- builder.setCompiledSymbols(compiledSymbols);
- }
-
- return builder.build();
- }
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java
index 13a7c04753..231a2e1d20 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java
@@ -106,25 +106,6 @@ public class AndroidResourceValidatorActionBuilder {
}
}
- public ResourceContainer build(
- AndroidDataContext dataContext, ResourceContainer resourceContainer) {
- withPrimary(resourceContainer).build(dataContext);
- ResourceContainer.Builder builder = resourceContainer.toBuilder();
-
- if (rTxtOut != null) {
- builder.setJavaSourceJar(sourceJarOut).setRTxt(rTxtOut);
- }
-
- if (compiledSymbols != null) {
- builder
- .setAapt2JavaSourceJar(aapt2SourceJarOut)
- .setAapt2RTxt(aapt2RTxtOut)
- .setStaticLibrary(staticLibraryOut);
- }
-
- return builder.build();
- }
-
public ValidatedAndroidResources build(
AndroidDataContext dataContext, MergedAndroidResources merged) {
withPrimary(merged).build(dataContext);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java
index d1a5e9f257..10b5f1ae05 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java
@@ -246,37 +246,6 @@ public class AndroidResourcesProcessorBuilder {
dataBindingContext);
}
- public ResourceContainer build(
- AndroidDataContext dataContext,
- ResourceContainer primary,
- DataBindingContext dataBindingContext) {
- build(
- dataContext,
- primary.getAndroidResources(),
- primary.getAndroidAssets(),
- ProcessedAndroidManifest.from(primary),
- dataBindingContext);
-
- ResourceContainer.Builder builder =
- primary.toBuilder().setJavaSourceJar(sourceJarOut).setRTxt(rTxtOut).setSymbols(symbols);
-
- // If there is an apk to be generated, use it, else reuse the apk from the primary resources.
- // All android_binary ResourceContainers have to have an apk, but if a new one is not
- // requested to be built for this resource processing action (in case of just creating an
- // R.txt or proguard merging), reuse the primary resource from the dependencies.
- if (apkOut != null) {
- builder.setApk(apkOut);
- }
- if (manifestOut != null) {
- builder.setManifest(manifestOut);
- }
- if (mergedResourcesOut != null) {
- builder.setMergedResources(mergedResourcesOut);
- }
-
- return builder.build();
- }
-
public ProcessedAndroidData build(
AndroidDataContext dataContext,
AndroidResources primaryResources,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkApiProvider.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkApiProvider.java
index 27fdde9ed0..190f987a51 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkApiProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkApiProvider.java
@@ -117,7 +117,7 @@ public class AndroidSkylarkApiProvider extends SkylarkApiProvider
return NestedSetBuilder.emptySet(Order.STABLE_ORDER);
}
// This will iterate over all (direct) resources. If this turns out to be a performance
- // problem, {@link ResourceContainer#getArtifacts} can be changed to return NestedSets.
+ // problem, {@link ValidatedAndroidData#getArtifacts()} can be changed to return NestedSets.
return NestedSetBuilder.wrap(
Order.STABLE_ORDER,
Iterables.concat(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/LibraryRGeneratorActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/LibraryRGeneratorActionBuilder.java
deleted file mode 100644
index 3a23bcc5e8..0000000000
--- a/src/main/java/com/google/devtools/build/lib/rules/android/LibraryRGeneratorActionBuilder.java
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2017 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 static com.google.common.collect.ImmutableList.toImmutableList;
-
-import com.google.common.base.Strings;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.actions.ParamFileInfo;
-import com.google.devtools.build.lib.actions.ParameterFile.ParameterFileType;
-import com.google.devtools.build.lib.analysis.FilesToRunProvider;
-import com.google.devtools.build.lib.analysis.RuleContext;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
-import com.google.devtools.build.lib.analysis.actions.SpawnAction;
-import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode;
-import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.collect.nestedset.Order;
-
-/** Builder for the action that generates the R class for libraries. */
-public class LibraryRGeneratorActionBuilder {
- private String javaPackage;
- private Iterable<ValidatedAndroidData> deps = ImmutableList.of();
- private ResourceContainer resourceContainer;
- private Artifact rJavaClassJar;
-
- public LibraryRGeneratorActionBuilder setJavaPackage(String javaPackage) {
- this.javaPackage = javaPackage;
- return this;
- }
-
- public LibraryRGeneratorActionBuilder withPrimary(ResourceContainer resourceContainer) {
- this.resourceContainer = resourceContainer;
- return this;
- }
-
- public LibraryRGeneratorActionBuilder withDependencies(ResourceDependencies resourceDeps) {
- this.deps = resourceDeps.getResourceContainers();
- return this;
- }
-
- public LibraryRGeneratorActionBuilder setClassJarOut(Artifact rJavaClassJar) {
- this.rJavaClassJar = rJavaClassJar;
- return this;
- }
-
- public ResourceContainer build(RuleContext ruleContext) {
- AndroidSdkProvider sdk = AndroidSdkProvider.fromRuleContext(ruleContext);
-
- CustomCommandLine.Builder builder = new CustomCommandLine.Builder();
- NestedSetBuilder<Artifact> inputs = NestedSetBuilder.naiveLinkOrder();
- FilesToRunProvider executable =
- ruleContext.getExecutablePrerequisite("$android_resources_busybox", Mode.HOST);
- inputs.addAll(executable.getRunfilesSupport().getRunfilesArtifacts());
-
- builder.add("--tool").add("GENERATE_LIBRARY_R").add("--");
-
- if (!Strings.isNullOrEmpty(javaPackage)) {
- builder.add("--packageForR", javaPackage);
- }
-
- FluentIterable<ValidatedAndroidData> symbolProviders =
- FluentIterable.from(deps).append(resourceContainer);
-
- if (!symbolProviders.isEmpty()) {
- ImmutableList<Artifact> symbols =
- symbolProviders.stream().map(ValidatedAndroidData::getSymbols).collect(toImmutableList());
- builder.addExecPaths("--symbols", symbols);
- inputs.addTransitive(NestedSetBuilder.wrap(Order.NAIVE_LINK_ORDER, symbols));
- }
-
- builder.addExecPath("--classJarOutput", rJavaClassJar);
- builder.addLabel("--targetLabel", ruleContext.getLabel());
-
- builder.addExecPath("--androidJar", sdk.getAndroidJar());
- inputs.add(sdk.getAndroidJar());
-
- // Create the spawn action.
- SpawnAction.Builder spawnActionBuilder = new SpawnAction.Builder();
- ruleContext.registerAction(
- spawnActionBuilder
- .useDefaultShellEnvironment()
- .addTransitiveInputs(inputs.build())
- .addOutputs(ImmutableList.<Artifact>of(rJavaClassJar))
- .addCommandLine(
- builder.build(), ParamFileInfo.builder(ParameterFileType.SHELL_QUOTED).build())
- .setExecutable(executable)
- .setProgressMessage("Generating Library R Classes: %s", ruleContext.getLabel())
- .setMnemonic("LibraryRClassGenerator")
- .build(ruleContext));
- return resourceContainer.toBuilder().setJavaClassJar(rJavaClassJar).build();
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ProcessedAndroidManifest.java b/src/main/java/com/google/devtools/build/lib/rules/android/ProcessedAndroidManifest.java
index 5d515c03f1..ee4aac0c0d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ProcessedAndroidManifest.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ProcessedAndroidManifest.java
@@ -33,11 +33,4 @@ public class ProcessedAndroidManifest extends StampedAndroidManifest implements
public boolean equals(Object object) {
return (object instanceof ProcessedAndroidManifest) && super.equals(object);
}
-
- public static ProcessedAndroidManifest from(ResourceContainer resourceContainer) {
- return new ProcessedAndroidManifest(
- resourceContainer.getManifest(),
- resourceContainer.getJavaPackage(),
- resourceContainer.isManifestExported());
- }
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java
index 4b3268f31f..fe354b8824 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java
@@ -57,12 +57,6 @@ public class RClassGeneratorActionBuilder {
return this;
}
- public ResourceContainer build(AndroidDataContext dataContext, ResourceContainer primary) {
- build(dataContext, primary.getRTxt(), ProcessedAndroidManifest.from(primary));
-
- return primary.toBuilder().setJavaClassJar(classJarOut).build();
- }
-
public ResourceApk build(AndroidDataContext dataContext, ProcessedAndroidData data) {
build(dataContext, data.getRTxt(), data.getManifest());
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java
index acb9d1d40a..03e192bb2e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java
@@ -52,35 +52,6 @@ public final class ResourceApk {
@Nullable private final Artifact mainDexProguardConfig;
private final DataBindingContext dataBindingContext;
- static ResourceApk of(
- ResourceContainer resourceContainer,
- ResourceDependencies resourceDeps,
- DataBindingContext dataBindingContext) {
- return of(resourceContainer, resourceDeps, null, null, dataBindingContext);
- }
-
- static ResourceApk of(
- ResourceContainer resourceContainer,
- ResourceDependencies resourceDeps,
- @Nullable Artifact resourceProguardConfig,
- @Nullable Artifact mainDexProguardConfig,
- DataBindingContext dataBindingContext) {
- return new ResourceApk(
- resourceContainer.getApk(),
- resourceContainer.getJavaSourceJar(),
- resourceContainer.getJavaClassJar(),
- resourceDeps,
- AssetDependencies.empty(),
- resourceContainer,
- resourceContainer.getAndroidResources(),
- resourceContainer.getAndroidAssets(),
- resourceContainer.getProcessedManifest(),
- resourceContainer.getRTxt(),
- resourceProguardConfig,
- mainDexProguardConfig,
- dataBindingContext);
- }
-
public static ResourceApk of(
ValidatedAndroidResources resources,
MergedAndroidAssets assets,
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
deleted file mode 100644
index 92055de918..0000000000
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainer.java
+++ /dev/null
@@ -1,352 +0,0 @@
-// Copyright 2017 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.auto.value.AutoValue;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.analysis.RuleContext;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
-import com.google.devtools.build.lib.packages.RuleErrorConsumer;
-import com.google.devtools.build.lib.syntax.Type;
-import com.google.devtools.build.lib.vfs.PathFragment;
-import java.util.Objects;
-import java.util.Optional;
-import javax.annotation.Nullable;
-
-/** The resources contributed by a single target. */
-@AutoValue
-@Immutable
-public abstract class ResourceContainer implements ValidatedAndroidData {
- /** The type of resource in question: either asset or a resource. */
- public enum ResourceType {
- ASSETS("assets"),
- RESOURCES("resources");
-
- private final String attribute;
-
- private ResourceType(String attribute) {
- this.attribute = attribute;
- }
-
- public String getAttribute() {
- return attribute;
- }
- }
-
- public abstract Label getLabel();
-
- @Nullable
- public abstract String getJavaPackage();
-
- @Override
- @Nullable
- public abstract Artifact getApk();
-
- @Override
- public ProcessedAndroidManifest getProcessedManifest() {
- return new ProcessedAndroidManifest(getManifest(), getJavaPackage(), isManifestExported());
- }
-
- @Override
- public abstract Artifact getManifest();
-
- @Override
- @Nullable
- public abstract Artifact getJavaSourceJar();
-
- @Nullable
- public abstract Artifact getJavaClassJar();
-
- @Override
- public ImmutableList<Artifact> getAssets() {
- return getAndroidAssets().getAssets();
- }
-
- public abstract AndroidAssets getAndroidAssets();
-
- @Override
- public ImmutableList<Artifact> getResources() {
- return getAndroidResources().getResources();
- }
-
- @VisibleForTesting
- public abstract AndroidResources getAndroidResources();
-
- /** @deprecated We are moving towards decoupling assets and resources */
- @Deprecated
- public ImmutableList<Artifact> getArtifacts(ResourceType resourceType) {
- return resourceType == ResourceType.ASSETS ? getAssets() : getResources();
- }
-
- @Override
- public Iterable<Artifact> getArtifacts() {
- return Iterables.concat(getAssets(), getResources());
- }
-
- @Override
- public ImmutableList<PathFragment> getResourceRoots() {
- return getAndroidResources().getResourceRoots();
- }
-
- @Override
- public ImmutableList<PathFragment> getAssetRoots() {
- return getAndroidAssets().getAssetRoots();
- }
-
- /**
- * Gets the directories containing the resources of a specific type.
- *
- * <p>TODO(b/30308041): Stop using these directories, and remove this code.
- *
- * @deprecated We are moving towards passing around the actual artifacts, rather than the
- * directories that contain them. If the resources were provided with a glob() that excludes
- * some files, the resource directory will still contain those files, resulting in unwanted
- * inputs.
- */
- @Deprecated
- public ImmutableList<PathFragment> getRoots(ResourceType resourceType) {
- return resourceType == ResourceType.ASSETS ? getAssetRoots() : getResourceRoots();
- }
-
- @Override
- public abstract boolean isManifestExported();
-
- @Nullable
- public abstract Artifact getRTxt();
-
- @Nullable
- public abstract Artifact getSymbols();
-
- @Nullable
- public abstract Artifact getCompiledSymbols();
-
- @Nullable
- public abstract Artifact getStaticLibrary();
-
- @Nullable
- public abstract Artifact getAapt2RTxt();
-
- @Nullable
- public abstract Artifact getAapt2JavaSourceJar();
-
- @Nullable
- @Override
- @Deprecated
- public abstract Artifact getMergedResources();
-
- // The limited hashCode and equals behavior is necessary to avoid duplication when building with
- // fat_apk_cpu set. Artifacts generated in different configurations will naturally be different
- // and non-equal objects, causing the ResourceContainer not to be automatically deduplicated at
- // the android_binary level.
- // TODO(bazel-team): deduplicate explicitly and remove hashCode and equals overrides to avoid
- // breaking "equals means interchangeable"
- @Override
- public int hashCode() {
- return Objects.hash(getLabel(), getRTxt(), getSymbols());
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof ResourceContainer)) {
- return false;
- }
- ResourceContainer other = (ResourceContainer) obj;
- return Objects.equals(getLabel(), other.getLabel())
- && Objects.equals(getRTxt(), other.getRTxt())
- && Objects.equals(getSymbols(), other.getSymbols());
- }
-
- /** Converts this container back into a builder to create a modified copy. */
- public abstract Builder toBuilder();
-
- /**
- * Returns a copy of this container with filtered resources, or the original if no resources
- * should be filtered. The original container is unchanged.
- */
- public ResourceContainer filter(
- RuleErrorConsumer errorConsumer, ResourceFilter filter, boolean isDependency)
- throws RuleErrorException {
- Optional<? extends AndroidResources> filteredResources =
- getAndroidResources().maybeFilter(errorConsumer, filter, isDependency);
-
- if (!filteredResources.isPresent()) {
- // No filtering was done; return this container
- return this;
- }
- return toBuilder().setAndroidResources(filteredResources.get()).build();
- }
-
- /** Creates a new builder with default values. */
- public static Builder builder() {
- return new AutoValue_ResourceContainer.Builder()
- .setJavaPackageFrom(Builder.JavaPackageSource.MANIFEST)
- .setAndroidAssets(AndroidAssets.empty())
- .setAndroidResources(AndroidResources.empty());
- }
-
- /**
- * Creates a new builder with the label, Java package, manifest package override, Java source jar,
- * and manifest-export switch set according to the given rule.
- */
- public static Builder builderFromRule(RuleContext ruleContext) throws InterruptedException {
- return builder().forRuleContext(ruleContext);
- }
-
- /** Builder to construct resource containers. */
- @AutoValue.Builder
- public abstract static class Builder {
- /** Enum to determine what to do if a package hasn't been manually set. */
- public enum JavaPackageSource {
- /**
- * Uses the package from the manifest, i.e., the generated ResourceContainer will return null
- * from {@link ResourceContainer#getJavaPackage()}.
- */
- MANIFEST,
- /**
- * Uses the package from the path to the source jar (or, if the rule context has it set, the
- * {@code custom_package} attribute). If the source jar is not under a valid Java root, this
- * will result in an error being added to the rule context. This can only be used if the
- * builder was created by {@link ResourceContainer#builderFromRule(RuleContext)}.
- */
- SOURCE_JAR_PATH
- }
-
- @Nullable private RuleContext ruleContext;
- @Nullable private JavaPackageSource javaPackageSource;
-
- private Builder forRuleContext(RuleContext ruleContext) throws InterruptedException {
- Preconditions.checkNotNull(ruleContext);
- this.ruleContext = ruleContext;
- return this.setLabel(ruleContext.getLabel())
- .setJavaSourceJar(
- ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_JAVA_SOURCE_JAR))
- .setJavaPackageFrom(JavaPackageSource.SOURCE_JAR_PATH)
- .setManifestExported(AndroidCommon.getExportsManifest(ruleContext));
- }
-
- /**
- * Sets the Java package from the given source. Overrides earlier calls to {@link
- * #setJavaPackageFrom(JavaPackageSource)} or {@link #setJavaPackageFromString(String)}.
- *
- * <p>To set the package from {@link JavaPackageSource#SOURCE_JAR_PATH}, this instance must have
- * been created using {@link ResourceContainer#builderFromRule(RuleContext)}. Also in this case,
- * the source jar must be set non-{@code null} when the {@link #build()} method is called. It
- * defaults to the source jar implicit output when creating a builder out of a rule context.
- */
- public Builder setJavaPackageFrom(JavaPackageSource javaPackageSource) {
- Preconditions.checkNotNull(javaPackageSource);
- Preconditions.checkArgument(
- !(javaPackageSource == JavaPackageSource.SOURCE_JAR_PATH && ruleContext == null),
- "setJavaPackageFrom(SOURCE_JAR_PATH) is only permitted when using builderFromRule.");
- this.javaPackageSource = javaPackageSource;
- return this.setJavaPackage(null);
- }
-
- /**
- * Sets the Java package from the given string. Overrides earlier calls to {@link
- * #setJavaPackageFrom(JavaPackageSource)} or {@link #setJavaPackageFromString(String)}.
- *
- * <p>To make {@link ResourceContainer#getJavaPackage()} return {@code null}, call {@code
- * setJavaPackageFrom(MANIFEST)} instead.
- */
- public Builder setJavaPackageFromString(String javaPackageOverride) {
- Preconditions.checkNotNull(javaPackageOverride);
- this.javaPackageSource = null;
- return this.setJavaPackage(javaPackageOverride);
- }
-
- public abstract Builder setLabel(Label label);
-
- abstract Builder setJavaPackage(@Nullable String javaPackage);
-
- public abstract Builder setApk(@Nullable Artifact apk);
-
- public abstract Builder setManifest(Artifact manifest);
-
- @Nullable
- abstract Artifact getJavaSourceJar();
-
- public abstract Builder setJavaSourceJar(@Nullable Artifact javaSourceJar);
-
- public abstract Builder setJavaClassJar(@Nullable Artifact javaClassJar);
-
- public abstract Builder setAndroidAssets(AndroidAssets assets);
-
- public abstract Builder setAndroidResources(AndroidResources resources);
-
- public abstract Builder setManifestExported(boolean manifestExported);
-
- public abstract Builder setRTxt(@Nullable Artifact rTxt);
-
- public abstract Builder setSymbols(@Nullable Artifact symbols);
-
- public abstract Builder setCompiledSymbols(@Nullable Artifact compiledSymbols);
-
- public abstract Builder setStaticLibrary(@Nullable Artifact staticLibrary);
-
- public abstract Builder setAapt2JavaSourceJar(@Nullable Artifact javaSourceJar);
-
- public abstract Builder setAapt2RTxt(@Nullable Artifact rTxt);
-
- public abstract Builder setMergedResources(@Nullable Artifact mergedResources);
-
- abstract ResourceContainer autoBuild();
-
- /**
- * Builds and returns the ResourceContainer.
- *
- * <p>May result in the rule context adding a rule error if the Java package was to be set from
- * the source jar path, but the source jar does not have an acceptable Java package.
- */
- public ResourceContainer build() {
- if (javaPackageSource == JavaPackageSource.SOURCE_JAR_PATH) {
- Preconditions.checkState(
- !(javaPackageSource == JavaPackageSource.SOURCE_JAR_PATH && ruleContext == null),
- "setJavaPackageFrom(SOURCE_JAR_PATH) is only permitted when using builderFromRule.");
- Preconditions.checkState(
- getJavaSourceJar() != null,
- "setJavaPackageFrom(SOURCE_JAR_PATH) was called, but no source jar was set.");
- setJavaPackage(getJavaPackageFromSourceJarPath());
- }
- return autoBuild();
- }
-
- @Nullable
- private String getJavaPackageFromSourceJarPath() {
- if (javaPackageSource != JavaPackageSource.SOURCE_JAR_PATH) {
- return null;
- }
- if (hasCustomPackage(ruleContext)) {
- return ruleContext.attributes().get("custom_package", Type.STRING);
- }
-
- return AndroidManifest.getJavaPackageFromPath(
- ruleContext, ruleContext, getJavaSourceJar().getExecPath());
- }
-
- private static boolean hasCustomPackage(RuleContext ruleContext) {
- return ruleContext.attributes().isAttributeValueExplicitlySpecified("custom_package");
- }
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceDependencies.java b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceDependencies.java
index ab59a6869c..ac0fbc652b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceDependencies.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceDependencies.java
@@ -29,15 +29,14 @@ import java.util.Optional;
import javax.annotation.Nullable;
/**
- * Represents a container for the {@link ResourceContainer}s for a given library. This is
- * abstraction simplifies the process of managing and exporting the direct and transitive resource
- * dependencies of an android rule, as well as providing type safety.
+ * Represents a container for the resource dependencies for a given target. This abstraction
+ * simplifies the process of managing and exporting the direct and transitive resource dependencies
+ * of an android rule, as well as providing type safety.
*
* <p>The transitive and direct dependencies are not guaranteed to be disjoint. If a library is
* included in both the transitive and direct dependencies, it will appear twice. This requires
* consumers to manage duplicated resources gracefully.
*
- *
* <p>TODO(b/76418178): Once resource processing is fully decoupled from asset and manifest
* processing, remove asset and manifest fields from this class.
*/
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java
index f5861a72c8..a327e4ac63 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java
@@ -79,7 +79,7 @@ public class ResourceShrinkerActionBuilder {
return this;
}
- /** @param resourceDeps The full dependency tree of {@link ResourceContainer}s. */
+ /** @param resourceDeps The full dependency tree of resources. */
public ResourceShrinkerActionBuilder withDependencies(ResourceDependencies resourceDeps) {
this.dependencyResources = resourceDeps;
return this;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ValidatedAndroidResources.java b/src/main/java/com/google/devtools/build/lib/rules/android/ValidatedAndroidResources.java
index 4c151328e9..231221e912 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ValidatedAndroidResources.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ValidatedAndroidResources.java
@@ -90,9 +90,9 @@ public class ValidatedAndroidResources extends MergedAndroidResources
Artifact rTxt,
Artifact sourceJar,
Artifact apk,
- Artifact aapt2RTxt,
- Artifact aapt2SourceJar,
- Artifact staticLibrary) {
+ @Nullable Artifact aapt2RTxt,
+ @Nullable Artifact aapt2SourceJar,
+ @Nullable Artifact staticLibrary) {
return new ValidatedAndroidResources(
merged, rTxt, sourceJar, apk, aapt2RTxt, aapt2SourceJar, staticLibrary);
}
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 06e603b901..38d691b39d 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
@@ -1849,8 +1849,7 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase {
* Gets the paths of matching artifacts that are used as input to resource processing
*
* @param dir the directory to look for artifacts in
- * @param resource the ResourceContainer output from the resource processing that uses these
- * artifacts as inputs
+ * @param resource the output from the resource processing that uses these artifacts as inputs
* @return the paths to all artifacts used as inputs to resource processing that are contained
* within the given directory, relative to that directory.
*/
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 f269d3dd80..a360befaac 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
@@ -124,15 +124,15 @@ public abstract class AndroidBuildViewTestCase extends BuildViewTestCase {
return getGeneratingSpawnAction(resource.getApk());
}
- protected static ResourceContainer getResourceContainer(ConfiguredTarget target) {
- return getResourceContainer(target, /* transitive= */ false);
+ protected static ValidatedAndroidResources getValidatedResources(ConfiguredTarget target) {
+ return getValidatedResources(target, /* transitive= */ false);
}
- protected static ResourceContainer getResourceContainer(
+ protected static ValidatedAndroidResources getValidatedResources(
ConfiguredTarget target, boolean transitive) {
ValidatedAndroidData validated = getValidatedData(target, transitive);
- assertThat(validated).isInstanceOf(ResourceContainer.class);
- return (ResourceContainer) validated;
+ assertThat(validated).isInstanceOf(ValidatedAndroidResources.class);
+ return (ValidatedAndroidResources) validated;
}
protected static ValidatedAndroidData getValidatedData(ConfiguredTarget target) {
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD
index b04f6061cf..d7c256c228 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD
@@ -141,6 +141,7 @@ java_library(
srcs = ["ResourceTestBase.java"],
deps = [
":AndroidBuildViewTestCase",
+ "//src/main/java/com/google/devtools/build/lib:android-rules",
"//src/main/java/com/google/devtools/build/lib:build-base",
"//src/main/java/com/google/devtools/build/lib:events",
"//src/main/java/com/google/devtools/build/lib:packages-internal",
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceFilterFactoryTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceFilterFactoryTest.java
index 1793e42b14..5ab028a7cd 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceFilterFactoryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceFilterFactoryTest.java
@@ -19,7 +19,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.truth.BooleanSubject;
import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
@@ -39,34 +38,22 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ResourceFilterFactoryTest extends ResourceTestBase {
- private NestedSet<ValidatedAndroidData> getResourceContainers(
- ImmutableList<Artifact>... resources) throws Exception {
+ private NestedSet<ValidatedAndroidData> getResources(ImmutableList<Artifact>... resources)
+ throws Exception {
NestedSetBuilder<ValidatedAndroidData> builder = NestedSetBuilder.naiveLinkOrder();
for (ImmutableList<Artifact> resourceList : resources) {
- builder.add(getResourceContainer(resourceList));
+ builder.add(getResources(resourceList));
}
return builder.build();
}
- private ResourceContainer getResourceContainer(ImmutableList<Artifact> resources)
+ private ValidatedAndroidResources getResources(ImmutableList<Artifact> resources)
throws Exception {
- // Get dummy objects for irrelevant values required by the builder.
- Artifact manifest = getResource("manifest");
-
- // Include a hashCode of the resources in the label. A hack in ResourceContainer currently means
- // that class has a limited hashCode method that doesn't take resources into account.
- // TODO(bazel-team): Remove this hack once that one no longer exists.
- Label label =
- Label.create(
- manifest.getOwnerLabel().getPackageName(), "resourceContainer_" + resources.hashCode());
-
- return ResourceContainer.builder()
- .setAndroidResources(
- AndroidResources.forResources(errorConsumer, resources, "resource_files"))
- .setLabel(label)
- .setManifestExported(false)
- .setManifest(manifest)
- .build();
+ return makeValidatedResourcesFor(
+ resources,
+ /* includeAapt2Outs = */ true,
+ new ProcessedAndroidManifest(getOutput("manifest"), "com.some.pkg", /* exported = */ false),
+ ResourceDependencies.empty());
}
@Test
@@ -363,10 +350,10 @@ public class ResourceFilterFactoryTest extends ResourceTestBase {
ResourceDependencies resourceDependencies =
ResourceDependencies.empty()
.withResources(
- getResourceContainers(
+ getResources(
ImmutableList.of(transitiveResourceToDiscard),
ImmutableList.of(transitiveResourceToKeep)),
- getResourceContainers(
+ getResources(
ImmutableList.of(directResourceToDiscard),
ImmutableList.of(directResourceToKeep)),
new NestedSetBuilder<Artifact>(Order.NAIVE_LINK_ORDER)
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java
index dad6ee04fe..073a2e4030 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java
@@ -34,6 +34,7 @@ import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.events.ExtendedEventHandler;
import com.google.devtools.build.lib.events.StoredEventHandler;
import com.google.devtools.build.lib.packages.AbstractRuleErrorConsumer;
+import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.packages.RuleErrorConsumer;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
import com.google.devtools.build.lib.vfs.FileSystem;
@@ -62,14 +63,15 @@ public abstract class ResourceTestBase extends AndroidBuildViewTestCase {
"android.jar",
"ResourceProcessorBusyBox_deploy.jar");
- private static final ArtifactOwner OWNER = () -> {
- try {
- return Label.create("java", "all");
- } catch (LabelSyntaxException e) {
- assertWithMessage(e.getMessage()).fail();
- return null;
- }
- };
+ private static final ArtifactOwner OWNER =
+ () -> {
+ try {
+ return Label.create("java", "all");
+ } catch (LabelSyntaxException e) {
+ assertWithMessage(e.getMessage()).fail();
+ return null;
+ }
+ };
/** A faked {@link RuleErrorConsumer} that validates that only expected errors were reported. */
public static final class FakeRuleErrorConsumer extends AbstractRuleErrorConsumer
@@ -202,8 +204,16 @@ public abstract class ResourceTestBase extends AndroidBuildViewTestCase {
return builder.build();
}
- public Artifact getResource(String pathString) {
- Path path = fileSystem.getPath("/" + RESOURCE_ROOT + "/" + pathString);
+ Artifact getResource(String pathString) {
+ return getArtifact(RESOURCE_ROOT, pathString);
+ }
+
+ Artifact getOutput(String pathString) {
+ return getArtifact("outputs", pathString);
+ }
+
+ private Artifact getArtifact(String subdir, String pathString) {
+ Path path = fileSystem.getPath("/" + subdir + "/" + pathString);
return new Artifact(
root, root.getExecPath().getRelative(root.getRoot().relativize(path)), OWNER);
}
@@ -236,6 +246,34 @@ public abstract class ResourceTestBase extends AndroidBuildViewTestCase {
ImmutableList.of(dummy.getConfiguration()), dummy.getHostConfiguration()));
}
+ public ValidatedAndroidResources makeValidatedResourcesFor(
+ ImmutableList<Artifact> resources,
+ boolean includeAapt2Outs,
+ ProcessedAndroidManifest manifest,
+ ResourceDependencies resourceDependencies)
+ throws RuleErrorException {
+ return ValidatedAndroidResources.of(
+ MergedAndroidResources.of(
+ ParsedAndroidResources.of(
+ AndroidResources.forResources(errorConsumer, resources, "resource_files"),
+ getOutput("symbols.bin"),
+ includeAapt2Outs ? getOutput("symbols.zip") : null,
+ manifest.getManifest().getOwnerLabel(),
+ manifest,
+ DataBinding.asDisabledDataBindingContext()),
+ getOutput("merged/resources.zip"),
+ getOutput("class.jar"),
+ /* dataBindingInfoZip = */ null,
+ resourceDependencies,
+ manifest),
+ getOutput("r.txt"),
+ getOutput("source.jar"),
+ getOutput("resources.apk"),
+ includeAapt2Outs ? getOutput("aapt2-r.txt") : null,
+ includeAapt2Outs ? getOutput("aapt2-source.jar") : null,
+ includeAapt2Outs ? getOutput("aapt2-static-lib") : null);
+ }
+
/**
* Assets that the action used to generate the given outputs has the expected inputs and outputs.
*/