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

Commit

Permalink
[fix] server handles properly remote artefacts after sync | #BAZEL-82…
Browse files Browse the repository at this point in the history
…3, #BAZEL-793 Done

review

workssss

todo

uri -> path

koooootlin

Rename .java to .kt


Merge-request: BAZEL-MR-823
Merged-by: Marcin Abramowicz <marcin.abramowicz@jetbrains.com>
  • Loading branch information
abrams27 authored and qodana-bot committed Feb 8, 2024
1 parent 31df73d commit 0cc0014
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,30 @@ class BazelBspServer(
val bazelRunner = BazelRunner.of(workspaceContextProvider, bspClientLogger, workspaceRoot)
val bspState = ConcurrentHashMap<String, Set<TextDocumentIdentifier>>()

compilationManager = BazelBspCompilationManager(bazelRunner, bspState)
bspServerApi = BspServerApi { bspServerData(bspInfo, workspaceContextProvider, bazelRunner, bspState) }
val bazelInfo = createBazelInfo(bspInfo, bazelRunner)
val bazelPathsResolver = BazelPathsResolver(bazelInfo)

compilationManager = BazelBspCompilationManager(bazelRunner, bazelPathsResolver, bspState)
bspServerApi = BspServerApi {
bspServerData(
bspInfo = bspInfo,
bazelInfo = bazelInfo,
workspaceContextProvider = workspaceContextProvider,
bazelRunner = bazelRunner,
bazelPathsResolver = bazelPathsResolver,
bspState = bspState
)
}
}

