From c30560ae9e523a4b8981afd6de17e5a264832b50 Mon Sep 17 00:00:00 2001 From: "Jesse L. Zamora" Date: Fri, 14 Feb 2025 09:56:32 -0500 Subject: [PATCH 1/3] Remove --ignore-if-missing, replace with local check before rsync for optional path --- .../Generator/SwiftSDKGenerator+Copy.swift | 15 ++++++++++----- .../Generator/SwiftSDKGenerator.swift | 5 ++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift index b2b0125..6feaf94 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, optional) 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 optional && !FileManager.default.fileExists(atPath: fromPath.string) { + 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 { From f64c9d68b5247174628becc61cf336f8987ce875 Mon Sep 17 00:00:00 2001 From: "Jesse L. Zamora" Date: Fri, 14 Feb 2025 10:10:35 -0500 Subject: [PATCH 2/3] Replace optional with isOptional in new code - optional is also a keyword --- .../SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift index 6feaf94..9987f8d 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift @@ -110,7 +110,7 @@ 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, optional) 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), @@ -118,7 +118,7 @@ extension SwiftSDKGenerator { ] { let fromPath = distributionPath.appending(pathWithinPackage) - if optional && !FileManager.default.fileExists(atPath: fromPath.string) { + if isOptional && !FileManager.default.fileExists(atPath: fromPath.string) { logger.debug("Optional package path ignored since it does not exist", metadata: ["packagePath": .string(fromPath.string)]) continue } From 19f85d2906d7f18a42b17de6aceb26bc3abd44bd Mon Sep 17 00:00:00 2001 From: "Jesse L. Zamora" Date: Fri, 14 Feb 2025 15:48:42 -0500 Subject: [PATCH 3/3] Use doesFileExist() method from SwiftSDKGenerator --- .../SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift index 9987f8d..5b9afae 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift @@ -118,7 +118,7 @@ extension SwiftSDKGenerator { ] { let fromPath = distributionPath.appending(pathWithinPackage) - if isOptional && !FileManager.default.fileExists(atPath: fromPath.string) { + if isOptional && !doesFileExist(at: fromPath) { logger.debug("Optional package path ignored since it does not exist", metadata: ["packagePath": .string(fromPath.string)]) continue }