aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar asteinb <asteinb@google.com>2018-05-03 07:22:56 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-03 07:24:48 -0700
commitffb0913d9f2bd210717bccb9bdc00b39a6c1ba5f (patch)
tree4e7e6cc38a06f5e5e19f4d17822c7a681db6043a /src
parent0c12603bedd4a270094137269b910a8587d3f93c (diff)
Expose asset merging result in AndroidAssetsInfo to Skylark
By default, in decoupled asset processing, merging will not be run. Expose an artifact so we can force validation as needed. RELNOTES: none PiperOrigin-RevId: 195248517
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidAssetsInfo.java36
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AssetDependencies.java15
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/MergedAndroidAssets.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java5
4 files changed, 51 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidAssetsInfo.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidAssetsInfo.java
index 5431c00006..80e4f6661a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidAssetsInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidAssetsInfo.java
@@ -20,8 +20,16 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.packages.NativeInfo;
import com.google.devtools.build.lib.packages.NativeProvider;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import javax.annotation.Nullable;
/** Provides information about transitive Android assets. */
+@SkylarkModule(
+ name = "AndroidAssetsInfo",
+ doc = "Information about the Android assets provided by a rule.",
+ category = SkylarkModuleCategory.PROVIDER)
public class AndroidAssetsInfo extends NativeInfo {
private static final String SKYLARK_NAME = "AndroidAssetsInfo";
@@ -30,6 +38,7 @@ public class AndroidAssetsInfo extends NativeInfo {
new NativeProvider<AndroidAssetsInfo>(AndroidAssetsInfo.class, SKYLARK_NAME) {};
private final Label label;
+ @Nullable private final Artifact validationResult;
private final NestedSet<ParsedAndroidAssets> directParsedAssets;
private final NestedSet<ParsedAndroidAssets> transitiveParsedAssets;
private final NestedSet<Artifact> transitiveAssets;
@@ -38,6 +47,7 @@ public class AndroidAssetsInfo extends NativeInfo {
static AndroidAssetsInfo empty(Label label) {
return new AndroidAssetsInfo(
label,
+ null,
NestedSetBuilder.emptySet(Order.NAIVE_LINK_ORDER),
NestedSetBuilder.emptySet(Order.NAIVE_LINK_ORDER),
NestedSetBuilder.emptySet(Order.NAIVE_LINK_ORDER),
@@ -46,22 +56,30 @@ public class AndroidAssetsInfo extends NativeInfo {
public static AndroidAssetsInfo of(
Label label,
+ @Nullable Artifact validationResult,
NestedSet<ParsedAndroidAssets> directParsedAssets,
NestedSet<ParsedAndroidAssets> transitiveParsedAssets,
NestedSet<Artifact> transitiveAssets,
NestedSet<Artifact> transitiveSymbols) {
return new AndroidAssetsInfo(
- label, directParsedAssets, transitiveParsedAssets, transitiveAssets, transitiveSymbols);
+ label,
+ validationResult,
+ directParsedAssets,
+ transitiveParsedAssets,
+ transitiveAssets,
+ transitiveSymbols);
}
private AndroidAssetsInfo(
Label label,
+ @Nullable Artifact validationResult,
NestedSet<ParsedAndroidAssets> directParsedAssets,
NestedSet<ParsedAndroidAssets> transitiveParsedAssets,
NestedSet<Artifact> transitiveAssets,
NestedSet<Artifact> transitiveSymbols) {
super(PROVIDER);
this.label = label;
+ this.validationResult = validationResult;
this.directParsedAssets = directParsedAssets;
this.transitiveParsedAssets = transitiveParsedAssets;
this.transitiveAssets = transitiveAssets;
@@ -72,6 +90,22 @@ public class AndroidAssetsInfo extends NativeInfo {
return label;
}
+ @SkylarkCallable(
+ name = "validation_result",
+ structField = true,
+ allowReturnNones = true,
+ doc =
+ "If not None, represents the output of asset merging and validation for this target. The"
+ + " action to merge and validate assets is not run be default; to force it, add this"
+ + " artifact to your target's outputs. The validation action is somewhat expensive -"
+ + " in native code, this artifact is added to the top-level output group (so"
+ + " validation is only done if the target is requested on the command line). The"
+ + " contents of this artifact are subject to change and should not be relied upon.")
+ @Nullable
+ public Artifact getValidationResult() {
+ return validationResult;
+ }
+
public NestedSet<ParsedAndroidAssets> getDirectParsedAssets() {
return directParsedAssets;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AssetDependencies.java b/src/main/java/com/google/devtools/build/lib/rules/android/AssetDependencies.java
index c2b68977ba..ef088993a8 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AssetDependencies.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AssetDependencies.java
@@ -90,14 +90,18 @@ public class AssetDependencies {
}
/** Creates a new AndroidAssetInfo using the passed assets as the direct dependency. */
- public AndroidAssetsInfo toInfo(ParsedAndroidAssets assets) {
+ public AndroidAssetsInfo toInfo(MergedAndroidAssets assets) {
if (neverlink) {
return AndroidAssetsInfo.empty(assets.getLabel());
}
+ // Create a new object to avoid passing around unwanted merge information to the provider
+ ParsedAndroidAssets parsedAssets = new ParsedAndroidAssets(assets);
+
return AndroidAssetsInfo.of(
assets.getLabel(),
- NestedSetBuilder.create(Order.NAIVE_LINK_ORDER, assets),
+ assets.getMergedAssets(),
+ NestedSetBuilder.create(Order.NAIVE_LINK_ORDER, parsedAssets),
NestedSetBuilder.<ParsedAndroidAssets>naiveLinkOrder()
.addTransitive(transitiveParsedAssets)
.addTransitive(directParsedAssets)
@@ -119,7 +123,12 @@ public class AssetDependencies {
}
return AndroidAssetsInfo.of(
- label, directParsedAssets, transitiveParsedAssets, transitiveAssets, transitiveSymbols);
+ label,
+ null,
+ directParsedAssets,
+ transitiveParsedAssets,
+ transitiveAssets,
+ transitiveSymbols);
}
public NestedSet<ParsedAndroidAssets> getDirectParsedAssets() {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/MergedAndroidAssets.java b/src/main/java/com/google/devtools/build/lib/rules/android/MergedAndroidAssets.java
index 37a5c849e0..608d56be38 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/MergedAndroidAssets.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/MergedAndroidAssets.java
@@ -79,9 +79,7 @@ public class MergedAndroidAssets extends ParsedAndroidAssets {
}
AndroidAssetsInfo toProvider() {
- // Create a new object to avoid passing around unwanted merge information to the provider
- ParsedAndroidAssets parsed = new ParsedAndroidAssets(this);
- return assetDependencies.toInfo(parsed);
+ return assetDependencies.toInfo(this);
}
public Artifact getMergedAssets() {
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 11c63df827..9466e5fd01 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
@@ -236,11 +236,12 @@ public final class ResourceApk {
// that only properly merged resources are passed into this object.
if (primaryAssets instanceof MergedAndroidAssets) {
MergedAndroidAssets merged = (MergedAndroidAssets) primaryAssets;
- builder.addNativeDeclaredProvider(merged.toProvider());
+ AndroidAssetsInfo assetsInfo = merged.toProvider();
+ builder.addNativeDeclaredProvider(assetsInfo);
// Asset merging output isn't consumed by anything. Require it to be run by top-level targets
// so we can validate there are no asset merging conflicts.
- builder.addOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL, merged.getMergedAssets());
+ builder.addOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL, assetsInfo.getValidationResult());
} else if (primaryAssets == null) {
builder.addNativeDeclaredProvider(assetDeps.toInfo(label));