Skip to content

Commit

Permalink
Propagate runfiles for singlejar.
Browse files Browse the repository at this point in the history
Since the singlejar toolchain attribute is currently defined as a single file and carried around as an Artifact instead of a FilesToRunProvider, it's not possible to implement it as a wrapper script that dispatches to an actual implementation somewhere in its runfiles. This would be useful to experiment with cross-platform action sharing.

PiperOrigin-RevId: 492487124
Change-Id: Ib0f80314eae09bd865b3f31a4180bf068833cdf4
  • Loading branch information
tjgq authored and ted-xie committed Mar 1, 2023
1 parent 11b1e10 commit eeaee3d
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.FileProvider;
import com.google.devtools.build.lib.analysis.FilesToRunProvider;
import com.google.devtools.build.lib.analysis.OutputGroupInfo;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory;
Expand Down Expand Up @@ -403,7 +404,7 @@ private static SpawnAction createAarEmbeddedJarsExtractorActions(
private static SpawnAction createAarJarsMergingActions(
RuleContext ruleContext, Artifact jarsTreeArtifact, Artifact mergedJar, Artifact paramFile) {
SpawnAction.Builder builder = new SpawnAction.Builder().useDefaultShellEnvironment();
Artifact singleJar = JavaToolchainProvider.from(ruleContext).getSingleJar();
FilesToRunProvider singleJar = JavaToolchainProvider.from(ruleContext).getSingleJar();
return builder
.setExecutable(singleJar)
.setMnemonic("AarJarsMerger")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ private static SpawnAction.Builder createSpawnActionBuilder(RuleContext ruleCont
}

private static SpawnAction.Builder singleJarSpawnActionBuilder(RuleContext ruleContext) {
Artifact singleJar = JavaToolchainProvider.from(ruleContext).getSingleJar();
FilesToRunProvider singleJar = JavaToolchainProvider.from(ruleContext).getSingleJar();
SpawnAction.Builder builder =
createSpawnActionBuilder(ruleContext).useDefaultShellEnvironment();
builder.setExecutable(singleJar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ private void signApk(

private static void setSingleJarAsExecutable(
RuleContext ruleContext, SpawnAction.Builder builder) {
Artifact singleJar = JavaToolchainProvider.from(ruleContext).getSingleJar();
FilesToRunProvider singleJar = JavaToolchainProvider.from(ruleContext).getSingleJar();
builder.setExecutable(singleJar);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.devtools.build.lib.actions.ParamFileInfo;
import com.google.devtools.build.lib.actions.ParameterFile.ParameterFileType;
import com.google.devtools.build.lib.actions.ResourceSet;
import com.google.devtools.build.lib.analysis.FilesToRunProvider;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
Expand Down Expand Up @@ -420,7 +421,7 @@ public void build() throws InterruptedException {
inputs.add(libModules);
}

Artifact singlejar = JavaToolchainProvider.from(ruleContext).getSingleJar();
FilesToRunProvider singlejar = JavaToolchainProvider.from(ruleContext).getSingleJar();

String toolchainIdentifier = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
import com.google.devtools.build.lib.analysis.Allowlist;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.FilesToRunProvider;
import com.google.devtools.build.lib.analysis.OutputGroupInfo;
import com.google.devtools.build.lib.analysis.PrerequisiteArtifacts;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
Expand Down Expand Up @@ -510,9 +511,10 @@ public ConfiguredTarget create(RuleContext ruleContext)

// Make single jar reachable from the coverage environment because it needs to be executed
// by the coverage collection script.
Artifact singleJar = JavaToolchainProvider.from(ruleContext).getSingleJar();
coverageEnvironment.add(new Pair<>("SINGLE_JAR_TOOL", singleJar.getExecPathString()));
coverageSupportFiles.add(singleJar);
FilesToRunProvider singleJar = JavaToolchainProvider.from(ruleContext).getSingleJar();
coverageEnvironment.add(
new Pair<>("SINGLE_JAR_TOOL", singleJar.getExecutable().getExecPathString()));
coverageSupportFiles.addTransitive(singleJar.getFilesToRun());
}

common.addTransitiveInfoProviders(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
.get("reduced_classpath_incompatible_processors", Type.STRING_LIST));
boolean forciblyDisableHeaderCompilation =
ruleContext.attributes().get("forcibly_disable_header_compilation", Type.BOOLEAN);
Artifact singleJar = ruleContext.getPrerequisiteArtifact("singlejar");
FilesToRunProvider singleJar = ruleContext.getExecutablePrerequisite("singlejar");
FilesToRunProvider oneVersion = ruleContext.getExecutablePrerequisite("oneversion");
Artifact oneVersionAllowlist = ruleContext.getPrerequisiteArtifact("oneversion_whitelist");
Artifact genClass = ruleContext.getPrerequisiteArtifact("genclass");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static JavaToolchainProvider create(
ImmutableSet<String> headerCompilerBuiltinProcessors,
ImmutableSet<String> reducedClasspathIncompatibleProcessors,
boolean forciblyDisableHeaderCompilation,
Artifact singleJar,
FilesToRunProvider singleJar,
@Nullable FilesToRunProvider oneVersion,
@Nullable Artifact oneVersionAllowlist,
Artifact genClass,
Expand Down Expand Up @@ -174,7 +174,7 @@ public static JavaToolchainProvider create(
private final ImmutableSet<String> headerCompilerBuiltinProcessors;
private final ImmutableSet<String> reducedClasspathIncompatibleProcessors;
private final boolean forciblyDisableHeaderCompilation;
private final Artifact singleJar;
private final FilesToRunProvider singleJar;
@Nullable private final FilesToRunProvider oneVersion;
@Nullable private final Artifact oneVersionAllowlist;
private final Artifact genClass;
Expand Down Expand Up @@ -208,7 +208,7 @@ private JavaToolchainProvider(
ImmutableSet<String> headerCompilerBuiltinProcessors,
ImmutableSet<String> reducedClasspathIncompatibleProcessors,
boolean forciblyDisableHeaderCompilation,
Artifact singleJar,
FilesToRunProvider singleJar,
@Nullable FilesToRunProvider oneVersion,
@Nullable Artifact oneVersionAllowlist,
Artifact genClass,
Expand Down Expand Up @@ -334,14 +334,14 @@ public boolean getForciblyDisableHeaderCompilation() {
return forciblyDisableHeaderCompilation;
}

/** Returns the {@link Artifact} of the SingleJar deploy jar */
/** Returns the {@link FilesToRunProvider} of the SingleJar tool. */
@Override
public Artifact getSingleJar() {
public FilesToRunProvider getSingleJar() {
return singleJar;
}

/**
* Return the {@link Artifact} of the binary that enforces one-version compliance of java
* Return the {@link FilesToRunProvider} of the tool that enforces one-version compliance of Java
* binaries.
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ The Java target version (e.g., '6' or '7'). It specifies for which Java runtime
.add(
attr("singlejar", LABEL_LIST)
.mandatory()
.singleArtifact()
// This needs to be in the execution configuration.
.cfg(ExecutionTransitionFactory.create())
.allowedFileTypes(FileTypeSet.ANY_FILE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public interface JavaToolchainStarlarkApiProviderApi extends StructApi {
@StarlarkMethod(name = "target_version", doc = "The java target version.", structField = true)
String getTargetVersion();

@StarlarkMethod(name = "single_jar", doc = "The SingleJar deploy jar.", structField = true)
FileApi getSingleJar();
@StarlarkMethod(name = "single_jar", doc = "The SingleJar tool.", structField = true)
FilesToRunProviderApi<? extends FileApi> getSingleJar();

@Nullable
@StarlarkMethod(
name = "one_version_tool",
doc = "The artifact that enforces One-Version compliance of java binaries.",
doc = "The tool that enforces One-Version compliance of java binaries.",
structField = true,
allowReturnNones = true)
FilesToRunProviderApi<? extends FileApi> getOneVersionBinary();
Expand Down

0 comments on commit eeaee3d

Please sign in to comment.