Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result of calling packageManager.build in a command plugin should include a path to an executable's resource bundle, if one is present #8420

Open
euanh opened this issue Mar 27, 2025 · 0 comments

Comments

@euanh
Copy link
Contributor

euanh commented Mar 27, 2025

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

  1. 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"),
            ]
        ),
    ]
)
  1. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant