swiftlang / swift-package-manager

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

Resolving dependencies fails on fresh build #7951

Open Akaike opened 1 week ago

Akaike commented 1 week ago

Swift version

swiftlang-5.10.0.13

Platform

macOS 14.6.1

Editor

Visual Studio Code

Does the issue reproduce with Swift 6?

I didn’t try

Description

Loading a Vapor server-side project without an build causes a failure in resolving dependencies. Whenever I load a project that doesn't have an existing build folder, it gets automatically recreated (executes build all), but even after successful build, the dependencies cannot be resolved. After restarting VSCode, magically everything works again.

I also encountered the issue that the build doesn't work at all after creating a fresh Vapor project, but maybe this is not important to this issue. I have to manually delete the build folder and execute swift build, restart VSCode to make it work again.

I hope the logs help. Let me know if I can support you with anything else. It seems like I can reproduce the issue on my end very easily.

Steps to Reproduce

Logging

Fresh vapor project: Fresh project just loaded: extension-logs-fresh-vapor-project-initial-load.txt

After manual build execution and restart: extension-fresh-vapor-after-manual-build-and-restart-logs.txt

Older vapor project: Before restart extension-logs-vapor-project-before-restart.txt

After restart, dependencies being resolved without an issue. extension-logs-vapor-project-after-restart.txt

Akaike commented 1 week ago

I'm not sure if it helps, but here is also a video of the behaviour. It shows that I can't open any definition even though the build with needed files exists.

https://github.com/user-attachments/assets/07e2a8f3-7853-40ed-9995-f7b8e1068f7b

Sorry for the quality, had to keep it low cause of size.

ahoppen commented 1 week ago

Synced to Apple’s issue tracker as rdar://135478754

ahoppen commented 1 week ago

It seems like SwiftPM is having issues accessing the package manifests from your dependencies, which also explains why jump-to-definition isn’t working.

From the logs you attached

19:45:49: hello: Listing tests: Command failed: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift test list --skip-build -Xswiftc -diagnostic-style=llvm
error: 'swift-crypto': the package manifest at '/Users/alex/Dev/swift-core/hello/.build/checkouts/swift-crypto/Package.swift' cannot be accessed (/Users/alex/Dev/swift-core/hello/.build/checkouts/swift-crypto/Package.swift doesn't exist in file system)
error: 'swift-collections': the package manifest at '/Users/alex/Dev/swift-core/hello/.build/checkouts/swift-collections/Package.swift' cannot be accessed (/Users/alex/Dev/swift-core/hello/.build/checkouts/swift-collections/Package.swift doesn't exist in file system)
error: 'swift-collections': the package manifest at '/Users/alex/Dev/swift-core/hello/.build/checkouts/swift-collections/Package.swift' cannot be accessed (/Users/alex/Dev/swift-core/hello/.build/checkouts/swift-collections/Package.swift doesn't exist in file system)
error: 'swift-crypto': the package manifest at '/Users/alex/Dev/swift-core/hello/.build/checkouts/swift-crypto/Package.swift' cannot be accessed (/Users/alex/Dev/swift-core/hello/.build/checkouts/swift-crypto/Package.swift doesn't exist in file system)
error: 'swift-collections': the package manifest at '/Users/alex/Dev/swift-core/hello/.build/checkouts/swift-collections/Package.swift' cannot be accessed (/Users/alex/Dev/swift-core/hello/.build/checkouts/swift-collections/Package.swift doesn't exist in file system)
error: 'swift-collections': the package manifest at '/Users/alex/Dev/swift-core/hello/.build/checkouts/swift-collections/Package.swift' cannot be accessed (/Users/alex/Dev/swift-core/hello/.build/checkouts/swift-collections/Package.swift doesn't exist in file system)
error: no tests found; create a target in the 'Tests' directory

Sending this over to SwiftPM to take a look

plemarquand commented 1 day ago

Hi @Akaike, I took a shot at reproducing this w/ the Swift version and OS you specified but I couldn't reproduce it; dependencies were pulled as expected and the build all ran correctly.

Could you delete your .build and try to reproduce again, and once the build has completed run > Swift: Capture VS Code Swift Diagnostic Bundle from the VS Code command palette. Then select Minimal Diagnostics and attach the files to this issue. I'm curious if there is an extension setting I'm missing.

Akaike commented 1 day ago

Hi @plemarquand :), Hm, that’s unfortunate, or maybe fortunate… Maybe it’s just an issue on my end. I deleted a bunch of extensions and thought maybe it would help, but it didn’t.

This is what I did to reproduce the issue:

extension-logs.txt

Am I doing something wrong? Or is this how it is expected to work?

Here a full video of the same issue, reproduced with a fresh Vapor template project. https://github.com/user-attachments/assets/cb1d4dc4-3e7b-4a3a-b2ca-0cd6aa253663

I also uploaded it on YouTube, just in case: https://youtu.be/BDJI1VfQ23w

Here are the extensions I have installed: