Dear esteemed gentlepeople,
I have a Swift Package with a test target. The test target needs to include a folder as a resource while preserving its folder structure. I have symlinked that folder because it lives in an npm package and contains many large-ish files that are shared with other test suites in other programming languages.
So my structure looks like this:
- Package.swift
- node_modules/some-package/Files
- Swift/Tests/Files (which is a symlink to "../../node_modules/some-package/Files")
My Package.swift:
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
import Foundation
let package = Package(
name: "MyGreatProject",
platforms: [.iOS(.v15), .macOS(.v13)],
products: [
.library(
name: "MyGreatProject",
targets: ["MyGreatProject"]),
],
targets: [
.target(
name: "MyGreatProject",
path: "Swift/Sources"
),
.testTarget(
name: "MyGreatProjectTests",
dependencies: [
"MyGreatProject",
],
path: "Swift/Tests",
resources: [
// symlinked from node_modules/some-package/Files to Swift/Tests/Files
.copy("Files"),
]
)
]
)
When I open this Swift package in Xcode, I can run the tests and everything works. The symlinked "Files" folder is copied to [Derived Data]/some extra folders/MyGreatProject_MyGreatProjectTests.bundle/Contents/Resources/Files.
However, when I run swift test
from the command line, the symlink itself is copied, not its recursive contents. So it creates a symlink named "Files" in .build/arm64-apple-macosx/debug/MyGreatProject_MyGreatProjectTests.bundle which points to "../../node_modules/some-package/Files", which is an invalid path from that location.
Is this a bug? If not, is there a way I can solve this so it works both in Xcode and when running swift test
from the command line? Thank you so much!