@@ -35,6 +35,7 @@ package import struct BuildServerProtocol.SourceItem
35
35
import struct TSCBasic. AbsolutePath
36
36
import class TSCBasic. Process
37
37
package import class ToolchainRegistry. Toolchain
38
+ import struct TSCBasic. FileSystemError
38
39
39
40
private typealias AbsolutePath = Basics . AbsolutePath
40
41
@@ -351,22 +352,36 @@ package actor SwiftPMBuildServer: BuiltInBuildServer {
351
352
description: " Create SwiftPM build description "
352
353
)
353
354
)
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 "
359
370
{
371
+ isOutputFileMapWriteError = true
372
+ } else {
373
+ isOutputFileMapWriteError = false
374
+ }
375
+ if isOutputFileMapWriteError, loadAttempt < maxLoadAttempts {
360
376
logger. log (
361
377
"""
362
378
Loading the build description failed to write output-file-map.json \
363
379
(attempt \( loadAttempt) / \( maxLoadAttempts) ), trying again.
364
- \( error)
380
+ \( error. forLogging )
365
381
"""
366
382
)
367
383
continue
368
384
}
369
- #endif
370
385
throw error
371
386
}
372
387
}
0 commit comments