Skip to content

Commit 80951b9

Browse files
committed
Change configuration build path to be absolute
While specifying the build path relative to something might be a useful idea in principle, we would need a clearer story for how it is specified and resolved. When passing a path to a command-line argument, it should be resolved relative to the CWD, not to the package root by default. Incidentally, it doesn't really make sense to have a global default, since different build systems are likely to want different defaults. For now, simplify this configuration to an optional absolute path (passing a relative path on the command line will resolve relative to the CWD). Each build system can interpret `nil` as its preferred default.
1 parent 8b69fad commit 80951b9

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

Sources/SKCore/BuildSetup.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Basic
1314
import Utility
1415
import SKSupport
1516

@@ -18,19 +19,19 @@ public struct BuildSetup {
1819

1920
/// Default configuration
2021
public static let `default` = BuildSetup(configuration: .debug,
21-
path: ".build",
22+
path: nil,
2223
flags: BuildFlags())
2324

24-
/// Build configuration
25+
/// Build configuration (debug|release).
2526
public let configuration: BuildConfiguration
2627

27-
/// Build artefacts directory path
28-
public let path: String
28+
/// Build artefacts directory path. If nil, the build system may choose a default value.
29+
public let path: AbsolutePath?
2930

3031
/// Additional build flags
3132
public let flags: BuildFlags
3233

33-
public init(configuration: BuildConfiguration, path: String, flags: BuildFlags) {
34+
public init(configuration: BuildConfiguration, path: AbsolutePath?, flags: BuildFlags) {
3435
self.configuration = configuration
3536
self.path = path
3637
self.flags = flags

Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,7 @@ public final class SwiftPMWorkspace {
113113
swiftPMToolchain.extraSwiftCFlags = extraSwiftFlags
114114
swiftPMToolchain.extraCPPFlags = extraClangFlags
115115

116-
117-
let buildPath: AbsolutePath
118-
if let absoluteBuildPath = try? AbsolutePath(validating: buildSetup.path) {
119-
buildPath = absoluteBuildPath
120-
} else {
121-
buildPath = packageRoot.appending(component: buildSetup.path)
122-
}
116+
let buildPath: AbsolutePath = buildSetup.path ?? packageRoot.appending(component: ".build")
123117

124118
self.workspace = Workspace(
125119
dataPath: buildPath,

Sources/SKTestSupport/TestServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct TestSourceKitServer {
3535
}
3636

3737
public static let buildSetup: BuildSetup = BuildSetup(configuration: .debug,
38-
path: ".build",
38+
path: nil,
3939
flags: BuildFlags())
4040

4141
public let client: TestClient

Sources/sourcekit-lsp/main.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import SKSupport
1717
import SKCore
1818
import SPMLibc
1919
import Dispatch
20+
import Basic
2021
import Utility
2122
import Foundation
2223
import sourcekitd // Not needed here, but fixes debugging...
@@ -26,7 +27,7 @@ func parseArguments() throws -> BuildSetup {
2627
let parser = ArgumentParser(usage: "[options]", overview: "Language Server Protocol implementation for Swift and C-based languages")
2728
let loggingOption = parser.add(option: "--log-level", kind: LogLevel.self, usage: "Set the logging level (debug|info|warning|error) [default: \(LogLevel.default)]")
2829
let buildConfigurationOption = parser.add(option: "--configuration", shortName: "-c", kind: BuildConfiguration.self, usage: "Build with configuration (debug|release) [default: debug]")
29-
let buildPathOption = parser.add(option: "--build-path", kind: String.self, usage: "Specify build/cache directory [default: ./.build]")
30+
let buildPathOption = parser.add(option: "--build-path", kind: PathArgument.self, usage: "Specify build/cache directory")
3031
let buildFlagsCc = parser.add(option: "-Xcc", kind: [String].self, strategy: .oneByOne, usage: "Pass flag through to all C compiler invocations")
3132
let buildFlagsCxx = parser.add(option: "-Xcxx", kind: [String].self, strategy: .oneByOne, usage: "Pass flag through to all C++ compiler invocations")
3233
let buildFlagsLinker = parser.add(option: "-Xlinker", kind: [String].self, strategy: .oneByOne, usage: "Pass flag through to all linker invocations")
@@ -46,9 +47,10 @@ func parseArguments() throws -> BuildSetup {
4647
Logger.shared.setLogLevel(environmentVariable: "SOURCEKIT_LOGGING")
4748
}
4849

49-
return BuildSetup(configuration: parsedArguments.get(buildConfigurationOption) ?? BuildSetup.default.configuration,
50-
path: parsedArguments.get(buildPathOption) ?? BuildSetup.default.path,
51-
flags: buildFlags)
50+
return BuildSetup(
51+
configuration: parsedArguments.get(buildConfigurationOption) ?? BuildSetup.default.configuration,
52+
path: parsedArguments.get(buildPathOption)?.path,
53+
flags: buildFlags)
5254
}
5355

5456
let clientConnection = JSONRPCConection(inFD: STDIN_FILENO, outFD: STDOUT_FILENO, closeHandler: {

Tests/SKSwiftPMWorkspaceTests/SwiftPMWorkspaceTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,17 @@ private func check(
385385
}
386386

387387
private func buildPath(root: AbsolutePath) -> AbsolutePath {
388-
if let absoluteBuildPath = try? AbsolutePath(validating: TestSourceKitServer.buildSetup.path) {
388+
if let absoluteBuildPath = TestSourceKitServer.buildSetup.path {
389389
#if os(macOS)
390390
return absoluteBuildPath.appending(components: "x86_64-apple-macosx", "debug")
391391
#else
392392
return absoluteBuildPath.appending(components: "x86_64-unknown-linux", "debug")
393393
#endif
394394
} else {
395395
#if os(macOS)
396-
return root.appending(components: TestSourceKitServer.buildSetup.path, "x86_64-apple-macosx", "debug")
396+
return root.appending(components: ".build", "x86_64-apple-macosx", "debug")
397397
#else
398-
return root.appending(components: TestSourceKitServer.buildSetup.path, "x86_64-unknown-linux", "debug")
398+
return root.appending(components: ".build", "x86_64-unknown-linux", "debug")
399399
#endif
400400
}
401401
}

0 commit comments

Comments
 (0)