Description
Description
A command plugin can call packageManager.build()
to ask SwiftPM to build a product. The return value includes the path to the target.
// Build a product
let result = try packageManager.build(.product("product"))
// Check the result. Ideally this would report more details.
guard result.succeeded else { throw PluginError.buildError }
// Get the list of built executables from the build result.
let builtExecutables = result.builtArtifacts.filter { $0.kind == .executable }
// Do something with the executables
for executable in builtExecutables {
doSomething(with: executable.url)
}
The value returned by packageManager.build()
does not tell the caller anything about the existence or location of any resource bundle associated with the target. This is a problem for plugins which archive or package targets.
Expected behavior
The output of packageManager.build()
should indicate whether or not there is a resource bundle associated with the target, and if so where it can be found.
Currently the plugin needs to guess the location of the resource bundle, which depends on how the build is being run. SwiftPM stores it in .build/debug/\(context.package.displayName)_\(productName).resources
; Xcode uses a similar path but with a .bundle
extension.
As an extra check, the plugin can infer the existence of a resource bundle by checking the sources associated with the target for files of type: PackagePlugin.FileType.resource
.
Actual behavior
No information is available.
Steps to reproduce
- Create a package with resources, e.g.:
// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "BaggagePkg",
targets: [
.executableTarget(
name: "BaggageTgt",
resources: [
.process("Processed"),
.copy("Copied"),
]
),
]
)
- Create a command plugin which builds the target and prints the return value of
packageManager.build()
. There is no information about the resource bundle.
Swift Package Manager version/commit hash
Swift Package Manager - Swift 6.0.3
Swift & OS version (output of swift --version && uname -a
)
Apple Swift version 6.0.3 (swift-6.0.3-RELEASE)
Target: arm64-apple-macosx15.0
Darwin computermabob.local 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan 2 20:45:33 PST 2025; root:xnu_development-11215.81.4~3