@@ -123,6 +123,44 @@ final class SwiftPMWorkspaceTests: XCTestCase {
123
123
check ( aswift. asString, arguments: arguments)
124
124
}
125
125
126
+ func testBuildSetup( ) {
127
+ // FIXME: should be possible to use InMemoryFileSystem.
128
+ let fs = localFileSystem
129
+ let tempDir = try ! TemporaryDirectory ( removeTreeOnDeinit: true )
130
+ try ! fs. createFiles ( root: tempDir. path, files: [
131
+ " pkg/Sources/lib/a.swift " : " " ,
132
+ " pkg/Package.swift " : """
133
+ // swift-tools-version:4.2
134
+ import PackageDescription
135
+ let package = Package(name: " a " , products: [], dependencies: [],
136
+ targets: [.target(name: " lib " , dependencies: [])])
137
+ """
138
+ ] )
139
+ let packageRoot = tempDir. path. appending ( component: " pkg " )
140
+ let tr = ToolchainRegistry . shared
141
+
142
+ let config = BuildSetup (
143
+ configuration: . release,
144
+ path: packageRoot. appending ( component: " non_default_build_path " ) ,
145
+ flags: BuildFlags ( xcc: [ " -m32 " ] , xcxx: [ ] , xswiftc: [ " -typecheck " ] , xlinker: [ ] ) )
146
+
147
+ let ws = try ! SwiftPMWorkspace (
148
+ workspacePath: packageRoot,
149
+ toolchainRegistry: tr,
150
+ fileSystem: fs,
151
+ buildSetup: config)
152
+
153
+ let aswift = packageRoot. appending ( components: " Sources " , " lib " , " a.swift " )
154
+ let build = buildPath ( root: packageRoot, config: config)
155
+
156
+ XCTAssertEqual ( ws. buildPath, build)
157
+ let arguments = ws. settings ( for: aswift. asURL, . swift) !. compilerArguments
158
+
159
+ check ( " -typecheck " , arguments: arguments)
160
+ check ( " -Xcc " , " -m32 " , arguments: arguments)
161
+ check ( " -O " , arguments: arguments)
162
+ }
163
+
126
164
func testManifestArgs( ) {
127
165
// FIXME: should be possible to use InMemoryFileSystem.
128
166
let fs = localFileSystem
@@ -384,18 +422,22 @@ private func check(
384
422
}
385
423
}
386
424
387
- private func buildPath( root: AbsolutePath ) -> AbsolutePath {
388
- if let absoluteBuildPath = TestSourceKitServer . buildSetup. path {
425
+ private func buildPath(
426
+ root: AbsolutePath ,
427
+ config: BuildSetup = TestSourceKitServer . buildSetup) -> AbsolutePath
428
+ {
429
+ let buildConfig = " \( config. configuration) "
430
+ if let absoluteBuildPath = config. path {
389
431
#if os(macOS)
390
- return absoluteBuildPath. appending ( components: " x86_64-apple-macosx " , " debug " )
432
+ return absoluteBuildPath. appending ( components: " x86_64-apple-macosx " , buildConfig )
391
433
#else
392
- return absoluteBuildPath. appending ( components: " x86_64-unknown-linux " , " debug " )
434
+ return absoluteBuildPath. appending ( components: " x86_64-unknown-linux " , buildConfig )
393
435
#endif
394
436
} else {
395
437
#if os(macOS)
396
- return root. appending ( components: " .build " , " x86_64-apple-macosx " , " debug " )
438
+ return root. appending ( components: " .build " , " x86_64-apple-macosx " , buildConfig )
397
439
#else
398
- return root. appending ( components: " .build " , " x86_64-unknown-linux " , " debug " )
440
+ return root. appending ( components: " .build " , " x86_64-unknown-linux " , buildConfig )
399
441
#endif
400
442
}
401
443
}
0 commit comments