Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.1.0] Share classpath NestedSet between full and header compile actions #21389

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public void createHeaderCompilationAction(
.addSourceJars(Sequence.cast(sourceJars, Artifact.class, "source_jars"))
.addSourceFiles(sourceFiles.toList(Artifact.class))
.addDirectJars(directJars.getSet(Artifact.class))
.addCompileTimeClassPathEntries(compileTimeClasspath.getSet(Artifact.class))
.setCompileTimeClassPathEntriesWithPrependedDirectJars(
compileTimeClasspath.getSet(Artifact.class))
.setStrictJavaDeps(getStrictDepsMode(Ascii.toUpperCase(strictDepsMode)))
.setTargetLabel(targetLabel)
.setInjectingRuleKind(
Expand Down Expand Up @@ -215,7 +216,8 @@ public void createCompilationAction(
.addSourceJars(Sequence.cast(sourceJars, Artifact.class, "source_jars"))
.addSourceFiles(Depset.noneableCast(sourceFiles, Artifact.class, "sources").toList())
.addDirectJars(directJars.getSet(Artifact.class))
.addCompileTimeClassPathEntries(compileTimeClasspath.getSet(Artifact.class))
.setCompileTimeClassPathEntriesWithPrependedDirectJars(
compileTimeClasspath.getSet(Artifact.class))
.addClassPathResources(
Sequence.cast(classpathResources, Artifact.class, "classpath_resources"))
.setStrictJavaDeps(getStrictDepsMode(Ascii.toUpperCase(strictDepsMode)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public static class Builder {

private final NestedSetBuilder<Artifact> excludedArtifacts = NestedSetBuilder.naiveLinkOrder();

private boolean prependDirectJars = true;

private boolean built = false;

private final JavaSemantics semantics;
Expand Down Expand Up @@ -179,6 +181,24 @@ public Builder addCompileTimeClassPathEntries(NestedSet<Artifact> entries) {
return this;
}

/**
* Avoids prepending the direct jars to the compile-time classpath when building the attributes,
* assuming that they have already been prepended. This avoids creating a new {@link NestedSet}
* instance.
*
* <p>After this method is called, {@link #addDirectJar(Artifact)} and {@link
* #addDirectJars(NestedSet)} will throw an exception.
*/
@CanIgnoreReturnValue
public Builder setCompileTimeClassPathEntriesWithPrependedDirectJars(
NestedSet<Artifact> entries) {
Preconditions.checkArgument(!built);
Preconditions.checkArgument(compileTimeClassPathBuilder.isEmpty());
prependDirectJars = false;
compileTimeClassPathBuilder.addTransitive(entries);
return this;
}

@CanIgnoreReturnValue
public Builder setTargetLabel(Label targetLabel) {
Preconditions.checkArgument(!built);
Expand Down Expand Up @@ -251,13 +271,15 @@ public Builder setStrictJavaDeps(StrictDepsMode strictDeps) {
@CanIgnoreReturnValue
public Builder addDirectJars(NestedSet<Artifact> directJars) {
Preconditions.checkArgument(!built);
Preconditions.checkArgument(prependDirectJars);
this.directJarsBuilder.addTransitive(directJars);
return this;
}

@CanIgnoreReturnValue
public Builder addDirectJar(Artifact directJar) {
Preconditions.checkArgument(!built);
Preconditions.checkArgument(prependDirectJars);
this.directJarsBuilder.add(directJar);
return this;
}
Expand Down Expand Up @@ -323,10 +345,12 @@ public JavaTargetAttributes build() {
built = true;
NestedSet<Artifact> directJars = directJarsBuilder.build();
NestedSet<Artifact> compileTimeClassPath =
NestedSetBuilder.<Artifact>naiveLinkOrder()
.addTransitive(directJars)
.addTransitive(compileTimeClassPathBuilder.build())
.build();
prependDirectJars
? NestedSetBuilder.<Artifact>naiveLinkOrder()
.addTransitive(directJars)
.addTransitive(compileTimeClassPathBuilder.build())
.build()
: compileTimeClassPathBuilder.build();
return new JavaTargetAttributes(
ImmutableSet.copyOf(sourceFiles),
runtimeClassPath.build(),
Expand Down
Loading