diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
7 files changed, 72 insertions, 110 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java index 30f20c3aaa..4d7d664550 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java @@ -532,7 +532,6 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { androidCommon.addTransitiveInfoProviders( builder, - androidSemantics, null /* aar */, resourceApk, zipAlignedApk, 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 c6292a623f..22ae229b8e 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 @@ -44,7 +44,6 @@ import com.google.devtools.build.lib.packages.NativeProvider; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; import com.google.devtools.build.lib.packages.TriState; -import com.google.devtools.build.lib.rules.android.AndroidConfiguration.AndroidAaptVersion; import com.google.devtools.build.lib.rules.cpp.CcLinkParams; import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo; import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore; @@ -131,7 +130,6 @@ public class AndroidCommon { private Artifact srcJar; private Artifact genClassJar; private Artifact genSourceJar; - private Artifact resourceClassJar; private Artifact resourceSourceJar; private Artifact outputDepsProto; private GeneratedExtensionRegistryProvider generatedExtensionRegistryProvider; @@ -399,68 +397,43 @@ public class AndroidCommon { Artifact resourcesJar, JavaCompilationArtifacts.Builder artifactsBuilder, JavaTargetAttributes.Builder attributes, - NestedSetBuilder<Artifact> filesBuilder, - boolean useRClassGenerator) + NestedSetBuilder<Artifact> filesBuilder) throws InterruptedException, RuleErrorException { - compileResourceJar(javaSemantics, resourceApk, resourcesJar, useRClassGenerator); + + // The resource class JAR should already have been generated. + Preconditions.checkArgument( + resourceApk + .getResourceJavaClassJar() + .equals( + ruleContext.getImplicitOutputArtifact( + AndroidRuleClasses.ANDROID_RESOURCES_CLASS_JAR))); + + packResourceSourceJar(javaSemantics, resourcesJar); + // Add the compiled resource jar to the classpath of the main compilation. - attributes.addDirectJars(NestedSetBuilder.create(Order.STABLE_ORDER, resourceClassJar)); + attributes.addDirectJars( + NestedSetBuilder.create(Order.STABLE_ORDER, resourceApk.getResourceJavaClassJar())); // Add the compiled resource jar to the classpath of consuming targets. // We don't actually use the ijar. That is almost the same as the resource class jar // except for <clinit>, but it takes time to build and waiting for that to build would // just delay building the rest of the library. - artifactsBuilder.addCompileTimeJarAsFullJar(resourceClassJar); + artifactsBuilder.addCompileTimeJarAsFullJar(resourceApk.getResourceJavaClassJar()); // Add the compiled resource jar as a declared output of the rule. filesBuilder.add(resourceSourceJar); - filesBuilder.add(resourceClassJar); + filesBuilder.add(resourceApk.getResourceJavaClassJar()); } - private void compileResourceJar( - JavaSemantics javaSemantics, - ResourceApk resourceApk, - Artifact resourcesJar, - boolean useRClassGenerator) - throws InterruptedException, RuleErrorException { + private void packResourceSourceJar(JavaSemantics javaSemantics, Artifact resourcesJar) + throws InterruptedException { + resourceSourceJar = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_SOURCE_JAR); - resourceClassJar = - ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_CLASS_JAR); - JavaCompilationArtifacts.Builder javaArtifactsBuilder = new JavaCompilationArtifacts.Builder(); JavaTargetAttributes.Builder javacAttributes = new JavaTargetAttributes.Builder(javaSemantics).addSourceJar(resourcesJar); JavaCompilationHelper javacHelper = new JavaCompilationHelper(ruleContext, javaSemantics, getJavacOpts(), javacAttributes); - // Only build the class jar if it's not already generated internally by resource processing. - if (resourceApk.getResourceJavaClassJar() == null) { - if (useRClassGenerator) { - new RClassGeneratorActionBuilder(ruleContext) - .targetAaptVersion(AndroidAaptVersion.chooseTargetAaptVersion(ruleContext)) - .withPrimary(resourceApk.getPrimaryResources()) - .withDependencies(resourceApk.getResourceDependencies()) - .setClassJarOut(resourceClassJar) - .build(); - } else { - Artifact outputDepsProto = - javacHelper.createOutputDepsProtoArtifact(resourceClassJar, javaArtifactsBuilder); - javacHelper.createCompileActionWithInstrumentation( - resourceClassJar, - null /* manifestProtoOutput */, - null /* genSourceJar */, - outputDepsProto, - javaArtifactsBuilder, - /* nativeHeaderOutput= */ null); - } - } else { - // Otherwise, it should have been the AndroidRuleClasses.ANDROID_RESOURCES_CLASS_JAR. - Preconditions.checkArgument( - resourceApk - .getResourceJavaClassJar() - .equals( - ruleContext.getImplicitOutputArtifact( - AndroidRuleClasses.ANDROID_RESOURCES_CLASS_JAR))); - } javacHelper.createSourceJarAction(resourceSourceJar, null); } @@ -516,21 +489,13 @@ public class AndroidCommon { Artifact resourcesJar = resourceApk.getResourceJavaSrcJar(); if (resourcesJar != null) { filesBuilder.add(resourcesJar); - // Use a fast-path R class generator for android_binary, where there is a bottleneck. - boolean useRClassGenerator = isBinary; compileResources( - javaSemantics, - resourceApk, - resourcesJar, - artifactsBuilder, - attributes, - filesBuilder, - useRClassGenerator); + javaSemantics, resourceApk, resourcesJar, artifactsBuilder, attributes, filesBuilder); // Combined resource constants needs to come even before our own classes that may contain // local resource constants. - artifactsBuilder.addRuntimeJar(resourceClassJar); - jarsProducedForRuntime.add(resourceClassJar); + artifactsBuilder.addRuntimeJar(resourceApk.getResourceJavaClassJar()); + jarsProducedForRuntime.add(resourceApk.getResourceJavaClassJar()); } JavaCompilationHelper helper = initAttributes(attributes, javaSemantics); @@ -693,7 +658,6 @@ public class AndroidCommon { public RuleConfiguredTargetBuilder addTransitiveInfoProviders( RuleConfiguredTargetBuilder builder, - AndroidSemantics androidSemantics, Artifact aar, ResourceApk resourceApk, Artifact zipAlignedApk, @@ -707,8 +671,10 @@ public class AndroidCommon { builder.add(GeneratedExtensionRegistryProvider.class, generatedExtensionRegistryProvider); } OutputJar resourceJar = null; - if (resourceClassJar != null && resourceSourceJar != null) { - resourceJar = new OutputJar(resourceClassJar, null, ImmutableList.of(resourceSourceJar)); + if (resourceApk.getResourceJavaClassJar() != null && resourceSourceJar != null) { + resourceJar = + new OutputJar( + resourceApk.getResourceJavaClassJar(), null, ImmutableList.of(resourceSourceJar)); javaRuleOutputJarsProviderBuilder.addOutputJar(resourceJar); } @@ -806,10 +772,6 @@ public class AndroidCommon { return javaCommon.getJavaCompilationArtifacts().getRuntimeJars(); } - public Artifact getResourceClassJar() { - return resourceClassJar; - } - /** * Returns Jars produced by this rule that may go into the runtime classpath. By contrast {@link * #getRuntimeJars()} returns the complete runtime classpath needed by this rule, including diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java index 9c899b1061..0be002e9b8 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java @@ -247,7 +247,6 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory { RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext); androidCommon.addTransitiveInfoProviders( builder, - androidSemantics, aarOut, resourceApk, null, @@ -257,8 +256,8 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory { androidCommon.isNeverLink()); NestedSetBuilder<Artifact> transitiveResourcesJars = collectTransitiveResourceJars(ruleContext); - if (androidCommon.getResourceClassJar() != null) { - transitiveResourcesJars.add(androidCommon.getResourceClassJar()); + if (resourceApk.getResourceJavaClassJar() != null) { + transitiveResourcesJars.add(resourceApk.getResourceJavaClassJar()); } builder diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java index ca7f4b4943..d3e3793261 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.rules.android; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; @@ -36,7 +35,6 @@ 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; import com.google.devtools.build.lib.packages.BuildType; -import com.google.devtools.build.lib.rules.android.AndroidConfiguration.AndroidAaptVersion; import com.google.devtools.build.lib.rules.java.ClasspathConfiguredFragment; import com.google.devtools.build.lib.rules.java.JavaCommon; import com.google.devtools.build.lib.rules.java.JavaCompilationArgs; @@ -102,8 +100,6 @@ public abstract class AndroidLocalTestBase implements RuleConfiguredTargetFactor String resourcesLocation = resourcesZip.getRunfilesPathString(); // Create the final merged R class - Artifact resourcesClassJar = - ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_CLASS_JAR); ResourceApk resourceApk = applicationManifest.packBinaryWithDataAndResources( ruleContext, @@ -121,8 +117,7 @@ public abstract class AndroidLocalTestBase implements RuleConfiguredTargetFactor DataBinding.isEnabled(ruleContext) ? DataBinding.getLayoutInfoFile(ruleContext) : null, null, /* featureOfArtifact */ null /* featureAfterArtifact */); - compileResourceJar(ruleContext, resourceApk, resourcesClassJar); - attributesBuilder.addRuntimeClassPathEntry(resourcesClassJar); + attributesBuilder.addRuntimeClassPathEntry(resourceApk.getResourceJavaClassJar()); // Exclude the Rs from the library from the runtime classpath. NestedSet<Artifact> excludedRuntimeArtifacts = getLibraryResourceJars(ruleContext); @@ -299,7 +294,7 @@ public abstract class AndroidLocalTestBase implements RuleConfiguredTargetFactor javaCommon, filesToBuild, manifest, - resourcesClassJar, + resourceApk.getResourceJavaClassJar(), resourcesZip, generateBinaryResources ? resourceApk : null); @@ -364,22 +359,6 @@ public abstract class AndroidLocalTestBase implements RuleConfiguredTargetFactor .build(); } - /** Creates the final merged R class with all of the transitive resources. */ - private void compileResourceJar( - RuleContext ruleContext, ResourceApk resourceApk, Artifact resourceClassJar) - throws InterruptedException, RuleErrorException { - if (resourceApk.getResourceJavaClassJar() == null) { - new RClassGeneratorActionBuilder(ruleContext) - .targetAaptVersion(AndroidAaptVersion.chooseTargetAaptVersion(ruleContext)) - .withPrimary(resourceApk.getPrimaryResources()) - .withDependencies(resourceApk.getResourceDependencies()) - .setClassJarOut(resourceClassJar) - .build(); - } else { - Preconditions.checkArgument(resourceApk.getResourceJavaClassJar().equals(resourceClassJar)); - } - } - /** * Returns a merged {@link ApplicationManifest} for the rule. The final merged manifest will be * merged into the manifest provided on the rule, or into a placeholder manifest if one is not diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java index 9ce263170d..8b6775b44b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java @@ -348,7 +348,16 @@ public final class ApplicationManifest { } ResourceContainer processed = builder.build(ruleContext); - return ResourceApk.of(processed, resourceDeps, proguardCfg, mainDexProguardCfg); + ResourceContainer finalContainer = + new RClassGeneratorActionBuilder(ruleContext) + .targetAaptVersion(AndroidAaptVersion.chooseTargetAaptVersion(ruleContext)) + .withDependencies(resourceDeps) + .setClassJarOut( + ruleContext.getImplicitOutputArtifact( + AndroidRuleClasses.ANDROID_RESOURCES_CLASS_JAR)) + .build(processed); + + return ResourceApk.of(finalContainer, resourceDeps, proguardCfg, mainDexProguardCfg); } /** Packages up the manifest with resource and assets from the LocalResourceContainer. */ @@ -467,6 +476,8 @@ public final class ApplicationManifest { .setPackageUnderTest(null) .build(ruleContext); + // Intentionally skip building an R class JAR - incremental binaries handle this separately. + return ResourceApk.of(processed, resourceDeps, proguardCfg, null); } @@ -548,7 +559,16 @@ public final class ApplicationManifest { .setSourceJarOut(resourceContainer.getJavaSourceJar()) .build(ruleContext); - return ResourceApk.of(processed, resourceDeps, proguardCfg, mainDexProguardCfg); + ResourceContainer finalContainer = + new RClassGeneratorActionBuilder(ruleContext) + .targetAaptVersion(AndroidAaptVersion.chooseTargetAaptVersion(ruleContext)) + .withDependencies(resourceDeps) + .setClassJarOut( + ruleContext.getImplicitOutputArtifact( + AndroidRuleClasses.ANDROID_RESOURCES_CLASS_JAR)) + .build(processed); + + return ResourceApk.of(finalContainer, resourceDeps, proguardCfg, mainDexProguardCfg); } public ResourceApk packLibraryWithDataAndResources( 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 f862e7f339..3aea312672 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 @@ -32,4 +32,11 @@ public class ProcessedAndroidManifest extends StampedAndroidManifest { 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 9c68d10f85..975fbd5be6 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 @@ -38,7 +38,6 @@ import javax.annotation.Nullable; public class RClassGeneratorActionBuilder { private final RuleContext ruleContext; - private ResourceContainer primary; private ResourceDependencies dependencies; private Artifact classJarOut; @@ -50,11 +49,6 @@ public class RClassGeneratorActionBuilder { this.ruleContext = ruleContext; } - public RClassGeneratorActionBuilder withPrimary(ResourceContainer primary) { - this.primary = primary; - return this; - } - public RClassGeneratorActionBuilder withDependencies(ResourceDependencies resourceDeps) { this.dependencies = resourceDeps; return this; @@ -70,7 +64,13 @@ public class RClassGeneratorActionBuilder { return this; } - public void build() { + public ResourceContainer build(ResourceContainer primary) { + build(primary.getRTxt(), ProcessedAndroidManifest.from(primary)); + + return primary.toBuilder().setJavaClassJar(classJarOut).build(); + } + + private void build(Artifact rTxt, ProcessedAndroidManifest manifest) { CustomCommandLine.Builder builder = new CustomCommandLine.Builder(); // Set the busybox tool. @@ -84,16 +84,12 @@ public class RClassGeneratorActionBuilder { .getRunfilesArtifacts()); List<Artifact> outs = new ArrayList<>(); - if (primary.getRTxt() != null) { - builder.addExecPath("--primaryRTxt", primary.getRTxt()); - inputs.add(primary.getRTxt()); - } - if (primary.getManifest() != null) { - builder.addExecPath("--primaryManifest", primary.getManifest()); - inputs.add(primary.getManifest()); - } - if (!Strings.isNullOrEmpty(primary.getJavaPackage())) { - builder.add("--packageForR", primary.getJavaPackage()); + builder.addExecPath("--primaryRTxt", rTxt); + inputs.add(rTxt); + builder.addExecPath("--primaryManifest", manifest.getManifest()); + inputs.add(manifest.getManifest()); + if (!Strings.isNullOrEmpty(manifest.getPackage())) { + builder.add("--packageForR", manifest.getPackage()); } if (dependencies != null) { // TODO(corysmith): Remove NestedSet as we are already flattening it. |