@@ -18,15 +18,22 @@ import TSCUtility
18
18
19
19
var intHandler : InterruptHandler ?
20
20
let diagnosticsEngine = DiagnosticsEngine ( handlers: [ Driver . stderrDiagnosticsHandler] )
21
+ var driverInterrupted = false
22
+ func getExitCode( _ code: Int32 ) -> Int32 {
23
+ if driverInterrupted {
24
+ return ( SIGINT | 0x80 )
25
+ }
26
+ return code
27
+ }
21
28
22
29
do {
30
+
23
31
let processSet = ProcessSet ( )
24
32
intHandler = try InterruptHandler {
25
- // Ignore the interruption signal.
26
- // The underlying swift compiler isn't ready to be safely interrupted yet and
27
- // interrupting them may cause red-herring build failures that may pollute the build
28
- // log.
29
- diagnosticsEngine. emit ( . remark( " Compilation process interrupted " ) )
33
+ // Terminate running compiler jobs and let the driver exit gracefully, remembering
34
+ // to return a corresponding exit code when done.
35
+ processSet. terminate ( )
36
+ driverInterrupted = true
30
37
}
31
38
32
39
if ProcessEnv . vars [ " SWIFT_ENABLE_EXPLICIT_MODULE " ] != nil {
57
64
diagnosticsEngine: diagnosticsEngine,
58
65
executor: executor,
59
66
integratedDriver: false )
67
+
60
68
// FIXME: The following check should be at the end of Driver.init, but current
61
69
// usage of the DiagnosticVerifier in tests makes this difficult.
62
70
guard !driver. diagnosticEngine. hasErrors else { throw Diagnostics . fatalError }
65
73
try driver. run ( jobs: jobs)
66
74
67
75
if driver. diagnosticEngine. hasErrors {
68
- exit ( EXIT_FAILURE)
76
+ exit ( getExitCode ( EXIT_FAILURE) )
69
77
}
78
+ exit ( getExitCode ( 0 ) )
70
79
} catch Diagnostics . fatalError {
71
- exit ( EXIT_FAILURE)
80
+ exit ( getExitCode ( EXIT_FAILURE) )
72
81
} catch let diagnosticData as DiagnosticData {
73
82
diagnosticsEngine. emit ( . error( diagnosticData) )
74
- exit ( EXIT_FAILURE)
83
+ exit ( getExitCode ( EXIT_FAILURE) )
75
84
} catch {
76
85
print ( " error: \( error) " )
77
- exit ( EXIT_FAILURE)
86
+ exit ( getExitCode ( EXIT_FAILURE) )
78
87
}
0 commit comments