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

Nk compilation avoidance java upstream #1

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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 @@ -777,7 +777,9 @@ private void addArgsAndJarsToAttributes(
attributes.addDirectJars(directJars);
}

attributes.merge(args);
boolean pruneTransitiveDeps = ruleContext.getFragment(JavaConfiguration.class)
.experimentalPruneTransitiveDeps();
attributes.merge(args, pruneTransitiveDeps);
}

private void addLibrariesToAttributesInternal(Iterable<? extends TransitiveInfoCollection> deps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public enum ImportDepsCheckingLevel {
private final boolean multiReleaseDeployJars;
private final boolean disallowJavaImportExports;
private final boolean disallowJavaImportEmptyJars;
private final boolean experimentalPruneTransitiveDeps;

// TODO(dmarting): remove once we have a proper solution for #2539
private final boolean useLegacyBazelJavaTest;
Expand Down Expand Up @@ -156,6 +157,7 @@ public JavaConfiguration(BuildOptions buildOptions) throws InvalidConfigurationE
this.multiReleaseDeployJars = javaOptions.multiReleaseDeployJars;
this.disallowJavaImportExports = javaOptions.disallowJavaImportExports;
this.disallowJavaImportEmptyJars = javaOptions.disallowJavaImportEmptyJars;
this.experimentalPruneTransitiveDeps = javaOptions.experimentalPruneTransitiveDeps;

Map<String, Label> optimizers = javaOptions.bytecodeOptimizers;
if (optimizers.size() > 1) {
Expand Down Expand Up @@ -466,4 +468,8 @@ public boolean experimentalEnableJspecify() {
public boolean requireJavaPluginInfo() {
return requireJavaPluginInfo;
}

public boolean experimentalPruneTransitiveDeps() {
return experimentalPruneTransitiveDeps;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ public ConfiguredTarget create(RuleContext ruleContext)
ruleContext.getUniqueDirectoryArtifact(
"_java_import", "jdeps.proto", ruleContext.getBinOrGenfilesDirectory());
JavaCompilationArgsProvider provider = JavaCompilationArgsProvider.legacyFromTargets(targets);
boolean pruneTransitiveDeps = ruleContext.getFragment(JavaConfiguration.class)
.experimentalPruneTransitiveDeps();
JavaTargetAttributes attributes =
new JavaTargetAttributes.Builder(semantics)
.merge(provider)
.merge(provider, pruneTransitiveDeps)
.addDirectJars(provider.getDirectCompileTimeJars())
.build();
ImportDepsCheckActionBuilder.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.config.CoreOptionConverters.StrictDepsMode;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.rules.java.JavaConfiguration.JavaClasspathMode;
Expand Down Expand Up @@ -404,7 +405,14 @@ private void addDepsToAttributes(JavaTargetAttributes.Builder attributes) {
attributes.addDirectJars(mergedDeps.getDirectCompileTimeJars());
}

attributes.addCompileTimeClassPathEntries(mergedDeps.getTransitiveCompileTimeJars());
boolean pruneTransitiveDeps = ruleContext.getFragment(JavaConfiguration.class)
.experimentalPruneTransitiveDeps();

NestedSet<Artifact> localCompileTimeDeps = pruneTransitiveDeps
? mergedDeps.getDirectCompileTimeJars()
: mergedDeps.getTransitiveCompileTimeJars();

attributes.addCompileTimeClassPathEntries(localCompileTimeDeps);
attributes.addRuntimeClassPathEntries(mergedRuntimeDeps.getRuntimeJars());
attributes.addRuntimeClassPathEntries(mergedDeps.getRuntimeJars());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,21 @@ public ImportDepsCheckingLevelConverter() {
effectTags = {OptionEffectTag.UNKNOWN},
help = "Enable experimental jspecify integration.")
public boolean experimentalEnableJspecify;

@Option(
name = "experimental_prune_transitive_deps",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.BUILD_TIME_OPTIMIZATION,
effectTags = {
OptionEffectTag.LOADING_AND_ANALYSIS,
OptionEffectTag.EXECUTION,
OptionEffectTag.AFFECTS_OUTPUTS},
metadataTags = {OptionMetadataTag.EXPERIMENTAL},
help =
"If enabled, compilation is performed against only direct dependencies. Transitive deps "
+ "required for compilation must be explicitly added")
public boolean experimentalPruneTransitiveDeps;

@Override
public FragmentOptions getHost() {
// Note validation actions don't run in host config, so no need copying flags related to that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ public Builder addSourceFiles(Iterable<Artifact> sourceFiles) {
}

@CanIgnoreReturnValue
public Builder merge(JavaCompilationArgsProvider context) {
Preconditions.checkArgument(!built);
addCompileTimeClassPathEntries(context.getTransitiveCompileTimeJars());
public Builder merge(JavaCompilationArgsProvider context, boolean pruneTransitiveDeps) {
addCompileTimeClassPathEntries(
pruneTransitiveDeps ? context.getDirectCompileTimeJars()
: context.getTransitiveCompileTimeJars());
addRuntimeClassPathEntries(context.getRuntimeJars());
return this;
}
Expand Down