swiftlang / swift-package-manager

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

Intermediates from build plugin generated files written to working directory #7930

Open samdeane opened 3 months ago

samdeane commented 3 months ago

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

Description

I have a buildCommand that generates a Swift file, and optionally some resources. The generated files are written to the correct place, and can be used by the client of the plugin. However, some intermediate files seem to sometimes be written to the current working directory, instead of the .build folder.

Specifically, for a generated file called Version.generated.swift, I am seeing the following files appear in the working directory:

This does not seem to happen every time, but I've yet to establish the trigger. A race condition perhaps?

Expected behavior

Generated files are written into a plugin/target specific folder inside .build. Any resulting intermediates go to the normal places inside .build.

Actual behavior

Generated files are written into a plugin/target specific folder inside .build. Resulting intermediates sometimes leak into the working directory.

Sometimes the build produces an error (but not always)

image

Steps to reproduce

clone https://github.com/elegantchaos/ReleaseTools.git checkout commit 7944ebb942e7681b44b00e25cc88837f23d31baf swift run rt --help

Swift Package Manager version/commit hash

Swift Package Manager - Swift 6.0.0-dev

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

swift-driver version: 1.113 Apple Swift version 6.0 (swiftlang-6.0.0.7.6 clang-1600.0.24.1) Target: arm64-apple-macosx14.0

Darwin space-monster.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000 arm64

samdeane commented 1 month ago

I have another unrelated reproducible case of this:

git clone git@github.com:elegantchaos/SwiftGodot
git checkout 559a6fbcef8c261ceeabe30f64690a8f1304e694
swift test

Version info:

+ uname -a
Darwin space-monster.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000 arm64
+ sw_vers
ProductName:        macOS
ProductVersion:     14.6.1
BuildVersion:       23G93
+ swift --version
swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx14.0
+ swift package --version
Swift Package Manager - Swift 6.0.2-dev
+ xcodebuild -version
Xcode 16.2
Build version 16B5100e
dschaefer2 commented 1 week ago

Same issue reported here https://github.com/apple/swift-openapi-generator/issues/676