SwiftPM resource copying question

I have a file hierarchy of resources I want to access in a test target in the Resources directory of my target:

Resources
  ├─ configInfo.json
  ├─ expectedResults.json
  └─ sourceFiles
            ├─ file1.md
            ├─ file2.md
            ├─ file3.md
            ├─ ...
            └─ file500.md

I want to copy the entire file hierarchy into the top level of the Resources directory in the resulting bundle.

I realize I can use .copy to copy a hierarchy:

.resources: [
    .copy("Resources")
],

However, this causes an extra level of directories in the resource bundle:
xxx.bundle/Contents/Resources/Resources

I understand that using .process would not be suitable for this since the hierarchy is flattened and all files end up at the top level of the bundle Resources directory.

I know I can explicitly name every file with a separate .copy entry, but with hundreds of files as part of the test, this is not practical.

Is there any way to simply say "I want the Resources directory in the bundle to be an exact copy of the Resources directory in my target"?

1 Like

UPDATE:

It seems like building a SwiftPM package in Xcode generates a different resource bundle structure than using the swift command line tool.

The resources I describe above are part of a test target. It is a single directory of resources where I want the hierarchy of its contents preserved in the bundle.

.resources: [
    .copy("Resources")
],

Using swift test creates a bundle with a Resources directory at the top level of the bundle.

Using Xcode, running the test action on the same Package.swift manifest file creates a bundle with the folder structure Contents/Resources/Resources.

I was completely surprised that building the same package with two different tools would generate two different bundle formats.

Is this by design? Is this a bug?

It seems like Bundle.module methods find the resources in both bundles, despite their different structures.

Is the behavior I am seeing expected? Any insights would be greatly appreciated!

This is using Xcode 15.2 and Xcode 15.3 and the SwiftPM swift command in Swift 5.9 and 5.10.

1 Like
resources: [
    .copy("Resources/.")
]

I think I've witnessed this behavior as well. Interested to hear what is supposed to be the "canonical" behavior.