From ce0b2b23189bc31c135573015ad06748101bc1ae Mon Sep 17 00:00:00 2001 From: kmb Date: Mon, 15 Mar 2021 18:19:31 -0700 Subject: [PATCH] Handle multiple data deps for java_toolchain tools PiperOrigin-RevId: 363077456 --- .../lib/rules/java/JavaToolchainTool.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainTool.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainTool.java index 712f53d8a70de3..67f40a9f35d42f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainTool.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainTool.java @@ -14,6 +14,8 @@ package com.google.devtools.build.lib.rules.java; +import static com.google.devtools.build.lib.collect.nestedset.Order.STABLE_ORDER; + import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; @@ -27,6 +29,7 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.actions.CustomCommandLine; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import javax.annotation.Nullable; @@ -40,7 +43,7 @@ public abstract class JavaToolchainTool { public abstract FilesToRunProvider tool(); /** Additional inputs required by the tool, e.g. a Class Data Sharing archive. */ - public abstract ImmutableList data(); + public abstract NestedSet data(); /** * JVM flags to invoke the tool with, or empty if it is not a {@code _deploy.jar}. Location @@ -58,18 +61,16 @@ static JavaToolchainTool fromRuleContext( if (tool == null) { return null; } - TransitiveInfoCollection data = ruleContext.getPrerequisite(dataAttribute); - ImmutableList dataArtifacts = - data == null - ? ImmutableList.of() - : data.getProvider(FileProvider.class).getFilesToBuild().toList(); - ImmutableMap> locations = - data == null - ? ImmutableMap.of() - : ImmutableMap.of(AliasProvider.getDependencyLabel(data), dataArtifacts); + NestedSetBuilder dataArtifacts = NestedSetBuilder.stableOrder(); + ImmutableMap.Builder> locations = ImmutableMap.builder(); + for (TransitiveInfoCollection data : ruleContext.getPrerequisites(dataAttribute)) { + NestedSet files = data.getProvider(FileProvider.class).getFilesToBuild(); + dataArtifacts.addTransitive(files); + locations.put(AliasProvider.getDependencyLabel(data), files.toList()); + } ImmutableList jvmOpts = - ruleContext.getExpander().withExecLocations(locations).list(jvmOptsAttribute); - return create(tool, dataArtifacts, jvmOpts); + ruleContext.getExpander().withExecLocations(locations.build()).list(jvmOptsAttribute); + return create(tool, dataArtifacts.build(), jvmOpts); } @Nullable @@ -77,12 +78,12 @@ static JavaToolchainTool fromFilesToRunProvider(@Nullable FilesToRunProvider exe if (executable == null) { return null; } - return create(executable, ImmutableList.of(), ImmutableList.of()); + return create(executable, NestedSetBuilder.emptySet(STABLE_ORDER), ImmutableList.of()); } @AutoCodec.Instantiator static JavaToolchainTool create( - FilesToRunProvider tool, ImmutableList data, ImmutableList jvmOpts) { + FilesToRunProvider tool, NestedSet data, ImmutableList jvmOpts) { return new AutoValue_JavaToolchainTool(tool, data, jvmOpts); } @@ -100,7 +101,7 @@ void buildCommandLine( CustomCommandLine.Builder command, JavaToolchainProvider toolchain, NestedSetBuilder inputs) { - inputs.addAll(data()); + inputs.addTransitive(data()); Artifact executable = tool().getExecutable(); if (!executable.getExtension().equals("jar")) { command.addExecPath(executable);