swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.74k stars 1.34k forks source link

Changes to an executable's resources don't trigger build commands depending on the executable itself #5982

Open natinusala opened 1 year ago

natinusala commented 1 year ago

Description

I have a build tool plugin that depends on an executable inside the package. The plugin makes a build command to the executable on every target Swift file (using context.tool(named:)).

The executable itself depends on resources, copied to the executable bundle by SPM. In my case they are Stencil template files to generate Swift code.

When I make any change to the executable code, SPM runs the build command again on every Swift file. That works fine.

However when I change a resource, SPM doesn't run the build command again. It copies the file to the bundle but it doesn't trigger a rebuild of the build commands declared by the plugin.

The end result is that I need to clean the project every time I make a change to a template if I want SPM to trigger my custom build command and update the generated Swift files.

Expected behavior

When I update a resource of an executable, I expect the executable target to be marked "dirty". I expect my plugin build commands to be ran again, as if the executable itself changed.

Actual behavior

The resource file is copied to the bundle but the executable target isn't considered changed, so my build commands are not executed again (and my generated code is outdated).

Steps to reproduce

  1. Make an executable target a. That has a dummy .swift resource file b. That takes an output arg c. That reads the file from the resources and writes it to output
  2. Make a build tool plugin a. That depends on that executable b. That lists all Swift files of the target and creates a build command running the executable on the file
  3. Apply that plugin to a dummy target
  4. Change the resource file and notice that the build command from the plugin isn't triggered again

Swift Package Manager version/commit hash

Swift Package Manager - Swift 5.7.1

Swift & OS version (output of swift --version && uname -a)

Swift version 5.7.1 (swift-5.7.1-RELEASE)
Target: x86_64-unknown-linux-gnu
Linux DESKTOP-LQ72L1B 5.15.79.1-microsoft-standard-WSL2 #1 SMP Wed Nov 23 01:01:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
code-per-day commented 11 months ago

I have a similar issue, I'm trying to parse the contents of a TOML file to generate localization resources. It works as a prebuild command but blows our incremental build time. It doesn't work as a build command because it never executes again.

What's the status on this?