diff options
author | 2016-06-03 05:25:21 +0000 | |
---|---|---|
committer | 2016-06-03 12:53:56 +0000 | |
commit | ba323b9af3a1c6759afb9623c69a40aea001abf3 (patch) | |
tree | 9be1bef6a1a9652bb09b000feca0f85389936a8b /src/main/java | |
parent | f1be207b9e1942e4b5cd18dcff98ccb447e4eb6a (diff) |
Add resource_jar to android_studio_info.proto.
The IDE currently extracts these from the output jars by
a fragile string comparison. This will allow the IDE to
do so more robustly (eg. in case the resource jar output is renamed).
--
MOS_MIGRATED_REVID=123939803
Diffstat (limited to 'src/main/java')
4 files changed, 43 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java b/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java index 1b95ca38ef..64f9293edd 100644 --- a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java @@ -532,6 +532,15 @@ public class AndroidStudioInfoAspect extends NativeAspectClass implements Config builder.setLegacyResources(dependenciesResult.resources.toString()); } + OutputJar resourceJar = androidIdeInfoProvider.getResourceJar(); + if (resourceJar != null) { + LibraryArtifact resourceLibraryArtifact = makeLibraryArtifact(ideResolveArtifacts, + resourceJar.getClassJar(), resourceJar.getIJar(), resourceJar.getSrcJar()); + if (resourceLibraryArtifact != null) { + builder.setResourceJar(resourceLibraryArtifact); + } + } + return builder.build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java index 80606ce237..457416cc1c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java @@ -59,6 +59,7 @@ import com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts; import com.google.devtools.build.lib.rules.java.JavaCompilationHelper; import com.google.devtools.build.lib.rules.java.JavaNativeLibraryProvider; import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider; +import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar; import com.google.devtools.build.lib.rules.java.JavaRuntimeJarProvider; import com.google.devtools.build.lib.rules.java.JavaSemantics; import com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider; @@ -244,6 +245,7 @@ public class AndroidCommon { RuleContext ruleContext, AndroidSemantics semantics, AndroidIdlHelper idlHelper, + OutputJar resourceJar, ResourceApk resourceApk, Artifact zipAlignedApk, Iterable<Artifact> apksUnderTest) { @@ -251,6 +253,7 @@ public class AndroidCommon { new AndroidIdeInfoProvider.Builder() .setIdlClassJar(idlHelper.getIdlClassJar()) .setIdlSourceJar(idlHelper.getIdlSourceJar()) + .setResourceJar(resourceJar) .addIdlParcelables(idlHelper.getIdlParcelables()) .addIdlSrcs(idlHelper.getIdlSources()) .addIdlGeneratedJavaFiles(idlHelper.getIdlGeneratedJavaSources()) @@ -660,8 +663,10 @@ public class AndroidCommon { JavaRuleOutputJarsProvider.Builder outputJarsBuilder = JavaRuleOutputJarsProvider.builder() .addOutputJar(classJar, iJar, srcJar) .setJdeps(outputDepsProto); + OutputJar resourceJar = null; if (resourceClassJar != null && resourceIJar != null && resourceSourceJar != null) { - outputJarsBuilder.addOutputJar(resourceClassJar, resourceIJar, resourceSourceJar); + resourceJar = new OutputJar(resourceClassJar, resourceIJar, resourceSourceJar); + outputJarsBuilder.addOutputJar(resourceJar); } return builder @@ -678,6 +683,7 @@ public class AndroidCommon { ruleContext, androidSemantics, idlHelper, + resourceJar, resourceApk, zipAlignedApk, apksUnderTest)) diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidIdeInfoProvider.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidIdeInfoProvider.java index d39365a17a..39f8ba9f7a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidIdeInfoProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidIdeInfoProvider.java @@ -22,6 +22,7 @@ import com.google.devtools.build.lib.actions.Root; import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.packages.AttributeMap; +import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.vfs.PathFragment; @@ -128,6 +129,7 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { private Artifact apk = null; private Artifact idlClassJar = null; private Artifact idlSourceJar = null; + private OutputJar resourceJar = null; private String javaPackage = null; private final Set<SourceDirectory> resourceDirs = new LinkedHashSet<>(); private final Set<SourceDirectory> assetDirs = new LinkedHashSet<>(); @@ -145,6 +147,7 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { apk, idlClassJar, idlSourceJar, + resourceJar, definesAndroidResources, ImmutableList.copyOf(assetDirs), ImmutableList.copyOf(resourceDirs), @@ -194,6 +197,11 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { return this; } + public Builder setResourceJar(OutputJar resourceJar) { + this.resourceJar = resourceJar; + return this; + } + /** * Add "idl_srcs" contents. */ @@ -280,6 +288,7 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { private final Artifact signedApk; @Nullable private final Artifact idlClassJar; @Nullable private final Artifact idlSourceJar; + @Nullable private final OutputJar resourceJar; private final ImmutableCollection<SourceDirectory> resourceDirs; private final boolean definesAndroidResources; private final ImmutableCollection<SourceDirectory> assetDirs; @@ -295,6 +304,7 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { @Nullable Artifact signedApk, @Nullable Artifact idlClassJar, @Nullable Artifact idlSourceJar, + @Nullable OutputJar resourceJar, boolean definesAndroidResources, ImmutableCollection<SourceDirectory> assetDirs, ImmutableCollection<SourceDirectory> resourceDirs, @@ -308,6 +318,7 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { this.signedApk = signedApk; this.idlClassJar = idlClassJar; this.idlSourceJar = idlSourceJar; + this.resourceJar = resourceJar; this.definesAndroidResources = definesAndroidResources; this.assetDirs = assetDirs; this.resourceDirs = resourceDirs; @@ -358,6 +369,11 @@ public final class AndroidIdeInfoProvider implements TransitiveInfoProvider { return idlSourceJar; } + @Nullable + public OutputJar getResourceJar() { + return resourceJar; + } + /** A list of the direct Resource directories. */ public ImmutableCollection<SourceDirectory> getResourceDirs() { return resourceDirs; 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 a8b81ddbaf..e64bc92f61 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,6 +117,17 @@ public class AndroidSkylarkApiProvider extends SkylarkApiProvider { return collectDirectArtifacts(ResourceType.RESOURCES); } + @SkylarkCallable( + name = "resource_jar", + structField = true, + allowReturnNones = true, + doc = "Returns a jar file for classes generated from resources." + ) + @Nullable + public JavaRuleOutputJarsProvider.OutputJar getResourceJar() { + return getIdeInfoProvider().getResourceJar(); + } + private NestedSet<Artifact> collectDirectArtifacts(final ResourceType resources) { AndroidResourcesProvider provider = getInfo().getProvider(AndroidResourcesProvider.class); if (provider == null) { |