swiftlang / swift-package-manager

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

Build can overlap with resolve packages resulting in corrupted dependencies checkouts #6643

Open tristanlabelle opened 1 year ago

tristanlabelle commented 1 year ago

Description

SPM does not synchronize build operations with resolve package operations, resulting in git dependencies checkouts running concurrently and corrupting repo state. The repro here involves the Swift VS Code extension automatically running resolve packages in the background while the user might be starting a build. This could be fixed at either the SPM level (more robust?) or the Swift VS Code extension (hence I also filed https://github.com/swift-server/vscode-swift/issues/547 )

Migrated from https://github.com/apple/sourcekit-lsp/issues/740

Expected behavior

Resolve package and build should not end up corrupting the repos of their git checkouts.

Actual behavior

With high likelihood, you will hit errors like:

fatal: not a git repository (or any of the parent directories): .git

error: input file 'C:\Code\swift-composable-architecture.build\checkouts\swift-argument-parser\Plugins\GenerateManual\GenerateManualPluginError.swift' was modified during the build

error: 'swift-benchmark': Failed to clone repository https://github.com/google/swift-benchmark: Cloning into 'C:\Code\swift-composable-architecture.build\checkouts\swift-benchmark'... error: could not write config file C:/Code/swift-composable-architecture/.build/checkouts/swift-benchmark/.git/config: No such file or directory fatal: could not set 'core.logallrefupdates' to 'true'

The checkout might now be in a bad state where there will be compilation errors in dependencies because of missing files or similar issues. The workaround is to delete .build and rebuild.

Steps to reproduce

  1. Open a Swift project with several git dependencies (such as https://github.com/pointfreeco/swift-composable-architecture.git) in VSCode
  2. Immediately start a build.

Swift Package Manager version/commit hash

No response

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

compnerd.org Swift version 5.9-dev (LLVM 1626c3d9b5175d1, Swift 0c0ec72255527fa) Target: x86_64-unknown-windows-msvc sswg.swift-lang Version: 1.2.1 Windows 11

neonichu commented 7 months ago

https://github.com/apple/swift-package-manager/pull/7291 should be able to solve this.