@@ -35,6 +35,7 @@ package import struct BuildServerProtocol.SourceItem
3535import struct TSCBasic. AbsolutePath
3636import class TSCBasic. Process
3737package import class ToolchainRegistry. Toolchain
38+ import struct TSCBasic. FileSystemError
3839
3940private typealias AbsolutePath = Basics . AbsolutePath
4041
@@ -351,22 +352,36 @@ package actor SwiftPMBuildServer: BuiltInBuildServer {
351352 description: " Create SwiftPM build description "
352353 )
353354 )
354- } catch let error as NSError {
355- #if os(Windows)
356- if error. domain == NSCocoaErrorDomain, error. code == CocoaError . fileWriteNoPermission. rawValue,
357- let url = error. userInfo [ " NSURL " ] as? URL , url. lastPathComponent == " output-file-map.json " ,
358- loadAttempt < maxLoadAttempts
355+ } catch {
356+ guard SwiftExtensions . Platform. current == . windows else {
357+ // We only retry loading the build description on Windows. The output-file-map issue does not exist on other
358+ // platforms.
359+ throw error
360+ }
361+ let isOutputFileMapWriteError : Bool
362+ let nsError = error as NSError
363+ if nsError. domain == NSCocoaErrorDomain,
364+ nsError. code == CocoaError . fileWriteNoPermission. rawValue,
365+ ( nsError. userInfo [ " NSURL " ] as? URL ) ? . lastPathComponent == " output-file-map.json "
366+ {
367+ isOutputFileMapWriteError = true
368+ } else if let error = error as? FileSystemError ,
369+ error. kind == . invalidAccess && error. path? . basename == " output-file-map.json "
359370 {
371+ isOutputFileMapWriteError = true
372+ } else {
373+ isOutputFileMapWriteError = false
374+ }
375+ if isOutputFileMapWriteError, loadAttempt < maxLoadAttempts {
360376 logger. log (
361377 """
362378 Loading the build description failed to write output-file-map.json \
363379 (attempt \( loadAttempt) / \( maxLoadAttempts) ), trying again.
364- \( error)
380+ \( error. forLogging )
365381 """
366382 )
367383 continue
368384 }
369- #endif
370385 throw error
371386 }
372387 }
0 commit comments