10
10
11
11
import Foundation
12
12
import Testing
13
- import TSCBasic
14
- import TSCTestSupport
13
+ import Basics
14
+ import struct TSCBasic. ProcessResult
15
+ import class TSCBasic. Process
15
16
import enum TSCUtility. Git
16
17
17
- public let sdkRoot : AbsolutePath ? = {
18
+ fileprivate let sdkRoot : AbsolutePath ? = {
18
19
if let environmentPath = ProcessInfo . processInfo. environment [ " SDK_ROOT " ] {
19
20
return try ! AbsolutePath ( validating: environmentPath)
20
21
}
@@ -28,7 +29,7 @@ public let sdkRoot: AbsolutePath? = {
28
29
#endif
29
30
} ( )
30
31
31
- public let toolchainPath : AbsolutePath = {
32
+ fileprivate let toolchainPath : AbsolutePath = {
32
33
if let environmentPath = ProcessInfo . processInfo. environment [ " TOOLCHAIN_PATH " ] {
33
34
return try ! AbsolutePath ( validating: environmentPath)
34
35
}
@@ -55,7 +56,7 @@ public let clang: AbsolutePath = {
55
56
return clangPath
56
57
} ( )
57
58
58
- public let xcodebuild : AbsolutePath = {
59
+ fileprivate let xcodebuild : AbsolutePath = {
59
60
#if os(macOS)
60
61
let xcodebuildPath = try ! AbsolutePath (
61
62
validating: sh ( " xcrun " , " --find " , " xcodebuild " ) . stdout. spm_chomp ( )
@@ -84,42 +85,46 @@ public let swiftc: AbsolutePath = {
84
85
return swiftcPath
85
86
} ( )
86
87
87
- public let lldb : AbsolutePath = {
88
- if let environmentPath = ProcessInfo . processInfo. environment [ " LLDB_PATH " ] {
89
- return try ! AbsolutePath ( validating: environmentPath)
90
- }
88
+ // public let lldb: AbsolutePath = {
89
+ // if let environmentPath = ProcessInfo.processInfo.environment["LLDB_PATH"] {
90
+ // return try! AbsolutePath(validating: environmentPath)
91
+ // }
91
92
92
- // We check if it exists because lldb doesn't exist in Xcode's default toolchain.
93
- let toolchainLLDBPath = toolchainPath. appending ( components: " usr " , " bin " , " lldb " )
94
- if localFileSystem. exists ( toolchainLLDBPath) {
95
- return toolchainLLDBPath
96
- }
93
+ // // We check if it exists because lldb doesn't exist in Xcode's default toolchain.
94
+ // let toolchainLLDBPath = toolchainPath.appending(components: "usr", "bin", "lldb")
95
+ // if localFileSystem.exists(toolchainLLDBPath) {
96
+ // return toolchainLLDBPath
97
+ // }
97
98
98
- #if os(macOS)
99
- let lldbPath = try ! AbsolutePath (
100
- validating: sh ( " xcrun " , " --find " , " lldb " ) . stdout. spm_chomp ( )
101
- )
102
- return lldbPath
103
- #else
104
- fatalError ( " LLDB_PATH environment variable required " )
105
- #endif
106
- } ( )
99
+ // #if os(macOS)
100
+ // let lldbPath = try! AbsolutePath(
101
+ // validating: sh("xcrun", "--find", "lldb").stdout.spm_chomp()
102
+ // )
103
+ // return lldbPath
104
+ // #else
105
+ // fatalError("LLDB_PATH environment variable required")
106
+ // #endif
107
+ // }()
107
108
108
- public let swiftpmBinaryDirectory : AbsolutePath = {
109
- if let environmentPath = ProcessInfo . processInfo. environment [ " SWIFTPM_BIN_DIR " ] {
110
- return try ! AbsolutePath ( validating: environmentPath)
111
- }
112
109
113
- return swift. parentDirectory
114
- } ( )
115
110
116
- public let swiftBuild : AbsolutePath = swiftpmBinaryDirectory. appending ( component: " swift-build " )
111
+ // public let swiftpmBinaryDirectory: AbsolutePath = {
112
+ // let envVarName = "SWIFTPM_BIN_DIR"
113
+ // if let environmentPath = ProcessInfo.processInfo.environment[envVarName] {
114
+ // return try! AbsolutePath(validating: environmentPath)
115
+ // }
116
+
117
+ // // throw TestConfigurationErrors.EnvironmentVariableNotSet(name: envVarName)
118
+ // return AbsolutePath("\(envVarName) was not set")
119
+ // }()
117
120
118
- public let swiftPackage : AbsolutePath = swiftpmBinaryDirectory. appending ( component: " swift-package " )
121
+ // public let swiftBuild : AbsolutePath = swiftpmBinaryDirectory.appending(component: "swift-build ")
119
122
120
- public let swiftTest : AbsolutePath = swiftpmBinaryDirectory. appending ( component: " swift-test " )
123
+ // public let swiftPackage : AbsolutePath = swiftpmBinaryDirectory.appending(component: "swift-package ")
121
124
122
- public let swiftRun : AbsolutePath = swiftpmBinaryDirectory. appending ( component: " swift-run " )
125
+ // public let swiftTest: AbsolutePath = swiftpmBinaryDirectory.appending(component: "swift-test")
126
+
127
+ // public let swiftRun: AbsolutePath = swiftpmBinaryDirectory.appending(component: "swift-run")
123
128
124
129
public let isSelfHosted : Bool = {
125
130
ProcessInfo . processInfo. environment [ " SWIFTCI_IS_SELF_HOSTED " ] != nil
@@ -192,127 +197,8 @@ public func _sh(
192
197
return result
193
198
}
194
199
195
- /// Test-helper function that runs a block of code on a copy of a test fixture
196
- /// package. The copy is made into a temporary directory, and the block is
197
- /// given a path to that directory. The block is permitted to modify the copy.
198
- /// The temporary copy is deleted after the block returns. The fixture name may
199
- /// contain `/` characters, which are treated as path separators, exactly as if
200
- /// the name were a relative path.
201
- public func fixture(
202
- name: String ,
203
- file: StaticString = #file,
204
- line: UInt = #line,
205
- body: ( AbsolutePath ) throws -> Void
206
- ) {
207
- do {
208
- // Make a suitable test directory name from the fixture subpath.
209
- let fixtureSubpath = try RelativePath ( validating: name)
210
- let copyName = fixtureSubpath. components. joined ( separator: " _ " )
211
-
212
- // Create a temporary directory for the duration of the block.
213
- try withTemporaryDirectory ( prefix: copyName) { tmpDirPath in
214
-
215
- defer {
216
- // Unblock and remove the tmp dir on deinit.
217
- try ? localFileSystem. chmod ( . userWritable, path: tmpDirPath, options: [ . recursive] )
218
- try ? localFileSystem. removeFileTree ( tmpDirPath)
219
- }
220
-
221
- // Construct the expected path of the fixture.
222
- // FIXME: This seems quite hacky; we should provide some control over where fixtures are found.
223
- let fixtureDir = try AbsolutePath (
224
- validating: " ../../../Fixtures/ \( name) " ,
225
- relativeTo: AbsolutePath ( validating: #file)
226
- )
227
-
228
- // Check that the fixture is really there.
229
- guard localFileSystem. isDirectory ( fixtureDir) else {
230
- Issue . record ( Comment ( " No such fixture: \( fixtureDir) " ) )
231
- return
232
- }
233
-
234
- // The fixture contains either a checkout or just a Git directory.
235
- if localFileSystem. isFile ( fixtureDir. appending ( component: " Package.swift " ) ) {
236
- // It's a single package, so copy the whole directory as-is.
237
- let dstDir = tmpDirPath. appending ( component: copyName)
238
- #if os(Windows)
239
- try localFileSystem. copy ( from: fixtureDir, to: dstDir)
240
- #else
241
- try systemQuietly ( " cp " , " -R " , " -H " , fixtureDir. pathString, dstDir. pathString)
242
- #endif
243
-
244
- // Invoke the block, passing it the path of the copied fixture.
245
- try body ( dstDir)
246
- } else {
247
- // Copy each of the package directories and construct a git repo in it.
248
- for fileName in try ! localFileSystem. getDirectoryContents ( fixtureDir) . sorted ( ) {
249
- let srcDir = fixtureDir. appending ( component: fileName)
250
- guard localFileSystem. isDirectory ( srcDir) else { continue }
251
- let dstDir = tmpDirPath. appending ( component: fileName)
252
- #if os(Windows)
253
- try localFileSystem. copy ( from: srcDir, to: dstDir)
254
- #else
255
- try systemQuietly ( " cp " , " -R " , " -H " , srcDir. pathString, dstDir. pathString)
256
- #endif
257
- initGitRepo ( dstDir, tag: " 1.2.3 " , addFile: false )
258
- }
259
-
260
- // Invoke the block, passing it the path of the copied fixture.
261
- try body ( tmpDirPath)
262
- }
263
- }
264
- } catch {
265
- Issue . record ( error)
266
- }
267
- }
268
-
269
- /// Test-helper function that creates a new Git repository in a directory. The new repository will contain
270
- /// exactly one empty file unless `addFile` is `false`, and if a tag name is provided, a tag with that name will be
271
- /// created.
272
- public func initGitRepo(
273
- _ dir: AbsolutePath ,
274
- tag: String ? = nil ,
275
- addFile: Bool = true ,
276
- file: StaticString = #file,
277
- line: UInt = #line
278
- ) {
279
- initGitRepo ( dir, tags: tag. flatMap { [ $0] } ?? [ ] , addFile: addFile, file: file, line: line)
280
- }
281
-
282
- public func initGitRepo(
283
- _ dir: AbsolutePath ,
284
- tags: [ String ] ,
285
- addFile: Bool = true ,
286
- file: StaticString = #file,
287
- line: UInt = #line
288
- ) {
289
- do {
290
- if addFile {
291
- let file = dir. appending ( component: " file.swift " )
292
- try localFileSystem. writeFileContents ( file, bytes: " " )
293
- }
294
-
295
- try systemQuietly ( [ Git . tool, " -C " , dir. pathString, " init " ] )
296
- try systemQuietly ( [
297
- Git . tool
, " -C " , dir
. pathString
, " config " , " user.email " , " [email protected] " ,
298
- ] )
299
- try systemQuietly ( [
300
- Git . tool, " -C " , dir. pathString, " config " , " user.name " , " Example Example " ,
301
- ] )
302
- try systemQuietly ( [ Git . tool, " -C " , dir. pathString, " config " , " commit.gpgsign " , " false " ] )
303
- try systemQuietly ( [ Git . tool, " -C " , dir. pathString, " add " , " . " ] )
304
- try systemQuietly ( [ Git . tool, " -C " , dir. pathString, " commit " , " -m " , " Add some files. " ] )
305
-
306
- for tag in tags {
307
- try systemQuietly ( [ Git . tool, " -C " , dir. pathString, " tag " , tag] )
308
- }
309
- } catch {
310
- Issue . record ( error)
311
- }
312
- }
313
-
314
- public func binaryTargetsFixture( _ closure: ( AbsolutePath ) throws -> Void ) throws {
315
- fixture ( name: " BinaryTargets " ) { fixturePath in
200
+ public func binaryTargetsFixture< T> ( _ closure: ( AbsolutePath ) async throws -> T ) async throws {
201
+ try await fixture ( name: " BinaryTargets " ) { fixturePath in
316
202
let inputsPath = fixturePath. appending ( component: " Inputs " )
317
203
let packagePath = fixturePath. appending ( component: " TestBinary " )
318
204
@@ -369,7 +255,7 @@ public func binaryTargetsFixture(_ closure: (AbsolutePath) throws -> Void) throw
369
255
)
370
256
}
371
257
372
- try closure ( packagePath)
258
+ return try await closure ( packagePath)
373
259
}
374
260
}
375
261
0 commit comments