Skip to content

Commit

Permalink
Fix issue 27: .sql/.db could not be marked as a resource in Xcode
Browse files Browse the repository at this point in the history
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+.
  • Loading branch information
helje5 committed Oct 3, 2024
1 parent d20ebf0 commit ad0d8c2
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions Plugins/Enlighter/Enlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ad0d8c2

Please sign in to comment.