Skip to content

Commit 0ae3d80

Browse files
committed
Fix Windows build failure
Windows has `ProcessResult.ExitStatus.abnormal` instead of ` `ProcessResult.ExitStatus.signalled`
1 parent a6a76c6 commit 0ae3d80

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

Sources/SKSupport/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_library(SKSupport STATIC
1414
Process+WaitUntilExitWithCancellation.swift
1515
Random.swift
1616
Result.swift
17+
SwitchableProcessResultExitStatus.swift
1718
ThreadSafeBox.swift
1819
WorkspaceType.swift
1920
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// We need to import all of TSCBasic because otherwise we can't refer to Process.ExitStatus (rdar://127577691)
14+
import struct TSCBasic.ProcessResult
15+
16+
/// Same as `ProcessResult.ExitStatus` in tools-support-core but has the same cases on all platforms and is thus easier
17+
/// to switch over
18+
public enum SwitchableProcessResultExitStatus {
19+
/// The process was terminated normally with a exit code.
20+
case terminated(code: Int32)
21+
/// The process was terminated abnormally.
22+
case abnormal(exception: UInt32)
23+
/// The process was terminated due to a signal.
24+
case signalled(signal: Int32)
25+
}
26+
27+
extension ProcessResult.ExitStatus {
28+
public var exhaustivelySwitchable: SwitchableProcessResultExitStatus {
29+
#if os(Windows)
30+
switch self {
31+
case .terminated(let code):
32+
return .terminated(code: code)
33+
case .abnormal(let exception):
34+
return .abnormal(exception: exception)
35+
}
36+
#else
37+
switch self {
38+
case .terminated(let code):
39+
return .terminated(code: code)
40+
case .signalled(let signal):
41+
return .signalled(signal: signal)
42+
}
43+
#endif
44+
}
45+
}

Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Foundation
1515
import LSPLogging
1616
import LanguageServerProtocol
1717
import SKCore
18+
import SKSupport
1819

1920
import struct TSCBasic.AbsolutePath
2021
import class TSCBasic.Process
@@ -198,7 +199,7 @@ public struct UpdateIndexStoreTaskDescription: TaskDescriptionProtocol {
198199
}
199200
try process.launch()
200201
let result = try await process.waitUntilExitSendingSigIntOnTaskCancellation()
201-
switch result.exitStatus {
202+
switch result.exitStatus.exhaustivelySwitchable {
202203
case .terminated(code: 0):
203204
break
204205
case .terminated(code: let code):
@@ -224,6 +225,11 @@ public struct UpdateIndexStoreTaskDescription: TaskDescriptionProtocol {
224225
logger.error("Updating index store for Swift file \(uri.forLogging) signaled \(signal)")
225226
BuildSettingsLogger.log(level: .error, settings: buildSettings, for: uri)
226227
}
228+
case .abnormal(exception: let exception):
229+
if !Task.isCancelled {
230+
logger.error("Updating index store for Swift file \(uri.forLogging) exited abnormally \(exception)")
231+
BuildSettingsLogger.log(level: .error, settings: buildSettings, for: uri)
232+
}
227233
}
228234
}
229235
}

0 commit comments

Comments
 (0)