Skip to content

Commit

Permalink
Only add symlinked proguard artifacts to filesBuilder when hasProguar…
Browse files Browse the repository at this point in the history
…dSpecs is True.

Some proguard artifacts are always generated in Starlark regardless of whether `proguard_specs` is specified or not because some users use a select to provide an empty list for `proguard_specs` and it's impossible to tell what a select will produce when determining implicit outputs.  When `proguard_specs` turns out to be an empty list, these artifacts should not be requested by filesBuilder, otherwise the build fails.

PiperOrigin-RevId: 574710546
Change-Id: I45ea0144eaaa195e0c1d5f119eabb83aaba48c0f
  • Loading branch information
Zhaoqing Xu authored and copybara-github committed Oct 19, 2023
1 parent 29985cd commit 073fba4
Showing 1 changed file with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ public static RuleConfiguredTargetBuilder createAndroidBinary(
javaSemantics,
dataContext,
filesBuilder,
hasProguardSpecs,
proguardOutput,
androidDexInfo.getFinalProguardOutputMap(),
optimizationInfo.getOptimizedResourceApk(),
Expand Down Expand Up @@ -1087,6 +1088,7 @@ private static void symlinkOptimizationOutputs(
JavaSemantics javaSemantics,
AndroidDataContext dataContext,
NestedSetBuilder<Artifact> filesBuilder,
boolean hasProguardSpecs,
ProguardOutput proguardOutput,
@Nullable Artifact finalProguardOutputMap,
@Nullable Artifact optimizedResourceApk,
Expand All @@ -1106,7 +1108,10 @@ private static void symlinkOptimizationOutputs(
proguardOutput.getOutputJar(),
proguardedJar,
"Symlinking proguard output jar"));
filesBuilder.add(proguardedJar);

if (hasProguardSpecs) {
filesBuilder.add(proguardedJar);
}
}

if (proguardOutput.getSeeds() != null) {
Expand All @@ -1118,7 +1123,10 @@ private static void symlinkOptimizationOutputs(
proguardOutput.getSeeds(),
proguardSeeds,
"Symlinking proguard seeds"));
filesBuilder.add(proguardSeeds);

if (hasProguardSpecs) {
filesBuilder.add(proguardSeeds);
}
}

if (proguardOutput.getConfig() != null) {
Expand All @@ -1130,7 +1138,10 @@ private static void symlinkOptimizationOutputs(
proguardOutput.getConfig(),
proguardConfig,
"Symlinking proguard config"));
filesBuilder.add(proguardConfig);

if (hasProguardSpecs) {
filesBuilder.add(proguardConfig);
}
}

if (proguardOutput.getUsage() != null) {
Expand All @@ -1142,7 +1153,10 @@ private static void symlinkOptimizationOutputs(
proguardOutput.getUsage(),
proguardUsage,
"Symlinking proguard usage"));
filesBuilder.add(proguardUsage);

if (hasProguardSpecs) {
filesBuilder.add(proguardUsage);
}
}

if (proguardOutput.getProtoMapping() != null
Expand All @@ -1154,7 +1168,10 @@ private static void symlinkOptimizationOutputs(
proguardOutput.getProtoMapping(),
proguardProtoMapping,
"Symlinking proguard proto mapping"));
filesBuilder.add(proguardProtoMapping);

if (hasProguardSpecs) {
filesBuilder.add(proguardProtoMapping);
}
}

// Conditionally select which output map to symlink. In the case where a select() resolves to
Expand All @@ -1173,7 +1190,10 @@ private static void symlinkOptimizationOutputs(
outputMap,
androidSemantics.getProguardOutputMap(ruleContext),
"Symlinking final proguard output map"));
filesBuilder.add(androidSemantics.getProguardOutputMap(ruleContext));

if (hasProguardSpecs) {
filesBuilder.add(androidSemantics.getProguardOutputMap(ruleContext));
}
}

if (optimizedResourceApk != null) {
Expand Down

0 comments on commit 073fba4

Please sign in to comment.