in server/bazelrunner/src/main/kotlin/org/jetbrains/bazel/bazelrunner/BazelRunner.kt [129:170]
fun runBazelCommand(
command: BazelCommand,
originId: String? = null,
logProcessOutput: Boolean = true,
serverPidFuture: CompletableFuture<Long>?,
shouldLogInvocation: Boolean = true,
createdProcessIdDeferred: CompletableDeferred<Long?>? = null,
): BazelProcess {
val executionDescriptor = command.buildExecutionDescriptor()
val finishCallback = executionDescriptor.finishCallback
val processArgs = executionDescriptor.command
val processSpawner = ProcessSpawner.getInstance()
var environment = emptyMap<String, String>()
// Run needs to be handled separately because the resulting process is not run in the sandbox
if (command is BazelCommand.Run) {
environment = command.environment
logInvocation(processArgs, command.environment, workspaceRoot, originId, shouldLogInvocation = shouldLogInvocation)
} else {
logInvocation(processArgs, null, null, originId, shouldLogInvocation = shouldLogInvocation)
}
val process =
processSpawner
.spawnProcessBlocking(
command = processArgs,
environment = environment,
redirectErrorStream = false,
workDirectory = workspaceRoot.toString(),
)
createdProcessIdDeferred?.complete(process.pid)
val outputLogger = bspClientLogger.takeIf { logProcessOutput }?.copy(originId = originId)
return BazelProcess(
process,
outputLogger,
serverPidFuture,
finishCallback,
)
}