private fun bspServerData(
bspInfo: BspInfo,
bazelInfo: BazelInfo,
workspaceContextProvider: WorkspaceContextProvider,
bazelRunner: BazelRunner,
bazelPathsResolver: BazelPathsResolver,
bspState: Map<String, Set<TextDocumentIdentifier>>
): BazelServices {
val bazelInfo = createBazelInfo(bspInfo, bazelRunner)
val bazelPathsResolver = BazelPathsResolver(bazelInfo)
val languagePluginsService = createLanguagePluginsService(bazelPathsResolver)
val projectProvider = createProjectProvider(
bspInfo = bspInfo,
Expand Down Expand Up @@ -101,6 +113,7 @@ class BazelBspServer(
workspaceContextProvider = workspaceContextProvider,
bspClientLogger = bspClientLogger,
bspClientTestNotifier = bspClientTestNotifier,
bazelPathsResolver = bazelPathsResolver,
hasAnyProblems = bspState,
)
return BazelServices(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ kt_jvm_library(
"//commons",
"//logger",
"//server/src/main/kotlin/org/jetbrains/bsp/bazel/server/diagnostics",
"//server/src/main/kotlin/org/jetbrains/bsp/bazel/server/paths",
"@bazel_bep//jar",
"@maven//:ch_epfl_scala_bsp4j",
"@maven//:com_google_guava_guava",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jetbrains.bsp.bazel.server.bep

import com.google.common.collect.Queues
import java.net.URI
import java.nio.file.Path

class BepOutput(
private val outputGroups: Map<String, Set<String>> = emptyMap(),
Expand All @@ -12,12 +12,12 @@ class BepOutput(
return rootTargets
}

fun filesByOutputGroupNameTransitive(outputGroup: String): Set<URI> {
fun filesByOutputGroupNameTransitive(outputGroup: String): Set<Path> {
val rootIds = outputGroups.getOrDefault(outputGroup, emptySet())
if (rootIds.isEmpty()) {
return emptySet()
}
val result = HashSet<URI>(rootIds.size)
val result = HashSet<Path>(rootIds.size)
val toVisit = Queues.newArrayDeque(rootIds)
val visited = HashSet<String>(rootIds.size)
while (!toVisit.isEmpty()) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.jetbrains.bsp.bazel.server.bep

import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.NamedSetOfFiles
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.OutputGroup
import org.jetbrains.bsp.bazel.server.paths.BazelPathsResolver
import java.io.File
import java.nio.file.Path
import kotlin.io.path.Path

data class TextProtoDepSet(val files: Collection<Path>, val children: Collection<String>)

internal class BepOutputBuilder(private val bazelPathsResolver: BazelPathsResolver) {
private val outputGroups: MutableMap<String, MutableSet<String>> = HashMap()
private val textProtoFileSets: MutableMap<String, TextProtoDepSet> = HashMap()
private val rootTargets: MutableSet<String> = HashSet()

fun storeNamedSet(id: String, namedSetOfFiles: NamedSetOfFiles) {
val textProtoDepSet = TextProtoDepSet(
files = namedSetOfFiles
.filesList
.filter { it.name.endsWith("bsp-info.textproto") }
.map { it.toLocalPath() },
children = namedSetOfFiles.fileSetsList.map { it.id }
)

textProtoFileSets[id] = textProtoDepSet
}

private fun BuildEventStreamProtos.File.toLocalPath(): Path {
val mergedPathPrefix = Path(pathPrefixList.joinToString(File.separator))
val bazelOutputRelativePath = mergedPathPrefix.resolve(name)

return bazelPathsResolver.resolveOutput(bazelOutputRelativePath)
}

fun storeTargetOutputGroups(target: String, outputGroups: List<OutputGroup>) {
rootTargets.add(target)

for (group in outputGroups) {
val fileSets = group.fileSetsList.map { it.id }
this.outputGroups.computeIfAbsent(group.name) { HashSet() }.addAll(fileSets)
}
}

fun clear() {
outputGroups.clear()
textProtoFileSets.clear()
rootTargets.clear()
}

fun build(): BepOutput = BepOutput(outputGroups, textProtoFileSets, rootTargets)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.jetbrains.bsp.bazel.commons.Constants;
import org.jetbrains.bsp.bazel.commons.ExitCodeMapper;
import org.jetbrains.bsp.bazel.server.diagnostics.DiagnosticsService;
import org.jetbrains.bsp.bazel.server.paths.BazelPathsResolver;

public class BepServer extends PublishBuildEventGrpc.PublishBuildEventImplBase {

Expand All @@ -47,26 +48,28 @@ public class BepServer extends PublishBuildEventGrpc.PublishBuildEventImplBase {

private final Deque<Map.Entry<TaskId, Optional<String>>> startedEvents = new ArrayDeque<>();
private final DiagnosticsService diagnosticsService;
private BepOutputBuilder bepOutputBuilder = new BepOutputBuilder();
private final BepOutputBuilder bepOutputBuilder;

private final Optional<BuildTargetIdentifier> target;

public BepServer(
BuildClient bspClient, DiagnosticsService diagnosticsService, Optional<String> originId, Optional<BuildTargetIdentifier> target) {
BuildClient bspClient, DiagnosticsService diagnosticsService, BazelPathsResolver bazelPathsResolver, Optional<String> originId, Optional<BuildTargetIdentifier> target) {
this.bspClient = bspClient;
this.target = target;
this.diagnosticsService = diagnosticsService;
this.bepOutputBuilder = new BepOutputBuilder(bazelPathsResolver);
this.originId = originId;
this.bepLogger = new BepLogger(bspClient, originId);
}

public static BepServer newBepServer(
BuildClient client,
Path workspaceRoot,
BazelPathsResolver bazelPathsResolver,
Map<String, Set<TextDocumentIdentifier>> hasAnyProblems,
Optional<String> originId,
Optional<BuildTargetIdentifier> target) {
return new BepServer(client, new DiagnosticsService(workspaceRoot, hasAnyProblems), originId, target);
return new BepServer(client, new DiagnosticsService(workspaceRoot, hasAnyProblems), bazelPathsResolver, originId, target);
}

@Override
Expand Down Expand Up @@ -134,7 +137,8 @@ private void processBuildMetrics(BuildEventStreamProtos.BuildEvent event) {
}

private void consumeBuildStartedEvent(BuildEventStreamProtos.BuildStarted buildStarted) {
bepOutputBuilder = new BepOutputBuilder();
bepOutputBuilder.clear();

TaskId taskId = new TaskId(buildStarted.getUuid());
TaskStartParams startParams = new TaskStartParams(taskId);
startParams.setEventTime(buildStarted.getStartTimeMillis());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import ch.epfl.scala.bsp4j.TextDocumentIdentifier
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.paths.BazelPathsResolver
import org.jetbrains.bsp.bazel.workspacecontext.TargetsSpec
import java.nio.file.Path
import java.util.Optional

class BazelBspCompilationManager(
private val bazelRunner: BazelRunner,
private val bazelPathsResolver: BazelPathsResolver,
private val hasAnyProblems: Map<String, Set<TextDocumentIdentifier>>,
) {
var client: BuildClient? = null
Expand All @@ -29,7 +31,7 @@ class BazelBspCompilationManager(
environment: List<Pair<String, String>>
): BepBuildResult {
val target = targetSpecs.values.firstOrNull()
val bepServer = BepServer.newBepServer(client, workspaceRoot, hasAnyProblems, Optional.ofNullable(originId), Optional.ofNullable(target))
val bepServer = BepServer.newBepServer(client, workspaceRoot, bazelPathsResolver, hasAnyProblems, Optional.ofNullable(originId), Optional.ofNullable(target))
val bepReader = BepReader(bepServer)
return try {
bepReader.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.jetbrains.bsp.bazel.logger.BspClientTestNotifier
import org.jetbrains.bsp.bazel.server.bep.BepServer
import org.jetbrains.bsp.bazel.server.bsp.managers.BazelBspCompilationManager
import org.jetbrains.bsp.bazel.server.bsp.managers.BepReader
import org.jetbrains.bsp.bazel.server.paths.BazelPathsResolver
import org.jetbrains.bsp.bazel.server.sync.BspMappings.toBspId
import org.jetbrains.bsp.bazel.server.sync.model.Module
import org.jetbrains.bsp.bazel.server.sync.model.Tag
Expand All @@ -40,14 +41,15 @@ class ExecuteService(
private val workspaceContextProvider: WorkspaceContextProvider,
private val bspClientLogger: BspClientLogger,
private val bspClientTestNotifier: BspClientTestNotifier,
private val bazelPathsResolver: BazelPathsResolver,
private val hasAnyProblems: Map<String, Set<TextDocumentIdentifier>>
) {
private val debugRunner = DebugRunner(bazelRunner) { message, originId ->
bspClientLogger.withOriginId(originId).error(message)
}

private fun <T> withBepServer(body : (BepReader) -> T): T {
val server = BepServer.newBepServer(compilationManager.client, compilationManager.workspaceRoot, hasAnyProblems, Optional.empty(), Optional.empty())
val server = BepServer.newBepServer(compilationManager.client, compilationManager.workspaceRoot, bazelPathsResolver, hasAnyProblems, Optional.empty(), Optional.empty())
val bepReader = BepReader(server)
return body(bepReader)
}
Expand Down
Loading

0 comments on commit 0cc0014

Please sign in to comment.