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

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tpasternak committed Mar 10, 2023
1 parent 38c4f4f commit fff7da4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ class BazelBspServer(
val client = launcher.remoteProxy
bspClientLogger.initialize(client)
bspClientTestNotifier.initialize(client)
val bepServer = BepServer(client, DiagnosticsService(workspaceRoot))
compilationManager.setBepServer(bepServer)
bspIntegrationData.server = ServerBuilder.forPort(0).addService(bepServer).build()
compilationManager.setClient(client)
compilationManager.setWorkspace(workspaceRoot)
}

private fun createLauncher(bspIntegrationData: BspIntegrationData): Launcher.Builder<BuildClient> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ object ServerInitializer {
)
val bspServer = BazelBspServer(bspInfo, workspaceContextProvider, Path(cliArgs.bazelWorkspaceRoot))
bspServer.startServer(bspIntegrationData)
val server = bspIntegrationData.server.start()
bspServer.setBesBackendPort(server.port)
bspIntegrationData.launcher.startListening()
server.awaitTermination()
while (true){
Thread.sleep(10000)
}
} catch (e: Exception) {
e.printStackTrace(System.err)
hasErrors = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void initializeClient(ServerContainer serverContainer, BloopBuildClient
var bepServer =
new BepServer(
client, new DiagnosticsService(serverContainer.getBazelInfo().getWorkspaceRoot()));
serverContainer.getCompilationManager().setBepServer(bepServer);
// serverContainer.getCompilationManager().setBepServer(bepServer);

var grpcServer = ServerBuilder.forPort(0).addService(bepServer).build();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ data class BspIntegrationData(
val traceWriter: PrintWriter?,
) {
lateinit var launcher: Launcher<BuildClient>
lateinit var server: Server
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ java_library(
"//server/src/main/java/org/jetbrains/bsp/bazel/server/bep",
"//server/src/main/java/org/jetbrains/bsp/bazel/server/bsp/utils",
"@maven//:org_eclipse_lsp4j_org_eclipse_lsp4j_jsonrpc",
"@//server/src/main/java/org/jetbrains/bsp/bazel/server/diagnostics",
"@io_bazel//third_party/grpc:grpc-jar_checked_in"
],
)
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package org.jetbrains.bsp.bazel.server.bsp.managers;

import ch.epfl.scala.bsp4j.BuildClient;
import io.grpc.ServerBuilder;
import io.vavr.collection.List;
import io.vavr.collection.Seq;
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
import org.jetbrains.bsp.bazel.bazelrunner.BazelRunner;
import org.jetbrains.bsp.bazel.server.bep.BepServer;
import org.jetbrains.bsp.bazel.server.diagnostics.DiagnosticsService;
import org.jetbrains.bsp.bazel.workspacecontext.TargetsSpec;

import java.io.IOException;
import java.nio.file.Path;

public class BazelBspCompilationManager {

private final BazelRunner bazelRunner;
private BepServer bepServer;
private BuildClient client;
private Path workspaceRoot;

public BazelBspCompilationManager(BazelRunner bazelRunner) {
this.bazelRunner = bazelRunner;
Expand All @@ -23,18 +30,34 @@ public BepBuildResult buildTargetsWithBep(CancelChecker cancelChecker, TargetsSp
public BepBuildResult buildTargetsWithBep(
CancelChecker cancelChecker,
TargetsSpec targetSpecs, Seq<String> extraFlags, String originId) {
var result =
bazelRunner
.commandBuilder()
.build()
.withFlags(extraFlags.asJava())
.withTargets(targetSpecs)
.executeBazelBesCommand(originId)
.waitAndGetResult(cancelChecker, false);
return new BepBuildResult(result, bepServer.getBepOutput());
var bepServer = new BepServer(client, new DiagnosticsService(workspaceRoot));
var server = ServerBuilder.forPort(0).addService(bepServer).build();
try {
server.start();
} catch (IOException e) {
throw new RuntimeException(e);
}
bazelRunner.setBesBackendPort(server.getPort());
try {
var result =
bazelRunner
.commandBuilder()
.build()
.withFlags(extraFlags.asJava())
.withTargets(targetSpecs)
.executeBazelBesCommand(originId)
.waitAndGetResult(cancelChecker, true);
return new BepBuildResult(result, bepServer.getBepOutput());
} finally {
server.shutdown();
}
}

public void setClient(BuildClient client) {
this.client = client;
}

public void setBepServer(BepServer bepServer) {
this.bepServer = bepServer;
public void setWorkspace(Path workspaceRoot) {
this.workspaceRoot = workspaceRoot;
}
}

0 comments on commit fff7da4

Please sign in to comment.