Skip to content

Commit

Permalink
Add --experimental_javac_exclude_transitive_workspace_jars
Browse files Browse the repository at this point in the history
  • Loading branch information
rsalvador committed Jan 1, 2023
1 parent 5f29bb3 commit 4c7ea46
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ public JavaCompileAction build() {
classpathMode = JavaClasspathMode.OFF;
}

JavaConfiguration javaConfiguration =
ruleContext.getConfiguration().getFragment(JavaConfiguration.class);
if (outputs.depsProto() != null) {
JavaConfiguration javaConfiguration =
ruleContext.getConfiguration().getFragment(JavaConfiguration.class);
if (javaConfiguration.inmemoryJdepsFiles()) {
executionInfo =
ImmutableMap.<String, String>builderWithExpectedSize(this.executionInfo.size() + 1)
Expand All @@ -271,6 +271,19 @@ public JavaCompileAction build() {
executableLine.stripOutputPaths(JavaCompilationHelper.outputBase(outputs.output()));
}

NestedSet<Artifact> transitiveInputs = classpathEntries;
if (javaConfiguration.javacExcludeTransitiveWorkspaceJars() && isWorkspaceJar(outputs.output())) {
NestedSetBuilder<Artifact> inputsBuilder = NestedSetBuilder.compileOrder();
ImmutableSet<Artifact> directJarsSet = directJars.toSet();
for (Artifact artifact: classpathEntries.toList()) {
// skip adding transitive workspace jars
if (!isWorkspaceJar(artifact) || directJarsSet.contains(artifact)) {
inputsBuilder.add(artifact);
}
}
transitiveInputs = inputsBuilder.build();
}

return new JavaCompileAction(
/* compilationType= */ JavaCompileAction.CompilationType.JAVAC,
/* owner= */ ruleContext.getActionOwner(),
Expand All @@ -284,7 +297,7 @@ public JavaCompileAction build() {
/* sourceJars= */ sourceJars,
/* plugins= */ plugins),
/* mandatoryInputs= */ mandatoryInputs,
/* transitiveInputs= */ classpathEntries, // directJars,
/* transitiveInputs= */ transitiveInputs,
/* directJars= */ directJars,
/* outputs= */ allOutputs(),
/* executionInfo= */ executionInfo,
Expand All @@ -297,6 +310,15 @@ public JavaCompileAction build() {
/* classpathMode= */ classpathMode);
}

/**
* @return True iff artifact is a jar build by the root workspace
*/
private static boolean isWorkspaceJar(Artifact artifact) {
String execPath = artifact.getExecPathString();
// TODO: better implementation/criteria
return !(artifact.getRoot().isExternal() || execPath.contains("/bin/external/") || execPath.contains("/third_party/"));
}

private ImmutableSet<Artifact> allOutputs() {
ImmutableSet.Builder<Artifact> result =
ImmutableSet.<Artifact>builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public enum ImportDepsCheckingLevel {
private final boolean allowRuntimeDepsOnNeverLink;
private final JavaClasspathMode javaClasspath;
private final boolean inmemoryJdepsFiles;
private final boolean javacExcludeTransitiveWorkspaceJars;
private final ImmutableList<String> defaultJvmFlags;
private final StrictDepsMode strictJavaDeps;
private final String fixDepsTool;
Expand Down Expand Up @@ -127,6 +128,7 @@ public JavaConfiguration(BuildOptions buildOptions) throws InvalidConfigurationE
javaOptions.javaDeps || javaOptions.javaClasspath != JavaClasspathMode.OFF;
this.javaClasspath = javaOptions.javaClasspath;
this.inmemoryJdepsFiles = javaOptions.inmemoryJdepsFiles;
this.javacExcludeTransitiveWorkspaceJars = javaOptions.javacExcludeTransitiveWorkspaceJars;
this.defaultJvmFlags = ImmutableList.copyOf(javaOptions.jvmOpts);
this.strictJavaDeps = javaOptions.strictJavaDeps;
this.fixDepsTool = javaOptions.fixDepsTool;
Expand Down Expand Up @@ -263,6 +265,8 @@ public boolean inmemoryJdepsFiles() {
return inmemoryJdepsFiles;
}

public boolean javacExcludeTransitiveWorkspaceJars() { return javacExcludeTransitiveWorkspaceJars; }

@Override
public ImmutableList<String> getDefaultJvmFlags() {
return defaultJvmFlags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ public ImportDepsCheckingLevelConverter() {
+ "written to disk.")
public boolean inmemoryJdepsFiles;

@Option(
name = "experimental_javac_exclude_transitive_workspace_jars",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help = "Help: do not pass transitive workspace jars to the java compile action")
public boolean javacExcludeTransitiveWorkspaceJars;

@Option(
name = "java_debug",
defaultValue = "null",
Expand Down

0 comments on commit 4c7ea46

Please sign in to comment.