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 build tool plugin sources do not cause targets using that plugin to rebuild #8062

Open DougGregor opened 4 days ago

DougGregor commented 4 days ago

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

Description

If I have a build tool plugin (in my case, Java2SwiftPlugin) and a target that uses it (JavaProbablyPrime), once the target has built, changes to the sources of Java2SwiftPlugin won't cause that target to rebuild.

Expected behavior

The implementation of a build tool plugin can affect the build of any targets that use that plugin. When the sources to the build tool plugin change, I'd expect those targets to rebuild.

Actual behavior

Changes to the build tool plugin sources do not cause targets using that plugin to rebuild.

Steps to reproduce

  1. git clone https://github.com/swiftlang/swift-java (tested at b9122bde780a7b66080a6065707977718357cac1)
  2. cd Samples/JavaProbablyPrime
  3. swift build (build succeeds)
  4. Put a fatalError at the beginning of createBuildCommands in Plugins/Java2SwiftPlugin/Java2SwiftPlugin.swift (patch below)
  5. cd Samples/JavaProbablyPrime if not already there
  6. swift build (should fail due to fatal error, but doesn't rebuild so it doesn't fail)

Swift Package Manager version/commit hash

6.0

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

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0
DougGregor commented 4 days ago

The "patch" to add the fatalError is this:

diff --git a/Plugins/Java2SwiftPlugin/Java2SwiftPlugin.swift b/Plugins/Java2SwiftPlugin/Java2SwiftPlugin.swift
index 30be39a..4e753a3 100644
--- a/Plugins/Java2SwiftPlugin/Java2SwiftPlugin.swift
+++ b/Plugins/Java2SwiftPlugin/Java2SwiftPlugin.swift
@@ -20,6 +20,7 @@ fileprivate let Java2SwiftConfigFileName = "Java2Swift.config"
 @main
 struct Java2SwiftBuildToolPlugin: BuildToolPlugin {
   func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] {
+    fatalError("Java2SwiftBuildToolPlugin is not supported.")
     guard let sourceModule = target.sourceModule else { return [] }

     // Note: Target doesn't have a directoryURL counterpart to directory,
rauhul commented 4 days ago

@dschaefer2 i think this is a great repro for the missing rebuilds I had mentioned a couple months back