Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
[fix] Fixup failed target names from BEP in bazel 6+ (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
steveniemitz authored May 10, 2023
1 parent f360c12 commit 3a60ce1
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
import org.jetbrains.bsp.bazel.bazelrunner.BazelInfo;
import org.jetbrains.bsp.bazel.bazelrunner.BazelRunner;
import org.jetbrains.bsp.bazel.logger.BspClientLogger;
import org.jetbrains.bsp.bazel.logger.BspClientTestNotifier;
Expand Down Expand Up @@ -70,7 +71,7 @@ public void export(CancelChecker cancelChecker) throws BazelExportFailedExceptio
bazelRunner,
compilationManager);
var projectProvider = serverContainer.getProjectProvider();
var client = new BloopBuildClient(System.out);
var client = new BloopBuildClient(System.out, serverContainer.getBazelInfo());
initializeClient(serverContainer, client);

var project = projectProvider.refreshAndGet(cancelChecker);
Expand Down Expand Up @@ -126,10 +127,12 @@ public Set<BuildTargetIdentifier> getFailedTargets() {
private static class BloopBuildClient implements BuildClient {

private final PrintStream out;
private final BazelInfo bazelInfo;
private final java.util.Set<BuildTargetIdentifier> failedTargets = Sets.newHashSet();

BloopBuildClient(PrintStream out) {
BloopBuildClient(PrintStream out, BazelInfo bazelInfo) {
this.out = out;
this.bazelInfo = bazelInfo;
}

public Set<BuildTargetIdentifier> getFailedTargets() {
Expand Down Expand Up @@ -157,7 +160,18 @@ public void onBuildTaskFinish(TaskFinishParams taskFinishParams) {}
public void onBuildPublishDiagnostics(PublishDiagnosticsParams publishDiagnosticsParams) {
if (publishDiagnosticsParams.getDiagnostics().stream()
.anyMatch(d -> d.getSeverity() == DiagnosticSeverity.ERROR)) {
this.failedTargets.add(publishDiagnosticsParams.getBuildTarget());
BuildTargetIdentifier modifiedTargetLabel;
if (bazelInfo.getRelease().getMajor() > 5) {
// Since bazel 6, the main repository targets are stringified to "@//"-prefixed labels,
// contrary to "//"-prefixed in older Bazel versions. Unfortunately this does not apply
// to BEP data, probably due to a bug, so we need to add the "@" prefix here.
modifiedTargetLabel =
new BuildTargetIdentifier("@" + publishDiagnosticsParams.getBuildTarget().getUri());
} else {
modifiedTargetLabel = publishDiagnosticsParams.getBuildTarget();
}

this.failedTargets.add(modifiedTargetLabel);
}
}

Expand Down

0 comments on commit 3a60ce1

Please sign in to comment.