aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar asteinb <asteinb@google.com>2018-05-08 13:58:47 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-08 14:01:11 -0700
commitfbdf70e6cc1a406f113e802abd24b3da25154435 (patch)
tree9c8e64acfc457582d7dc9979cc191065b376e204 /src/main/java/com
parente3784eccef5ff6b1db35186e763a2b3d1dd3ef54 (diff)
Expose R.class as a JavaInfo
The R.class file, when available, is used in Java compilation. So it should be exposed in its own provider as an output of resource processing. The R.class file is marked as Neverlink and compiletime-only to ensure it doesn't get inherited. Change resource processing to return a SkylarkDict of providers. That way, callers can easily get the provider they want, or use values() to get all the providers. Stop exposing R.class in AndroidResourcesInfo since we're exposing it in an easier-to-consume way now. Will update other methods that return multiple providers to do the same in future reviews. RELNOTES: none PiperOrigin-RevId: 195871587
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesInfo.java33
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkData.java49
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceDependencies.java9
4 files changed, 42 insertions, 51 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 f08b2ceb91..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
@@ -22,7 +22,6 @@ 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;
/** A provider that supplies ResourceContainers from its transitive closure. */
@SkylarkModule(
@@ -54,23 +53,6 @@ public class AndroidResourcesInfo extends NativeInfo {
private final Artifact rTxt;
/*
- * An R.class file for this target that can be used to build Java source.
- *
- * This class file should not be used for any targets besides the one that exposes this provider
- * instance - even similar targets can have very different R.class files. In particular, final
- * R.class files (for android_binary and similar rules) are generated very differently than
- * R.class files for android_library - the latter are meant to be thrown away after building local
- * Java classes.
- *
- * An R.class file is exposed rather than an R.java file because generating the R.class from the
- * R.txt file is quicker than compiling the R.java file.
- *
- * An R.class file will not be produced for android_library targets that do not specify a manifest
- * or resource files.
- */
- @Nullable private final Artifact rClassJar;
-
- /*
* Transitive information used for resource processing
*/
@@ -89,7 +71,6 @@ public class AndroidResourcesInfo extends NativeInfo {
Label label,
ProcessedAndroidManifest manifest,
Artifact rTxt,
- @Nullable Artifact rClassJar,
NestedSet<ValidatedAndroidData> transitiveAndroidResources,
NestedSet<ValidatedAndroidData> directAndroidResources,
NestedSet<Artifact> transitiveResources,
@@ -104,7 +85,6 @@ public class AndroidResourcesInfo extends NativeInfo {
this.label = label;
this.manifest = manifest;
this.rTxt = rTxt;
- this.rClassJar = rClassJar;
this.transitiveAndroidResources = transitiveAndroidResources;
this.directAndroidResources = directAndroidResources;
this.transitiveResources = transitiveResources;
@@ -131,19 +111,6 @@ public class AndroidResourcesInfo extends NativeInfo {
return rTxt;
}
- @SkylarkCallable(
- name = "r_class_jar",
- structField = true,
- allowReturnNones = true,
- doc =
- "Returns a JAR of R.class files for this target, for use in compiling this target's Java"
- + " code. This JAR is only accurate for this target, and should not be used in any"
- + " way for other targets. The JAR will not be available for android_library targets"
- + " that do not specify resources or manifest.")
- public Artifact getRClassJar() {
- return rClassJar;
- }
-
/** 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/AndroidSkylarkData.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkData.java
index 38238f836d..d0c3819e41 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
@@ -21,13 +21,18 @@ import com.google.devtools.build.lib.analysis.skylark.SkylarkRuleContext;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.events.Location;
+import com.google.devtools.build.lib.packages.NativeInfo;
+import com.google.devtools.build.lib.packages.NativeProvider;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.rules.android.AndroidLibraryAarInfo.Aar;
+import com.google.devtools.build.lib.rules.java.JavaCompilationInfoProvider;
+import com.google.devtools.build.lib.rules.java.JavaInfo;
import com.google.devtools.build.lib.skylarkinterface.Param;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Runtime;
+import com.google.devtools.build.lib.syntax.SkylarkDict;
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.List;
@@ -312,12 +317,15 @@ public class AndroidSkylarkData {
+ " targets that depend on this one."),
},
doc =
- "Merges this target's resources together with resources inherited from dependencies. The"
- + " passed manifest provider is used to get Android package information and to"
- + " validate that all resources it refers to are available. Note that this method"
- + " might do additional processing to this manifest, so in the future, you may want"
- + " to use the manifest contained in this method's output instead of this one.")
- public AndroidResourcesInfo mergeResources(
+ "Merges this target's resources together with resources inherited from dependencies."
+ + " Returns a dict of provider type to actual info, with elements for"
+ + " AndroidResourcesInfo (various resource information) and JavaInfo (wrapping the"
+ + " R.class jar, for use in Java compilation). The passed manifest provider is used"
+ + " to get Android package information and to validate that all resources it refers"
+ + " to are available. Note that this method might do additional processing to this"
+ + " manifest, so in the future, you may want to use the manifest contained in this"
+ + " method's output instead of this one.")
+ public SkylarkDict<NativeProvider<?>, NativeInfo> mergeResources(
SkylarkRuleContext ctx,
AndroidManifestInfo manifest,
SkylarkList<ConfiguredTarget> resources,
@@ -333,11 +341,30 @@ public class AndroidSkylarkData {
.collect(ImmutableList.toImmutableList());
try {
- return AndroidResources.from(ctx.getRuleContext(), fileProviders, "resources")
- .parse(ctx.getRuleContext(), manifest.asStampedManifest())
- .merge(ctx.getRuleContext(), ResourceDependencies.fromProviders(deps, neverlink))
- .validate(ctx.getRuleContext())
- .toProvider();
+ ValidatedAndroidResources validated =
+ AndroidResources.from(ctx.getRuleContext(), fileProviders, "resources")
+ .parse(ctx.getRuleContext(), manifest.asStampedManifest())
+ .merge(ctx.getRuleContext(), ResourceDependencies.fromProviders(deps, neverlink))
+ .validate(ctx.getRuleContext());
+
+ JavaInfo javaInfo =
+ JavaInfo.Builder.create()
+ .setNeverlink(true)
+ .addProvider(
+ JavaCompilationInfoProvider.class,
+ new JavaCompilationInfoProvider.Builder()
+ .setCompilationClasspath(
+ NestedSetBuilder.create(Order.NAIVE_LINK_ORDER, validated.getClassJar()))
+ .build())
+ .build();
+
+ return SkylarkDict.of(
+ /* env = */ null,
+ AndroidResourcesInfo.PROVIDER,
+ validated.toProvider(),
+ JavaInfo.PROVIDER,
+ javaInfo);
+
} catch (RuleErrorException e) {
throw new EvalException(Location.BUILTIN, e);
}
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 ffef2d5d0e..324766d323 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
@@ -223,7 +223,7 @@ public final class ResourceApk {
*/
AndroidResourcesInfo toResourceInfo(Label label) {
if (validatedResources == null) {
- return resourceDeps.toInfo(label, manifest, rTxt, resourceJavaClassJar);
+ return resourceDeps.toInfo(label, manifest, rTxt);
}
return resourceDeps.toInfo(validatedResources);
}
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 1631db5992..0a62aea8d2 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
@@ -254,14 +254,12 @@ public final class ResourceDependencies {
.toInfo(
newDirectResource.getLabel(),
newDirectResource.getProcessedManifest(),
- newDirectResource.getRTxt(),
- newDirectResource.getJavaClassJar());
+ newDirectResource.getRTxt());
}
return new AndroidResourcesInfo(
newDirectResource.getLabel(),
newDirectResource.getProcessedManifest(),
newDirectResource.getRTxt(),
- newDirectResource.getJavaClassJar(),
NestedSetBuilder.<ValidatedAndroidData>naiveLinkOrder()
.addTransitive(transitiveResourceContainers)
.addTransitive(directResourceContainers)
@@ -294,15 +292,14 @@ public final class ResourceDependencies {
* @return A provider with the current resources and label.
*/
public AndroidResourcesInfo toInfo(
- Label label, ProcessedAndroidManifest manifest, Artifact rTxt, @Nullable Artifact rClassJar) {
+ Label label, ProcessedAndroidManifest manifest, Artifact rTxt) {
if (neverlink) {
- return ResourceDependencies.empty().toInfo(label, manifest, rTxt, rClassJar);
+ return ResourceDependencies.empty().toInfo(label, manifest, rTxt);
}
return new AndroidResourcesInfo(
label,
manifest,
rTxt,
- rClassJar,
transitiveResourceContainers,
directResourceContainers,
transitiveResources,