The prebuild plugin does not run on every build which is expected by the documentation.
I am trying to use the new amazing feature of Swift 5.6 - prebuild plugin and have encountered a flaw in the plugin execution. Maybe I don’t understand how the plugin works.
I used the plugin to auto-generate the build version from the GIT repository information.
From prebuild plugin documentation:
"Commands of type .prebuildCommand
run before the start of every build.":
SE-0303
swift-package-manager/Sources/PackagePlugin/Command.swift
The plugin with documentation is located here:
https://github.com/DimaRU/PackageBuildInfo
Sample project:
https://github.com/DimaRU/PackageBuildInfoExample
Shell scripts to reproduce the problem:
https://gist.github.com/DimaRU/964135c00eb3ee3cd3c7abd6f09587c8
Second script (example-clean.sh) force rebuild entire project by clean build artifacts each run.
Scripts execution log:
a-dmitry:~/Developer/temp% ./example.sh + git clone https://github.com/DimaRU/PackageBuildInfoExample Cloning into 'PackageBuildInfoExample'... remote: Enumerating objects: 34, done. remote: Counting objects: 100% (34/34), done. remote: Compressing objects: 100% (29/29), done. remote: Total 34 (delta 9), reused 26 (delta 3), pack-reused 0 Receiving objects: 100% (34/34), 6.00 KiB | 3.00 MiB/s, done. Resolving deltas: 100% (9/9), done. + cd PackageBuildInfoExample + swift run Fetching https://github.com/DimaRU/PackageBuildInfo from cache Fetched https://github.com/DimaRU/PackageBuildInfo (1.13s) Creating working copy for https://github.com/DimaRU/PackageBuildInfo Working copy of https://github.com/DimaRU/PackageBuildInfo resolved at master Building for debugging... [5/5] Linking PackageBuildInfoExample Build complete! (3.76s) Build: 1.0.0-2-g727592a Package build info: Time: 07.05.2022, 23:29 Branch: master Tag: 1.0.0 Commit count: 6 Commits since: 2 ID: 727592a42da716b59d2b0f061dbc614dc9a75892 + touch a + swift run Building for debugging... [2/2] Compiling PackageBuildInfoExample packageBuildInfo.swift Build complete! (0.71s) Build: 1.0.0-2-g727592a Package build info: Time: 07.05.2022, 23:29 Branch: master Tag: 1.0.0 Commit count: 6 Commits since: 2 ID: 727592a42da716b59d2b0f061dbc614dc9a75892 + git add a + swift run Building for debugging... Build complete! (0.06s) Build: 1.0.0-2-g727592a Package build info: Time: 07.05.2022, 23:29 Branch: master Tag: 1.0.0 Commit count: 6 Commits since: 2 ID: 727592a42da716b59d2b0f061dbc614dc9a75892 + git commit -m 'Add a' [master b226b81] Add a 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 a + swift run Building for debugging... Build complete! (0.06s) Build: 1.0.0-2-g727592a Package build info: Time: 07.05.2022, 23:29 Branch: master Tag: 1.0.0 Commit count: 6 Commits since: 2 ID: 727592a42da716b59d2b0f061dbc614dc9a75892 a-dmitry:~/Developer/temp% ./example-clean.sh + git clone https://github.com/DimaRU/PackageBuildInfoExample Cloning into 'PackageBuildInfoExample'... remote: Enumerating objects: 34, done. remote: Counting objects: 100% (34/34), done. remote: Compressing objects: 100% (29/29), done. remote: Total 34 (delta 9), reused 26 (delta 3), pack-reused 0 Receiving objects: 100% (34/34), 6.00 KiB | 2.00 MiB/s, done. Resolving deltas: 100% (9/9), done. + cd PackageBuildInfoExample + swift run Fetching https://github.com/DimaRU/PackageBuildInfo from cache Fetched https://github.com/DimaRU/PackageBuildInfo (0.66s) Creating working copy for https://github.com/DimaRU/PackageBuildInfo Working copy of https://github.com/DimaRU/PackageBuildInfo resolved at master Building for debugging... [5/5] Linking PackageBuildInfoExample Build complete! (3.71s) Build: 1.0.0-2-g727592a Package build info: Time: 07.05.2022, 23:29 Branch: master Tag: 1.0.0 Commit count: 6 Commits since: 2 ID: 727592a42da716b59d2b0f061dbc614dc9a75892 + touch a + swift package clean + swift run Building for debugging... [5/5] Linking PackageBuildInfoExample Build complete! (3.42s) Build: 1.0.0-2-g727592a Package build info: Time: 07.05.2022, 23:29 Branch: master Tag: 1.0.0 Commit count: 6 Commits since: 2 ID: 727592a42da716b59d2b0f061dbc614dc9a75892 + git add a + swift package clean + swift run Building for debugging... [5/5] Linking PackageBuildInfoExample Build complete! (3.38s) Build: 1.0.0-2-g727592a-dirty Package build info: Time: 07.05.2022, 23:29 Branch: master Tag: 1.0.0 Commit count: 6 Commits since: 2 ID: 727592a42da716b59d2b0f061dbc614dc9a75892 Dirty build (have uncommitted changes) + git commit -m 'Add a' [master 331aaee] Add a 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 a + swift package clean + swift run Building for debugging... [5/5] Linking PackageBuildInfoExample Build complete! (3.40s) Build: 1.0.0-3-g331aaee Package build info: Time: 08.05.2022, 09:22 Branch: master Tag: 1.0.0 Commit count: 7 Commits since: 3 ID: 331aaeeb8162446b25bb411a67eabb23d1723f9f