diff options
author | 2018-05-03 12:51:55 -0700 | |
---|---|---|
committer | 2018-05-03 12:53:41 -0700 | |
commit | 8aa610bb7fce80440a563f91b32783716f51e77d (patch) | |
tree | bf088c908ff160feb2d3e901e70eba702a6b9db9 | |
parent | 807bdbc722c8318548a1e0952053de32f7ef96b6 (diff) |
Methods for generating empty Android data providers
RELNOTES: none
PiperOrigin-RevId: 195296176
8 files changed, 153 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesInfo.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesInfo.java index 4af26bff72..6f1d665be4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesInfo.java @@ -36,7 +36,26 @@ public class AndroidResourcesInfo extends NativeInfo { public static final NativeProvider<AndroidResourcesInfo> PROVIDER = new NativeProvider<AndroidResourcesInfo>(AndroidResourcesInfo.class, SKYLARK_NAME) {}; + /* + * Local information about the target that produced this provider, for tooling. These values will + * be made available even if they should not be inherited (for example, if this target has + * "neverlink" set) - do not inherit them directly. + */ + + // Lets us know where the provider came from private final Label label; + + // An updated manifest - resource processing sometimes does additional manifest processing + // TODO(b/30817309): Remove this once resource processing no longer does manifest processing + private final ProcessedAndroidManifest manifest; + + // An R.txt file containing a list of all transitive resources this target expected + private final Artifact rTxt; + + /* + * Transitive information used for resource processing + */ + private final NestedSet<ValidatedAndroidData> transitiveAndroidResources; private final NestedSet<ValidatedAndroidData> directAndroidResources; private final NestedSet<Artifact> transitiveResources; @@ -50,6 +69,8 @@ public class AndroidResourcesInfo extends NativeInfo { AndroidResourcesInfo( Label label, + ProcessedAndroidManifest manifest, + Artifact rTxt, NestedSet<ValidatedAndroidData> transitiveAndroidResources, NestedSet<ValidatedAndroidData> directAndroidResources, NestedSet<Artifact> transitiveResources, @@ -62,6 +83,8 @@ public class AndroidResourcesInfo extends NativeInfo { NestedSet<Artifact> transitiveRTxt) { super(PROVIDER); this.label = label; + this.manifest = manifest; + this.rTxt = rTxt; this.transitiveAndroidResources = transitiveAndroidResources; this.directAndroidResources = directAndroidResources; this.transitiveResources = transitiveResources; @@ -80,6 +103,14 @@ public class AndroidResourcesInfo extends NativeInfo { return label; } + public ProcessedAndroidManifest getManifest() { + return manifest; + } + + public Artifact getRTxt() { + return rTxt; + } + /** Returns the transitive ResourceContainers for the label. */ @SkylarkCallable( name = "transitive_android_resources", 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 a93740d3b1..3417f538c6 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 @@ -234,7 +234,7 @@ public class AndroidResourcesProcessorBuilder { return ResourceApk.fromTransitiveResources( resourceDependencies, assetDependencies, - manifestOut == null ? manifest.getManifest() : manifestOut, + manifest.withProcessedManifest(manifestOut == null ? manifest.getManifest() : manifestOut), rTxtOut); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkData.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkData.java index 66b0602774..4b8574bda3 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkData.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkData.java @@ -40,6 +40,94 @@ import javax.annotation.Nullable; public class AndroidSkylarkData { /** + * Skylark API for getting a asset provider for android_library targets that don't specify assets. + * + * <p>TODO(b/79159379): Stop passing SkylarkRuleContext here + * + * @param ctx the SkylarkRuleContext. We will soon change to using an ActionConstructionContext + * instead. See b/79159379 + */ + @SkylarkCallable( + name = "assets_from_deps", + mandatoryPositionals = 1, // context + parameters = { + @Param( + name = "deps", + defaultValue = "[]", + type = SkylarkList.class, + generic1 = AndroidAssetsInfo.class, + positional = false, + named = true, + doc = "Dependencies to inherit assets from"), + @Param( + name = "neverlink", + defaultValue = "False", + type = Boolean.class, + positional = false, + named = true, + doc = + "Defaults to False. If true, assets will not be exposed to targets that depend on" + + " them.") + }, + doc = + "Creates an AndroidAssetsInfo from this target's asset dependencies, ignoring local" + + " assets. No processing will be done. This method is deprecated and exposed only" + + " for backwards-compatibility with existing Native behavior.") + public static AndroidAssetsInfo assetsFromDeps( + SkylarkRuleContext ctx, SkylarkList<AndroidAssetsInfo> deps, boolean neverlink) + throws EvalException { + return AssetDependencies.fromProviders(deps, neverlink).toInfo(ctx.getLabel()); + } + + /** + * Skylark API for getting a resource provider for android_library targets that don't specify + * resources. + * + * <p>TODO(b/79159379): Stop passing SkylarkRuleContext here + * + * @param ctx the SkylarkRuleContext. We will soon change to using an ActionConstructionContext + * instead. See b/79159379 + */ + @SkylarkCallable( + name = "resources_from_deps", + mandatoryPositionals = 1, // context + parameters = { + @Param( + name = "deps", + defaultValue = "[]", + type = SkylarkList.class, + generic1 = AndroidResourcesInfo.class, + positional = false, + named = true, + doc = "Dependencies to inherit resources from"), + @Param( + name = "neverlink", + defaultValue = "False", + type = Boolean.class, + positional = false, + named = true, + doc = + "Defaults to False. If true, resources will not be exposed to targets that depend" + + " on them.") + }, + doc = + "Creates an AndroidResourcesInfo from this target's resource dependencies, ignoring local" + + " resources. Only processing of deps will be done. This method is deprecated and" + + " exposed only for backwards-compatibility with existing Native behavior. An empty" + + " manifest will be generated and included in the provider - this path should not" + + " be used when an explicit manifest is specified.") + public static AndroidResourcesInfo resourcesFromDeps( + SkylarkRuleContext ctx, SkylarkList<AndroidResourcesInfo> deps, boolean neverlink) + throws EvalException, InterruptedException { + return ResourceApk.processFromTransitiveLibraryData( + ctx.getRuleContext(), + ResourceDependencies.fromProviders(deps, /* neverlink = */ neverlink), + AssetDependencies.empty(), + StampedAndroidManifest.createEmpty(ctx.getRuleContext(), /* exported = */ false)) + .toResourceInfo(ctx.getLabel()); + } + + /** * Skylark API for stamping an Android manifest * * <p>TODO(b/79159379): Stop passing SkylarkRuleContext here diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/MergedAndroidResources.java b/src/main/java/com/google/devtools/build/lib/rules/android/MergedAndroidResources.java index 70ed4dfb9b..8229b3aabf 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/MergedAndroidResources.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/MergedAndroidResources.java @@ -131,6 +131,10 @@ public class MergedAndroidResources extends ParsedAndroidResources { return manifest; } + public ProcessedAndroidManifest getProcessedManifest() { + return manifest; + } + public ResourceDependencies getResourceDependencies() { return resourceDependencies; } 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 96115475d9..cc826a067c 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 @@ -45,7 +45,8 @@ public final class ResourceApk { private final AndroidResources primaryResources; private final AndroidAssets primaryAssets; - private final Artifact manifest; // The non-binary XML version of AndroidManifest.xml + // The non-binary XML version of AndroidManifest.xml + private final ProcessedAndroidManifest manifest; private final Artifact rTxt; @Nullable private final Artifact resourceProguardConfig; @Nullable private final Artifact mainDexProguardConfig; @@ -68,7 +69,7 @@ public final class ResourceApk { resourceContainer, resourceContainer.getAndroidResources(), resourceContainer.getAndroidAssets(), - resourceContainer.getManifest(), + resourceContainer.getProcessedManifest(), resourceContainer.getRTxt(), resourceProguardConfig, mainDexProguardConfig); @@ -88,7 +89,7 @@ public final class ResourceApk { resources, resources, assets, - resources.getManifest(), + resources.getProcessedManifest(), resources.getRTxt(), resourceProguardConfig, mainDexProguardConfig); @@ -103,7 +104,7 @@ public final class ResourceApk { @Nullable ValidatedAndroidData validatedResources, AndroidResources primaryResources, AndroidAssets primaryAssets, - Artifact manifest, + ProcessedAndroidManifest manifest, Artifact rTxt, @Nullable Artifact resourceProguardConfig, @Nullable Artifact mainDexProguardConfig) { @@ -155,7 +156,7 @@ public final class ResourceApk { } public Artifact getManifest() { - return manifest; + return manifest.getManifest(); } public Artifact getRTxt() { @@ -173,7 +174,7 @@ public final class ResourceApk { static ResourceApk fromTransitiveResources( ResourceDependencies resourceDeps, AssetDependencies assetDeps, - Artifact manifest, + ProcessedAndroidManifest manifest, Artifact rTxt) { return new ResourceApk( null, @@ -216,9 +217,9 @@ public final class ResourceApk { * <p>If the ResourceApk was generated from local resources, that will be the direct dependencies * and the rest will be transitive. */ - private AndroidResourcesInfo toResourceInfo(Label label) { + AndroidResourcesInfo toResourceInfo(Label label) { if (validatedResources == null) { - return resourceDeps.toInfo(label); + return resourceDeps.toInfo(label, manifest, rTxt); } return resourceDeps.toInfo(validatedResources); } 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 035d77e856..254a1d0c5d 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 @@ -69,6 +69,11 @@ public abstract class ResourceContainer implements ValidatedAndroidData { @Nullable public abstract Artifact getApk(); + @Override + public ProcessedAndroidManifest getProcessedManifest() { + return new ProcessedAndroidManifest(getManifest(), getJavaPackage(), isManifestExported()); + } + @SkylarkCallable( name = "manifest", doc = "Returns the manifest for the target.", 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 45f559eb85..09ac5afbb3 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 @@ -272,10 +272,16 @@ public final class ResourceDependencies { */ public AndroidResourcesInfo toInfo(ValidatedAndroidData newDirectResource) { if (neverlink) { - return ResourceDependencies.empty().toInfo(newDirectResource.getLabel()); + return ResourceDependencies.empty() + .toInfo( + newDirectResource.getLabel(), + newDirectResource.getProcessedManifest(), + newDirectResource.getRTxt()); } return new AndroidResourcesInfo( newDirectResource.getLabel(), + newDirectResource.getProcessedManifest(), + newDirectResource.getRTxt(), NestedSetBuilder.<ValidatedAndroidData>naiveLinkOrder() .addTransitive(transitiveResourceContainers) .addTransitive(directResourceContainers) @@ -307,12 +313,15 @@ public final class ResourceDependencies { * @param label The label of the library exporting this provider. * @return A provider with the current resources and label. */ - public AndroidResourcesInfo toInfo(Label label) { + public AndroidResourcesInfo toInfo( + Label label, ProcessedAndroidManifest manifest, Artifact rTxt) { if (neverlink) { - return ResourceDependencies.empty().toInfo(label); + return ResourceDependencies.empty().toInfo(label, manifest, rTxt); } return new AndroidResourcesInfo( label, + manifest, + rTxt, transitiveResourceContainers, directResourceContainers, transitiveResources, diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ValidatedAndroidData.java b/src/main/java/com/google/devtools/build/lib/rules/android/ValidatedAndroidData.java index 3848eb3a8d..2ab246c6b9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/ValidatedAndroidData.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/ValidatedAndroidData.java @@ -59,4 +59,7 @@ public interface ValidatedAndroidData extends CompiledMergableAndroidData { */ @Deprecated Artifact getMergedResources(); + + ProcessedAndroidManifest getProcessedManifest(); } + |