Skip to content

SKCore: allow non python build servers #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions Sources/SKCore/BuildServerBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,20 @@ public final class BuildServerBuildSystem {
}

private func initializeBuildServer() throws {
guard let interpreter =
lookupExecutablePath(filename: executable("python3"),
searchPaths: searchPaths) ??
lookupExecutablePath(filename: executable("python"),
searchPaths: searchPaths) else {
throw BuildServerTestError.executableNotFound("python3")
var serverPath = AbsolutePath(serverConfig.argv[0], relativeTo: projectRoot)
var flags = Array(serverConfig.argv[1...])
if serverPath.suffix == ".py" {
flags = [serverPath.pathString] + flags
guard let interpreterPath =
lookupExecutablePath(filename: executable("python3"),
searchPaths: searchPaths) ??
lookupExecutablePath(filename: executable("python"),
searchPaths: searchPaths) else {
throw BuildServerTestError.executableNotFound("python3")
}

serverPath = interpreterPath
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't realize that this was in SKCore, this makes sense. I thought that this was a test-only method, which would be fine to assume that the build server would never be an executable.

let flags = [AbsolutePath(serverConfig.argv[0], relativeTo: projectRoot).pathString] + Array(serverConfig.argv[1...])
let languages = [
Language.c,
Language.cpp,
Expand All @@ -141,7 +147,7 @@ public final class BuildServerBuildSystem {
capabilities: BuildClientCapabilities(languageIds: languages))

let handler = BuildServerHandler()
let buildServer = try makeJSONRPCBuildServer(client: handler, interpreter: interpreter, serverFlags: flags)
let buildServer = try makeJSONRPCBuildServer(client: handler, serverPath: serverPath, serverFlags: flags)
let response = try buildServer.sendSync(initializeRequest)
buildServer.send(InitializedBuildNotification())
log("initialized build server \(response.displayName)")
Expand Down Expand Up @@ -306,7 +312,7 @@ struct BuildServerConfig: Codable {
let argv: [String]
}

private func makeJSONRPCBuildServer(client: MessageHandler, interpreter: AbsolutePath, serverFlags: [String]?) throws -> JSONRPCConnection {
private func makeJSONRPCBuildServer(client: MessageHandler, serverPath: AbsolutePath, serverFlags: [String]?) throws -> JSONRPCConnection {
let clientToServer = Pipe()
let serverToClient = Pipe()

Expand All @@ -322,7 +328,7 @@ private func makeJSONRPCBuildServer(client: MessageHandler, interpreter: Absolut
withExtendedLifetime((clientToServer, serverToClient)) {}
}
let process = Foundation.Process()
process.executableURL = interpreter.asURL
process.executableURL = serverPath.asURL
process.arguments = serverFlags
process.standardOutput = serverToClient
process.standardInput = clientToServer
Expand Down