-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Intermediates from build plugin generated files written to working directory #7930
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
Comments
I have another unrelated reproducible case of this:
Version info:
|
Same issue reported here apple/swift-openapi-generator#676 |
I spent some time today trying to reproduce this, and here are some notes. Steps to reproduce:
From looking at the file system while the build is going, it seems to me that VS Code's background indexing (or even the lighter weight project prep that writes to The file most central to my repro case seems to be But seems that even when doing a side build in Terminal with This is as far as I got, but wonder if this should be moved back into the Swift VS Code extension repo, before we can identify that this truly is a SwiftPM bug. |
This is happening to me intermittently when using just Terminal + Vim, so it's not specific to VS Code |
Might be LSP-triggered builds and regular builds interacting, yeah. |
cc @ahoppen for visibility, in case something similar has shown up with other IDEs that use sourcekit-lsp |
I have seen this before in VS Code / SourceKit-LSP but haven’t been able to figure out what might be causing it. |
I'm working on isolating it into a smaller example. Seems to be a bug around Out of curiosity, what's the expected locking mechanism over the contents of |
Looks like I'll try to reproduce with some arbitrary sleeps tomorrow on a trivial project. I'm still interested to learn what the intended synchronization mechanism between sourcekit-lsp and swift-package is supposed to be. |
That could be a thing. The output-file-map is written early in the build planning which is totally the wrong place to do it. |
Right, for any target that has a plugin registered, output-file-map shouldn't be created until the plugin build command has been created and the output files are known (but the plugin build command itself can be run later, that's not a blocker). |
Thanks for investigating, Honza. sourcekit-lsp should operate in |
@ahoppen does that mean that this is unexpected? Output of
See that sourcekit-lsp is checking for, and then creating, the file Is this unexpected? |
Confirmed this with more logging. I suspect that this only causes issues whenever I have two questions:
|
And the reason why this isn't 100% reproducible (but I can ~100% reproduce it using the instructions I shared earlier on a specific sample project) is because this bug only shows up if there's enough time between |
Only workaround to be able to build from VS Code without this bug is disabling sourcekit-lsp in the extension's settings, which is obviously a quite nuclear option. I'm not currently aware of a better workaround. |
This does seem to match up with my environment: a package with a build plugin (swift-argument-parser) and sourcekit-lsp (via Sublime Text). Maybe one workaround for now would be to adjust the swift build command in VS code to pass a different |
The bug manifests for me when building from the command line. That said, I'm wondering whether I've always had vscode open, and potentially doing background indexing, at the same time. Next time I hit the problem I will try shutting down xcode and making sure that sourcekit-lsp isn't doing anything, and see if the issue goes away. |
If I quit vscode and build on the command line, it does seem to fix the problem. I was hoping that turning off background indexing and background compilation in the plugin would be enough to fix it with VS code still running, but sadly not. The plugin is still doing something with swift-lsp even then, and it's enough to reproduce the bug. |
Turning on background indexing should help here because with background indexing enabled, SourceKit-LSP will operate in its own |
i run into this on nearly every build with a project that uses package-benchmark
there doesn’t seem to be any way to get around this, except to close out VSCode each time and build the project from the command line. |
@tayloraswift does turning on background indexing in sourcekit-lsp help? Then it will use |
I've been looking for a package that consistently reproduces this. |
https://github.com/ordo-one/external-reproducers/tree/existential-copy/benchmarks/existential-copy is a good example of a project that frequently experiences this issue |
@tayloraswift Awesome. Thanks! I'll take a look. It's very weird it doesn't happen all the time. Hard to think of what would be non-deterministic there. But must be. |
…ally This resolves an issue where outputs of build tool plugins could be emitted to a random output directory based on whatever the working directory of the calling process happened to be at the time the build tool plugin was executed. Closes #7930
Is it reproducible with SwiftPM command-line tools:
swift build
,swift test
,swift package
etc?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:Version.generated.o
Version.generated.swiftdeps
Version.generated.swiftdeps~
Version.generated.d
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)
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
The text was updated successfully, but these errors were encountered: