Skip to content

Commit 0370acb

Browse files
authored
Merge pull request #7 from llvm-swift/build-experiment2
Switch to SwiftPM's Process
2 parents 02a6963 + 9f5835c commit 0370acb

File tree

4 files changed

+84
-14
lines changed

4 files changed

+84
-14
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ let package = Package(
1111
],
1212
dependencies: [
1313
.package(url: "https://github.com/onevcat/Rainbow.git", from: "3.0.0"),
14-
.package(url: "https://github.com/JohnSundell/ShellOut.git", from: "2.1.0"),
14+
.package(url: "https://github.com/apple/swift-package-manager.git", from: "0.1.0"),
1515
],
1616
targets: [
1717
.target(
1818
name: "LiteSupport",
19-
dependencies: ["Rainbow", "ShellOut"]),
19+
dependencies: ["Rainbow", "Utility"]),
2020

2121
// This needs to be named `lite-test` instead of `lite` because consumers
2222
// of `lite` should use the target name `lite`.

Sources/LiteSupport/ParallelExecutor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ final class ParallelExecutor<TaskResult> {
6060
/// Adds a task to run asynchronously on the next worker. Workers are chosen
6161
/// in a round-robin fashion.
6262
func addTask(_ work: @escaping () -> TaskResult) {
63-
queues[nextTask % queues.count].async(group: group) {
63+
queues[nextTask % queues.count].async(group: group, qos: .userInitiated) {
6464
self.addResult(work())
6565
}
6666
}

Sources/LiteSupport/TestRunner.swift

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
import Foundation
99
import Rainbow
10-
import ShellOut
10+
import Basic
11+
import Utility
12+
import POSIX
1113
import Dispatch
1214

1315
/// Specifies how to parallelize test runs.
@@ -36,7 +38,7 @@ public enum ParallelismLevel {
3638
class TestRunner {
3739

3840
/// The test directory in which tests reside.
39-
let testDir: URL
41+
let testDir: Foundation.URL
4042

4143
/// The set of substitutions to apply to each run line.
4244
let substitutor: Substitutor
@@ -92,7 +94,7 @@ class TestRunner {
9294
let enumerator = fm.enumerator(at: testDir,
9395
includingPropertiesForKeys: nil)!
9496
var files = [TestFile]()
95-
for case let file as URL in enumerator {
97+
for case let file as Foundation.URL in enumerator {
9698
guard pathExtensions.contains(file.pathExtension) else { continue }
9799
let nsPath = NSString(string: file.path)
98100
let matchesFilter = filters.contains {
@@ -250,15 +252,26 @@ class TestRunner {
250252
let exitCode: Int
251253
let bash = file.makeCommandLine(line, substitutor: substitutor)
252254
do {
253-
stdout = try shellOut(to: bash)
255+
let args = ["/bin/bash", "-c", bash]
256+
let result = try Process.popen(arguments: args)
257+
stdout = try result.utf8Output().chomp()
254258
stderr = ""
255-
exitCode = 0
256-
} catch let error as ShellOutError {
257-
stderr = error.message
258-
stdout = error.output
259-
exitCode = Int(error.terminationStatus)
259+
switch result.exitStatus {
260+
case let .terminated(code: code):
261+
exitCode = Int(code)
262+
case let .signalled(signal: code):
263+
exitCode = Int(code)
264+
}
265+
} catch let error as SystemError {
266+
stderr = error.description
267+
stdout = ""
268+
exitCode = Int(error.exitCode)
269+
} catch let error as Basic.Process.Error {
270+
stderr = error.description
271+
stdout = ""
272+
exitCode = Int(EXIT_FAILURE)
260273
} catch {
261-
fatalError("unhandled error")
274+
fatalError("\(error)")
262275
}
263276
let end = Date()
264277
results.append(TestResult(line: line,
@@ -271,3 +284,60 @@ class TestRunner {
271284
return results
272285
}
273286
}
287+
288+
extension SystemError {
289+
var exitCode: Int32 {
290+
switch self {
291+
case .chdir(let errno, _):
292+
return errno
293+
case .close(let errno):
294+
return errno
295+
case .dirfd(let errno, _):
296+
return errno
297+
case .exec(let errno, _, _):
298+
return errno
299+
case .fgetc(let errno):
300+
return errno
301+
case .fread(let errno):
302+
return errno
303+
case .getcwd(let errno):
304+
return errno
305+
case .mkdir(let errno, _):
306+
return errno
307+
case .mkdtemp(let errno):
308+
return errno
309+
case .pipe(let errno):
310+
return errno
311+
case .posix_spawn(let errno, _):
312+
return errno
313+
case .popen(let errno, _):
314+
return errno
315+
case .read(let errno):
316+
return errno
317+
case .readdir(let errno, _):
318+
return errno
319+
case .realpath(let errno, _):
320+
return errno
321+
case .rename(let errno, _, _):
322+
return errno
323+
case .rmdir(let errno, _):
324+
return errno
325+
case .setenv(let errno, _):
326+
return errno
327+
case .stat(let errno, _):
328+
return errno
329+
case .symlink(let errno, _, _):
330+
return errno
331+
case .symlinkat(let errno, _):
332+
return errno
333+
case .unlink(let errno, _):
334+
return errno
335+
case .unsetenv(let errno, _):
336+
return errno
337+
case .waitpid(let errno):
338+
return errno
339+
case .usleep(let errno):
340+
return errno
341+
}
342+
}
343+
}

Sources/lite-test/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import LiteSupport
77
/// Runs `lite` looking for `.test` files and executing them.
88
do {
99
let allPassed = try runLite(
10-
substitutions: [("echo", "echo")],
10+
substitutions: [("echo", "/bin/echo")],
1111
pathExtensions: ["test"],
1212
testDirPath: nil,
1313
testLinePrefix: "//",

0 commit comments

Comments
 (0)