diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift index b2b0125..5b9afae 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// import SystemPackage +import Foundation extension SwiftSDKGenerator { func copyTargetSwiftFromDocker( @@ -109,16 +110,20 @@ extension SwiftSDKGenerator { func copyTargetSwift(from distributionPath: FilePath, sdkDirPath: FilePath) async throws { logger.info("Copying Swift core libraries for the target triple into Swift SDK bundle...") - for (pathWithinPackage, pathWithinSwiftSDK, ignoreIfMissing) in [ + for (pathWithinPackage, pathWithinSwiftSDK, isOptional) in [ ("lib/swift", sdkDirPath.appending("usr/lib"), false), ("lib/swift_static", sdkDirPath.appending("usr/lib"), false), ("lib/clang", sdkDirPath.appending("usr/lib"), true), ("include", sdkDirPath.appending("usr"), false), ] { - try await rsync( - from: distributionPath.appending(pathWithinPackage), - to: pathWithinSwiftSDK, ignoreIfMissing: ignoreIfMissing - ) + let fromPath = distributionPath.appending(pathWithinPackage) + + if isOptional && !doesFileExist(at: fromPath) { + logger.debug("Optional package path ignored since it does not exist", metadata: ["packagePath": .string(fromPath.string)]) + continue + } + + try await rsync(from: fromPath, to: pathWithinSwiftSDK) } } } diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift index 714d054..0db1d5e 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift @@ -158,10 +158,9 @@ public actor SwiftSDKGenerator { try Data(contentsOf: URL(fileURLWithPath: path.string)) } - func rsync(from source: FilePath, to destination: FilePath, ignoreIfMissing: Bool = false) async throws { + func rsync(from source: FilePath, to destination: FilePath) async throws { try self.createDirectoryIfNeeded(at: destination) - let ignoreMissingArgs = ignoreIfMissing ? "--ignore-missing-args" : "" - try await Shell.run("rsync -a \(ignoreMissingArgs) \(source) \(destination)", shouldLogCommands: self.isVerbose) + try await Shell.run("rsync -a \(source) \(destination)", shouldLogCommands: self.isVerbose) } func rsyncContents(from source: FilePath, to destination: FilePath) async throws {