suspend fun buildTargetsWithBep()

in server/server/src/main/kotlin/org/jetbrains/bazel/server/bsp/managers/BazelBspCompilationManager.kt [23:61]


  suspend fun buildTargetsWithBep(
    targetsSpec: TargetCollection,
    extraFlags: List<String> = emptyList(),
    originId: String?,
    environment: List<Pair<String, String>> = emptyList(),
    shouldLogInvocation: Boolean,
    workspaceContext: WorkspaceContext,
  ): BepBuildResult {
    val diagnosticsService = DiagnosticsService(workspaceRoot)
    val bepServer = BepServer(client, diagnosticsService, originId, bazelPathsResolver)
    val bepReader = BepReader(bepServer)
    return try {
      coroutineScope {
        val readerFuture =
          async(Dispatchers.Default) {
            bepReader.start()
          }
        val command =
          bazelRunner.buildBazelCommand(workspaceContext) {
            build {
              options.addAll(extraFlags)
              targets.addAll(targetsSpec.values)
              excludedTargets.addAll(targetsSpec.excludedValues)
              this.environment.putAll(environment)
              useBes(bepReader.eventFile.toPath().toAbsolutePath())
            }
          }
        val result =
          bazelRunner
            .runBazelCommand(command, originId = originId, serverPidFuture = bepReader.serverPid, shouldLogInvocation = shouldLogInvocation)
            .waitAndGetResult(true)
        bepReader.finishBuild()
        readerFuture.await()
        BepBuildResult(result, bepServer.bepOutput)
      }
    } finally {
      bepReader.finishBuild()
    }
  }