Skip to content

Commit 54e5973

Browse files
committed
Clean up toolchain-related property names and types, and parameter names and types, and also add comments to document what they are.
1 parent 0a2617e commit 54e5973

File tree

4 files changed

+37
-33
lines changed

4 files changed

+37
-33
lines changed

Sources/Build/describe().swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public func describe(_ prefix: AbsolutePath, _ conf: Configuration, _ graph: Pac
3232
try makeDirectories(prefix)
3333
let swiftcArgs = flags.cCompilerFlags.flatMap{ ["-Xcc", $0] } + flags.swiftCompilerFlags + verbosity.ccArgs
3434

35-
let SWIFT_EXEC = toolchain.SWIFT_EXEC
35+
let SWIFT_EXEC = toolchain.swiftCompiler
3636
let CC = getenv("CC") ?? "clang"
3737

3838
var commands = [Command]()
@@ -41,7 +41,7 @@ public func describe(_ prefix: AbsolutePath, _ conf: Configuration, _ graph: Pac
4141
for module in graph.modules {
4242
switch module {
4343
case let module as SwiftModule:
44-
let compile = try Command.compile(swiftModule: module, configuration: conf, prefix: prefix, otherArgs: swiftcArgs + toolchain.platformArgsSwiftc, SWIFT_EXEC: SWIFT_EXEC)
44+
let compile = try Command.compile(swiftModule: module, configuration: conf, prefix: prefix, otherArgs: swiftcArgs + toolchain.swiftPlatformArgs, SWIFT_EXEC: SWIFT_EXEC.asString)
4545
commands.append(compile)
4646
targets.append([compile], for: module)
4747

@@ -51,7 +51,7 @@ public func describe(_ prefix: AbsolutePath, _ conf: Configuration, _ graph: Pac
5151
if module.isTest { continue }
5252
#endif
5353
// FIXME: Find a way to eliminate `externalModules` from here.
54-
let compile = try Command.compile(clangModule: module, externalModules: graph.externalModules, configuration: conf, prefix: prefix, CC: CC, otherArgs: flags.cCompilerFlags + toolchain.platformArgsClang)
54+
let compile = try Command.compile(clangModule: module, externalModules: graph.externalModules, configuration: conf, prefix: prefix, CC: CC, otherArgs: flags.cCompilerFlags + toolchain.clangPlatformArgs)
5555
commands += compile
5656
targets.append(compile, for: module)
5757

@@ -76,7 +76,7 @@ public func describe(_ prefix: AbsolutePath, _ conf: Configuration, _ graph: Pac
7676
if product.containsOnlyClangModules {
7777
command = try Command.linkClangModule(product, configuration: conf, prefix: prefix, otherArgs: Xld, CC: CC)
7878
} else {
79-
command = try Command.linkSwiftModule(product, configuration: conf, prefix: prefix, otherArgs: Xld + swiftcArgs + toolchain.platformArgsSwiftc + rpathArgs, SWIFT_EXEC: SWIFT_EXEC)
79+
command = try Command.linkSwiftModule(product, configuration: conf, prefix: prefix, otherArgs: Xld + swiftcArgs + toolchain.swiftPlatformArgs + rpathArgs, SWIFT_EXEC: SWIFT_EXEC.asString)
8080
}
8181

8282
commands.append(command)

Sources/Build/misc.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@ import func POSIX.getenv
1616
import func POSIX.popen
1717

1818
public protocol Toolchain {
19-
var platformArgsClang: [String] { get }
20-
var platformArgsSwiftc: [String] { get }
21-
var sysroot: String? { get }
22-
var SWIFT_EXEC: String { get }
23-
var clang: String { get }
19+
/// Path of the `swiftc` compiler.
20+
var swiftCompiler: AbsolutePath { get }
21+
22+
/// Platform-specific arguments for Swift compiler.
23+
var swiftPlatformArgs: [String] { get }
24+
25+
/// Path of the `clang` compiler.
26+
var clangCompiler: AbsolutePath { get }
27+
28+
/// Platform-specific arguments for Clang compiler.
29+
var clangPlatformArgs: [String] { get }
30+
31+
/// Path of the default SDK (a.k.a. "sysroot"), if any.
32+
var defaultSDK: AbsolutePath? { get }
2433
}
2534

2635
extension AbsolutePath {

Sources/Commands/UserToolchain.swift

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@ import protocol Build.Toolchain
2121
#endif
2222

2323
struct UserToolchain: Toolchain {
24-
let SWIFT_EXEC: String
25-
let clang: String
26-
let sysroot: String?
24+
/// Path of the `swiftc` compiler.
25+
let swiftCompiler: AbsolutePath
26+
27+
/// Path of the `clang` compiler.
28+
let clangCompiler: AbsolutePath
29+
30+
/// Path of the default SDK (a.k.a. "sysroot"), if any.
31+
let defaultSDK: AbsolutePath?
2732

2833
#if os(macOS)
29-
var platformArgsClang: [String] {
30-
return ["-arch", "x86_64", "-mmacosx-version-min=10.10", "-isysroot", sysroot!]
34+
var clangPlatformArgs: [String] {
35+
return ["-arch", "x86_64", "-mmacosx-version-min=10.10", "-isysroot", defaultSDK!.asString]
3136
}
32-
33-
var platformArgsSwiftc: [String] {
34-
return ["-target", "x86_64-apple-macosx10.10", "-sdk", sysroot!]
37+
var swiftPlatformArgs: [String] {
38+
return ["-target", "x86_64-apple-macosx10.10", "-sdk", defaultSDK!.asString]
3539
}
3640
#else
37-
let platformArgsClang: [String] = []
38-
let platformArgsSwiftc: [String] = []
41+
let clangPlatformArgs: [String] = []
42+
let swiftPlatformArgs: [String] = []
3943
#endif
4044

4145
init() throws {
42-
let swiftCompiler: AbsolutePath
43-
let clangCompiler: AbsolutePath
44-
let defaultSDK: AbsolutePath?
45-
4646
// Find the Swift compiler, looking first in the environment.
4747
if let value = getenv("SWIFT_EXEC"), !value.isEmpty {
4848
// We have a value, but it could be an absolute or a relative path.
@@ -104,10 +104,5 @@ struct UserToolchain: Toolchain {
104104
#else
105105
defaultSDK = nil
106106
#endif
107-
108-
// Finally set the properties (we will refactor these to paths in the next diff).
109-
SWIFT_EXEC = swiftCompiler.asString
110-
clang = clangCompiler.asString
111-
sysroot = defaultSDK?.asString
112107
}
113108
}

Tests/BuildTests/DescribeTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ final class DescribeTests: XCTestCase {
2121
let dummyPackage = Package(manifest: Manifest(path: AbsolutePath("/"), url: "/", package: PackageDescription.Package(name: "Foo"), products: [], version: nil), path: AbsolutePath("/"), modules: [], testModules: [], products: [])
2222

2323
struct InvalidToolchain: Toolchain {
24-
var platformArgsClang: [String] { fatalError() }
25-
var platformArgsSwiftc: [String] { fatalError() }
26-
var sysroot: String? { fatalError() }
27-
var SWIFT_EXEC: String { fatalError() }
28-
var clang: String { fatalError() }
24+
var swiftCompiler: AbsolutePath { fatalError() }
25+
var clangCompiler: AbsolutePath { fatalError() }
26+
var defaultSDK: AbsolutePath? { fatalError() }
27+
var swiftPlatformArgs: [String] { fatalError() }
28+
var clangPlatformArgs: [String] { fatalError() }
2929
}
3030

3131
func testDescribingNoModulesThrows() {

0 commit comments

Comments
 (0)