Skip to content

Commit

Permalink
Fix Fast Run for Bazel 7
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 599966301
  • Loading branch information
mai93 authored and copybara-github committed Jan 27, 2024
1 parent b93027f commit fb5d37d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.idea.blaze.base.model.BlazeVersionData;
import com.google.idea.blaze.base.model.primitives.Label;
import com.google.idea.blaze.base.model.primitives.TargetExpression;
import com.google.idea.blaze.base.settings.BuildSystemName;
Expand All @@ -29,22 +30,37 @@ public ImmutableSet<BuildSystemName> getSupportedBuildSystems() {
}

@Override
public ImmutableList<? extends TargetExpression> getBuildTargets(Label label) {
return ImmutableList.of(createDeployJarLabel(label), label);
public ImmutableList<? extends TargetExpression> getBuildTargets(
Label label, BlazeVersionData versionData) {
if (versionData.bazelIsAtLeastVersion(7, 0, 1)) {
return ImmutableList.of(label);
}
return ImmutableList.of(createDeployJarLabel(label, versionData), label);
}

@Override
public ImmutableList<String> getBuildFlags() {
public ImmutableList<String> getBuildFlags(BlazeVersionData versionData) {
if (versionData.bazelIsAtLeastVersion(7, 0, 1)) {
return ImmutableList.of(
"--experimental_java_test_auto_create_deploy_jar",
"--output_groups=+_hidden_top_level_INTERNAL_");
}
return ImmutableList.of();
}

@Override
public Label createDeployJarLabel(Label label) {
public Label createDeployJarLabel(Label label, BlazeVersionData versionData) {
if (versionData.bazelIsAtLeastVersion(7, 0, 1)) {
return Label.create(label + "_auto_deploy.jar");
}
return Label.create(label + "_deploy.jar");
}

@Override
public Label deployJarOwnerLabel(Label label) {
return createDeployJarLabel(label);
public Label deployJarOwnerLabel(Label label, BlazeVersionData versionData) {
if (versionData.bazelIsAtLeastVersion(7, 0, 1)) {
return label;
}
return createDeployJarLabel(label, versionData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.idea.blaze.java.fastbuild;

import com.google.common.collect.ImmutableList;
import com.google.idea.blaze.base.model.BlazeVersionData;
import com.google.idea.blaze.base.model.primitives.Label;
import com.google.idea.blaze.base.model.primitives.TargetExpression;
import com.google.idea.blaze.base.settings.BuildSystemName;
Expand All @@ -30,11 +31,12 @@ static FastBuildDeployJarStrategy getInstance(BuildSystemName buildSystemName) {
return BuildSystemExtensionPoint.getInstance(EP_NAME, buildSystemName);
}

public abstract ImmutableList<? extends TargetExpression> getBuildTargets(Label label);
public abstract ImmutableList<? extends TargetExpression> getBuildTargets(
Label label, BlazeVersionData versionData);

public abstract ImmutableList<String> getBuildFlags();
public abstract ImmutableList<String> getBuildFlags(BlazeVersionData versionData);

public abstract Label createDeployJarLabel(Label label);
public abstract Label createDeployJarLabel(Label label, BlazeVersionData versionData);

public abstract Label deployJarOwnerLabel(Label label);
public abstract Label deployJarOwnerLabel(Label label, BlazeVersionData versionData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,33 +269,34 @@ private FastBuildState.BuildOutput buildDeployJar(
Label label,
FastBuildParameters buildParameters,
BuildResultHelper resultHelper) {
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
BlazeInfo blazeInfo = getBlazeInfo(context, buildParameters);

BlazeVersionData blazeversionData =
BlazeVersionData.build(
Blaze.getBuildSystemProvider(project).getBuildSystem(), workspaceRoot, blazeInfo);

FastBuildDeployJarStrategy deployJarStrategy =
FastBuildDeployJarStrategy.getInstance(Blaze.getBuildSystemName(project));
Label deployJarLabel = deployJarStrategy.createDeployJarLabel(label);
Label deployJarLabel = deployJarStrategy.createDeployJarLabel(label, blazeversionData);
context.output(
new StatusOutput(
"Building base deploy jar for fast builds: " + deployJarLabel.targetName()));

BlazeInfo blazeInfo = getBlazeInfo(context, buildParameters);
FastBuildAspectStrategy aspectStrategy =
FastBuildAspectStrategy.getInstance(Blaze.getBuildSystemName(project));

Stopwatch timer = Stopwatch.createStarted();

BlazeCommand.Builder command =
BlazeCommand.builder(buildParameters.blazeBinary(), BlazeCommandName.BUILD)
.addTargets(deployJarStrategy.getBuildTargets(label))
.addBlazeFlags(deployJarStrategy.getBuildFlags())
.addTargets(deployJarStrategy.getBuildTargets(label, blazeversionData))
.addBlazeFlags(deployJarStrategy.getBuildFlags(blazeversionData))
.addBlazeFlags(buildParameters.buildFlags())
.addBlazeFlags(resultHelper.getBuildFlags());

WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);

aspectStrategy.addAspectAndOutputGroups(
command,
BlazeVersionData.build(
Blaze.getBuildSystemProvider(project).getBuildSystem(), workspaceRoot, blazeInfo),
/* additionalOutputGroups...= */ "default");
command, blazeversionData, /* additionalOutputGroups...= */ "default");

int exitCode =
ExternalTask.builder(workspaceRoot)
Expand All @@ -318,7 +319,7 @@ private FastBuildState.BuildOutput buildDeployJar(
ImmutableList<File> deployJarArtifacts =
BlazeArtifact.getLocalFiles(
resultHelper.getBuildArtifactsForTarget(
deployJarStrategy.deployJarOwnerLabel(label), jarPredicate));
deployJarStrategy.deployJarOwnerLabel(label, blazeversionData), jarPredicate));
checkState(deployJarArtifacts.size() == 1);
File deployJar = deployJarArtifacts.get(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ final class BazelFastBuildTestEnvironmentCreator extends FastBuildTestEnvironmen
// Bazel adds the Java launcher to the runfiles path when building a Java test target.
private static final File STANDARD_JAVA_BINARY = new File("../local_jdk/bin/java");

// TODO: b/295221112 - remove LAUNCHER_ALIAS once label_flag is used
private static final String LAUNCHER_ALIAS = "@bazel_tools//tools/jdk:launcher_flag_alias";

@Override
String getTestClassProperty() {
return "bazel.test_suite";
Expand All @@ -44,7 +47,7 @@ File getJavaBinFromLauncher(
@Nullable Label javaLauncher,
boolean swigdeps,
String runfilesPath) {
if (javaLauncher == null) {
if (javaLauncher == null || javaLauncher.getLabel().equals(LAUNCHER_ALIAS)) {
return getStandardJavaBinary(runfilesPath);
} else {
return new File(getTestBinary(label) + "_nativedeps");
Expand Down

0 comments on commit fb5d37d

Please sign in to comment.