diff options
author | 2017-01-25 02:15:44 +0000 | |
---|---|---|
committer | 2017-01-25 10:11:20 +0000 | |
commit | a385f73a07dd100d2a07327fc69f73add9db47d5 (patch) | |
tree | b0eebc1435e5aa2459bbf01d7748acafd8839517 /src/main/java/com/google/devtools/build/lib/rules/java/ProguardHelper.java | |
parent | 78cae6dd66b4c7ce348039c8956a6b2b758e1307 (diff) |
Move rexed proguard map to top level blaze-bin directory when rex enabled
--
PiperOrigin-RevId: 145495392
MOS_MIGRATED_REVID=145495392
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/java/ProguardHelper.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/java/ProguardHelper.java | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/ProguardHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/ProguardHelper.java index 13575580e9..4447cadf63 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/ProguardHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/ProguardHelper.java @@ -108,10 +108,13 @@ public abstract class ProguardHelper { /** Adds the output artifacts to the given set builder. */ public void addAllToSet(NestedSetBuilder<Artifact> filesBuilder) { + addAllToSet(filesBuilder, null); + } + + /** Adds the output artifacts to the given set builder. If the progaurd map was updated + * then add the updated map instead of the original proguard output map */ + public void addAllToSet(NestedSetBuilder<Artifact> filesBuilder, Artifact finalProguardMap) { filesBuilder.add(outputJar); - if (mapping != null) { - filesBuilder.add(mapping); - } if (protoMapping != null) { filesBuilder.add(protoMapping); } @@ -127,6 +130,11 @@ public abstract class ProguardHelper { if (config != null) { filesBuilder.add(config); } + if (finalProguardMap != null) { + filesBuilder.add(finalProguardMap); + } else if (mapping != null) { + filesBuilder.add(mapping); + } } } @@ -167,6 +175,14 @@ public abstract class ProguardHelper { collectProguardSpecs(ruleContext, bootclasspath, mainClassName); Artifact singleJar = ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_BINARY_MERGED_JAR); + + // TODO(bazel-team): Verify that proguard spec files don't contain -printmapping directions + // which this -printmapping command line flag will override. + Artifact proguardOutputMap = null; + if (genProguardMapping(ruleContext.attributes()) || optMode.alwaysGenerateOutputMapping()) { + proguardOutputMap = + ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_BINARY_PROGUARD_MAP); + } return createProguardAction( ruleContext, proguard, @@ -178,7 +194,8 @@ public abstract class ProguardHelper { bootclasspath, deployJar, semantics, - /* optimizationPases */ 3); + /* optimizationPases */ 3, + proguardOutputMap); } private ImmutableList<Artifact> collectProguardSpecs( @@ -298,20 +315,18 @@ public abstract class ProguardHelper { @Nullable Artifact proguardSeeds, @Nullable Artifact proguardUsage, RuleContext ruleContext, - JavaSemantics semantics) + JavaSemantics semantics, + @Nullable Artifact proguardOutputMap) throws InterruptedException { JavaOptimizationMode optMode = getJavaOptimizationMode(ruleContext); boolean mappingRequested = genProguardMapping(ruleContext.attributes()); - Artifact proguardOutputMap = null; Artifact proguardOutputProtoMap = null; Artifact proguardConstantStringMap = null; if (mappingRequested || optMode.alwaysGenerateOutputMapping()) { - // TODO(bazel-team): Verify that proguard spec files don't contain -printmapping directions - // which this -printmapping command line flag will override. - proguardOutputMap = - ruleContext.getImplicitOutputArtifact(JavaSemantics.JAVA_BINARY_PROGUARD_MAP); + // TODO(bazel-team): if rex is enabled, the proguard map will change and then will no + // longer correspond to the proto map proguardOutputProtoMap = semantics.getProtoMapping(ruleContext); } @@ -349,6 +364,7 @@ public abstract class ProguardHelper { * produced anyway if --java_optimization_mode includes obfuscation) * @param optimizationPasses if not null specifies to break proguard up into multiple passes with * the given number of optimization passes. + * @param proguardOutputMap mapping generated by Proguard if requested. could be null. */ public static ProguardOutput createProguardAction(RuleContext ruleContext, FilesToRunProvider proguard, @@ -360,13 +376,15 @@ public abstract class ProguardHelper { Iterable<Artifact> libraryJars, Artifact proguardOutputJar, JavaSemantics semantics, - @Nullable Integer optimizationPasses) throws InterruptedException { + @Nullable Integer optimizationPasses, + @Nullable Artifact proguardOutputMap) throws InterruptedException { JavaOptimizationMode optMode = getJavaOptimizationMode(ruleContext); Preconditions.checkArgument(optMode != JavaOptimizationMode.NOOP); Preconditions.checkArgument(optMode != JavaOptimizationMode.LEGACY || !proguardSpecs.isEmpty()); ProguardOutput output = - getProguardOutputs(proguardOutputJar, proguardSeeds, proguardUsage, ruleContext, semantics); + getProguardOutputs(proguardOutputJar, proguardSeeds, proguardUsage, ruleContext, semantics, + proguardOutputMap); if (optimizationPasses == null) { // Run proguard as a single step. |