Skip to content

Commit 5181e28

Browse files
committed
[swiftpm] Add a test for deployment target option
This requires using a recent master toolchain, since the manifest is loaded using the PackageDescription library from the toolchain, not from the libSwiftPM bundled with sourcekit-lsp.
1 parent 30b7cc8 commit 5181e28

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Tests/SKSwiftPMWorkspaceTests/SwiftPMWorkspaceTests.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,37 @@ final class SwiftPMWorkspaceTests: XCTestCase {
187187
checkNot(bcxx.asString, arguments: arguments)
188188
check("-o", build.appending(components: "lib.build", "a.cpp.o").asString, arguments: arguments)
189189
}
190+
191+
func testDeploymentTargetSwift() {
192+
// FIXME: should be possible to use InMemoryFileSystem.
193+
let fs = localFileSystem
194+
let tempDir = try! TemporaryDirectory(removeTreeOnDeinit: true)
195+
try! fs.createFiles(root: tempDir.path, files: [
196+
"pkg/Sources/lib/a.swift": "",
197+
"pkg/Package.swift": """
198+
// swift-tools-version:5.0
199+
import PackageDescription
200+
let package = Package(name: "a",
201+
platforms: [.macOS(.v10_13)],
202+
products: [], dependencies: [],
203+
targets: [.target(name: "lib", dependencies: [])])
204+
"""
205+
])
206+
let packageRoot = tempDir.path.appending(component: "pkg")
207+
let ws = try! SwiftPMWorkspace(
208+
workspacePath: packageRoot,
209+
toolchainRegistry: ToolchainRegistry.shared,
210+
fileSystem: fs)!
211+
212+
let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift")
213+
let arguments = ws.settings(for: aswift.asURL, language: .swift)!.compilerArguments
214+
check("-target", arguments: arguments) // Only one!
215+
#if os(macOS)
216+
check("-target", "x86_64-apple-macosx10.13", arguments: arguments)
217+
#else
218+
check("-target", "x86_64-unknown-linux", arguments: arguments)
219+
#endif
220+
}
190221
}
191222

192223
private func checkNot(

Tests/SKSwiftPMWorkspaceTests/XCTestManifests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
import XCTest
33

44
extension SwiftPMWorkspaceTests {
5-
// DO NOT MODIFY: This is autogenerated, use:
5+
// DO NOT MODIFY: This is autogenerated, use:
66
// `swift test --generate-linuxmain`
77
// to regenerate.
88
static let __allTests__SwiftPMWorkspaceTests = [
99
("testBasicCXXArgs", testBasicCXXArgs),
1010
("testBasicSwiftArgs", testBasicSwiftArgs),
11+
("testDeploymentTargetSwift", testDeploymentTargetSwift),
1112
("testMultiFileSwift", testMultiFileSwift),
1213
("testMultiTargetSwift", testMultiTargetSwift),
1314
]

0 commit comments

Comments
 (0)