Skip to content

Commit 2202398

Browse files
committed
[test] DependenciesScanner: running shell commands via a python script instead from Swift
Running shell commands using Swift in simulator tests is hard. We change the mechanism so that BuildModulesFromGraph.swift prints command line arguments and a simple python script picks these arguments and actually runs the command.
1 parent cb3f278 commit 2202398

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

test/ScanDependencies/Inputs/BuildModulesFromGraph.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,11 @@ func findModuleBuildingCommand(_ moduleName: String) -> [String]? {
3636
return nil
3737
}
3838

39-
func run(command: String, arguments: [String] = []) -> Int32 {
40-
let process = Process()
41-
process.launchPath = command
42-
process.arguments = arguments
43-
let outputPipe = Pipe()
44-
process.standardOutput = outputPipe
45-
process.launch()
46-
process.waitUntilExit()
47-
return process.terminationStatus
48-
}
49-
5039
if let command = findModuleBuildingCommand(moduleName) {
51-
exit(run(command: swiftPath, arguments: command))
40+
var result = swiftPath
41+
command.forEach { result += " \($0)"}
42+
print(result)
43+
exit(0)
5244
} else {
5345
fatalError("cannot find module building commands for \(moduleName)")
5446
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/python
2+
3+
import subprocess
4+
import sys
5+
6+
for line in sys.stdin:
7+
subprocess.check_call(line.split())

test/ScanDependencies/module_deps.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222
// RUN: %target-build-swift %S/Inputs/ModuleDependencyGraph.swift %t/BuildModules/main.swift -o %t/ModuleBuilder
2323
// RUN: %target-codesign %t/ModuleBuilder
2424

25-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path A.pcm
25+
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path A.pcm | %S/Inputs/CommandRunner.py
2626
// RUN: ls %t/clang-module-cache/A-*.pcm
27-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path B.pcm
27+
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path B.pcm | %S/Inputs/CommandRunner.py
2828
// RUN: ls %t/clang-module-cache/B-*.pcm
29-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path C.pcm
29+
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path C.pcm | %S/Inputs/CommandRunner.py
3030
// RUN: ls %t/clang-module-cache/C-*.pcm
31-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path A.swiftmodule
31+
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path A.swiftmodule | %S/Inputs/CommandRunner.py
3232
// RUN: ls %t/clang-module-cache/A-*.swiftmodule
33-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path E.swiftmodule
33+
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path E.swiftmodule | %S/Inputs/CommandRunner.py
3434
// RUN: ls %t/clang-module-cache/E-*.swiftmodule
35-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path F.swiftmodule
35+
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path F.swiftmodule | %S/Inputs/CommandRunner.py
3636
// RUN: ls %t/clang-module-cache/F-*.swiftmodule
37-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path G.swiftmodule
37+
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path G.swiftmodule | %S/Inputs/CommandRunner.py
3838
// RUN: ls %t/clang-module-cache/G-*.swiftmodule
3939

4040
// REQUIRES: executable_test

0 commit comments

Comments
 (0)