Skip to content

Commit

Permalink
[7.4.0] Blaze/Bazel changes for Java 17 Record desugaring (#24030)
Browse files Browse the repository at this point in the history
createDexMergerActions continues to be exposed to Starlark due to it's
use for SpawnActionTemplate which is not exposed to Starlark. We must
pass a file containing global information to the final dexmerging step
in order to support Java 17 Record desugaring. This change adds an
optional parameter to the Starlark interface to forward the globals file
to the Dex Merger.

PiperOrigin-RevId: 660045021
Change-Id: Ie3b961ff2687f48ca29a94e67180c0e5875ddbe3

Commit
2daa0a3

Co-authored-by: Andrew Sinclair <[email protected]>
  • Loading branch information
bazel-io and ajsinclair authored Oct 18, 2024
1 parent a99de87 commit aa47fd1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,13 @@ private static void createIncrementalDexingActions(
ruleContext.getUniqueDirectory("dexfiles"), ruleContext.getBinOrGenfilesDirectory());
FilesToRunProvider dexMerger = ruleContext.getExecutablePrerequisite("$dexmerger");
createTemplatedMergerActions(
ruleContext, multidexShards, shardsToMerge, dexopts, dexMerger, minSdkVersion);
ruleContext,
multidexShards,
shardsToMerge,
dexopts,
dexMerger,
minSdkVersion,
null /* desugarGlobals */);
// TODO(b/69431301): avoid this action and give the files to apk build action directly
createZipMergeAction(ruleContext, multidexShards, classesDex);
}
Expand Down Expand Up @@ -2024,7 +2030,8 @@ public static void createTemplatedMergerActions(
SpecialArtifact inputTree,
List<String> dexopts,
FilesToRunProvider executable,
int minSdkVersion) {
int minSdkVersion,
Object desugarGlobals) {
SpawnActionTemplate.Builder dexmerger =
new SpawnActionTemplate.Builder(inputTree, outputTree)
.setExecutable(executable)
Expand All @@ -2044,6 +2051,12 @@ public static void createTemplatedMergerActions(
if (minSdkVersion > 0) {
commandLine.add("--min_sdk_version", Integer.toString(minSdkVersion));
}
Artifact desugarGlobalsArtifact =
AndroidStarlarkData.fromNoneable(desugarGlobals, Artifact.class);
if (desugarGlobalsArtifact != null) {
dexmerger.addCommonInputs(ImmutableList.of(desugarGlobalsArtifact));
commandLine.addPath("--global_synthetics_path", desugarGlobalsArtifact.getExecPath());
}
dexmerger.setCommandLineTemplate(commandLine.build());
ruleContext.registerAction(dexmerger.build(ruleContext.getActionOwner()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,17 @@ public void createDexMergerActions(
Artifact input,
Sequence<?> dexopts, // <String> expected.
FilesToRunProvider dexmerger,
StarlarkInt minSdkVersion)
StarlarkInt minSdkVersion,
Object desugarGlobals)
throws EvalException, RuleErrorException {
AndroidBinary.createTemplatedMergerActions(
starlarkRuleContext.getRuleContext(),
(SpecialArtifact) output,
(SpecialArtifact) input,
Sequence.cast(dexopts, String.class, "dexopts"),
dexmerger,
minSdkVersion.toInt("min_sdk_version"));
minSdkVersion.toInt("min_sdk_version"),
desugarGlobals);
}

@StarlarkMethod(name = AndroidIdeInfoProviderApi.NAME, structField = true, documented = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.starlark.java.annot.StarlarkBuiltin;
import net.starlark.java.annot.StarlarkMethod;
import net.starlark.java.eval.EvalException;
import net.starlark.java.eval.NoneType;
import net.starlark.java.eval.Sequence;
import net.starlark.java.eval.StarlarkInt;
import net.starlark.java.eval.StarlarkValue;
Expand Down Expand Up @@ -154,14 +155,25 @@ JavaInfoT enableImplicitSourcelessDepsExportsCompatibility(Info javaInfo, boolea
defaultValue = "0",
allowedTypes = {
@ParamType(type = StarlarkInt.class),
})
}),
@Param(
name = "desugar_globals",
doc = "The D8 desugar globals file.",
positional = false,
named = true,
defaultValue = "None",
allowedTypes = {
@ParamType(type = FileApi.class),
@ParamType(type = NoneType.class),
}),
})
void createDexMergerActions(
StarlarkRuleContextT starlarkRuleContext,
FileT output,
FileT input,
Sequence<?> dexopts, // <String> expected.
FilesToRunProviderT dexmerger,
StarlarkInt minSdkVersion)
StarlarkInt minSdkVersion,
Object desugarGlobals)
throws EvalException, RuleErrorException;
}

0 comments on commit aa47fd1

Please sign in to comment.