From ad0d8c24dc9041512df67bea4767088f0f67cbb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helge=20He=C3=9F?= Date: Thu, 3 Oct 2024 17:46:17 +0200 Subject: [PATCH] Fix issue 27: .sql/.db could not be marked as a resource in Xcode This bug was introduced due to a fix in apparently Xcode 15.4. Previous versions of Xcode would not copy the resource into the target, hence Enlighter did that part. This seems to be fixed in Xcode now, so it ends up with duplicate resource files. Only fixed that for Xcode 16. Note: If the resource is required in an existing project, this will now need to mark the resource as a copy-resource again in Xcode 16+. --- Plugins/Enlighter/Enlighter.swift | 32 ++++--------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/Plugins/Enlighter/Enlighter.swift b/Plugins/Enlighter/Enlighter.swift index 0a7ff61..13f8d56 100644 --- a/Plugins/Enlighter/Enlighter.swift +++ b/Plugins/Enlighter/Enlighter.swift @@ -532,34 +532,7 @@ extension Enlighter: XcodeBuildToolPlugin { inputFiles : inputFiles, outputFiles : outputFiles )) - - // So, in Xcode, if a resource is handled by Enlighter, Xcode itself - // doesn't copy the resource anymore. Likely a bug. - // So what we do is copy them ourselves into the plugin dir. They then - // get bundled properly. - let inResourceURLs = groups.map({ $0.resourceURLs }).reduce([], +) - try inResourceURLs.forEach { ( inputResource : URL ) in - #if compiler(>=6) && canImport(Foundation) - let outResourceURL = context.pluginWorkDirectoryURL - .appendingPathComponent(inputResource.lastPathComponent) - #else - let outResourceFile = context.pluginWorkDirectory // TODO: Xcode16b2? - .appending(inputResource.lastPathComponent) - let outResourceURL = URL(fileURLWithPath: outResourceFile.string) - #endif - - buildCommands.append(.buildCommand( - displayName : "Copy \(group.stem) resource " - + "\(inputResource.lastPathComponent) into \(target.name)", - executable : try context.tool(named: "cp").url, - arguments : [ "-a", - inputResource .path(percentEncoded: false), - outResourceURL.path(percentEncoded: false) ], - inputFiles : [ inputResource ], - outputFiles : [ outResourceURL ] - )) - } - #else + #else // Xcode <16 let inputFiles : [ Path ] = { var inputFiles = group.matches.map { Path($0.path) } if let configURL = configuration.configURL { @@ -592,6 +565,9 @@ extension Enlighter: XcodeBuildToolPlugin { outputFiles : outputFiles )) + // Fixed in Xcode 16, and maybe in 15.4 already. + // The fix resulted in this issue I think: + // https://github.com/Lighter-swift/Lighter/issues/27 // So, in Xcode, if a resource is handled by Enlighter, Xcode itself // doesn't copy the resource anymore. Likely a bug. // So what we do is copy them ourselves into the plugin dir. They then