Skip to content

Commit

Permalink
Inline and delete JavaSemantics.getTestSupport() that always return…
Browse files Browse the repository at this point in the history
…s `null`

PiperOrigin-RevId: 585045653
Change-Id: Ibb17fca91c00705a09e4bfef9638043cc8698e13
  • Loading branch information
hvadehra authored and copybara-github committed Nov 24, 2023
1 parent 38eefc0 commit dad111c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@
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.collect.nestedset.Order;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.rules.java.DeployArchiveBuilder;
import com.google.devtools.build.lib.rules.java.DeployArchiveBuilder.Compression;
import com.google.devtools.build.lib.rules.java.JavaCommon;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider.ClasspathType;
import com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts;
import com.google.devtools.build.lib.rules.java.JavaConfiguration;
Expand Down Expand Up @@ -205,19 +203,8 @@ public Artifact createStubAction(
? "0"
: "1"));

TransitiveInfoCollection testSupport = JavaSemantics.getTestSupport(ruleContext);
NestedSet<Artifact> testSupportJars =
testSupport == null
? NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER)
: getRuntimeJarsForTargets(testSupport);

NestedSetBuilder<Artifact> classpathBuilder = NestedSetBuilder.naiveLinkOrder();
classpathBuilder.addTransitive(javaCommon.getRuntimeClasspath());
if (enforceExplicitJavaTestDeps(ruleContext)) {
// Currently, this is only needed when --explicit_java_test_deps=true, as otherwise the
// testSupport classpath is wrongly present in the javaCommon.getRuntimeClasspath().
classpathBuilder.addTransitive(testSupportJars);
}
NestedSet<Artifact> classpath = classpathBuilder.build();

arguments.add(new ComputedClasspathSubstitution(classpath, workspacePrefix, isRunfilesEnabled));
Expand Down Expand Up @@ -332,15 +319,6 @@ private static boolean enforceExplicitJavaTestDeps(RuleContext ruleContext) {
return ruleContext.getFragment(JavaConfiguration.class).explicitJavaTestDeps();
}

private static NestedSet<Artifact> getRuntimeJarsForTargets(TransitiveInfoCollection... deps)
throws RuleErrorException {
// The dep may be a simple JAR and not a java rule, hence we can't simply do
// dep.getProvider(JavaCompilationArgsProvider.class).getRecursiveJavaCompilationArgs(),
// so we reuse the logic within JavaCompilationArgsProvider to handle both scenarios.
return JavaCompilationArgsProvider.legacyFromTargets(ImmutableList.copyOf(deps))
.getRuntimeJars();
}

@Override
public void addRunfilesForLibrary(RuleContext ruleContext, Runfiles.Builder runfilesBuilder) {
}
Expand All @@ -358,13 +336,6 @@ public void collectTargetsTreatedAsDeps(
// targets may break, we are keeping it behind this flag.
return;
}
// Only add the test support to the dependencies when running in regular mode.
// In persistent test runner mode don't pollute the classpath of the test with
// the test support classes.
TransitiveInfoCollection testSupport = JavaSemantics.getTestSupport(ruleContext);
if (testSupport != null) {
builder.add(testSupport);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.fromTemplates;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.OutputGroupInfo;
import com.google.devtools.build.lib.analysis.RuleContext;
Expand All @@ -33,7 +32,6 @@
import com.google.devtools.build.lib.packages.Attribute.LabelListLateBoundDefault;
import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.rules.java.DeployArchiveBuilder.Compression;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider.ClasspathType;
import com.google.devtools.build.lib.rules.java.JavaConfiguration.OneVersionEnforcementLevel;
Expand Down Expand Up @@ -220,34 +218,6 @@ Artifact createStubAction(
*/
boolean isJavaExecutableSubstitution();

@Nullable
static TransitiveInfoCollection getTestSupport(RuleContext ruleContext) {
if (!isJavaBinaryOrJavaTest(ruleContext)) {
return null;
}

if (useLegacyJavaTest(ruleContext)) {
return null;
}

boolean createExecutable = ruleContext.attributes().get("create_executable", Type.BOOLEAN);
if (createExecutable && ruleContext.attributes().get("use_testrunner", Type.BOOLEAN)) {
return Iterables.getOnlyElement(ruleContext.getPrerequisites("$testsupport"));
} else {
return null;
}
}

static boolean useLegacyJavaTest(RuleContext ruleContext) {
return !ruleContext.attributes().isAttributeValueExplicitlySpecified("test_class")
&& ruleContext.getFragment(JavaConfiguration.class).useLegacyBazelJavaTest();
}

static boolean isJavaBinaryOrJavaTest(RuleContext ruleContext) {
return ruleContext.getRule().getRuleClass().equals("java_binary")
|| ruleContext.getRule().getRuleClass().equals("java_test");
}

/** Adds extra runfiles for a {@code java_library} rule. */
void addRunfilesForLibrary(RuleContext ruleContext, Runfiles.Builder runfilesBuilder);

Expand Down

0 comments on commit dad111c

Please sign in to comment.