swiftlang / swift-package-manager

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

Use Local Version -- Case Sensitivity Problems #7931

Closed samdeane closed 2 months ago

samdeane commented 2 months ago

Describe the bug

Selecting Use Local Version for a package dependency is failing for me.

I suspect that the problem relates to case sensitivity.

The VS Code Package Dependencies window shows the dependency name as versionator. The Package.swift file for dependency declares the package name as "Versionator". The local directory for the package is called Versionator.

Performing this step results in the following error:

image

To Reproduce

Clone git@github.com:elegantchaos/VersionatorTest Checkout commit b5ffdc1354d68b46fc65793d8acea8e59eab163e Clone git@github.com:elegantchaos/Versionator to a parallel directory Open VersionatorTest in vscode Right click on versionator in the Package Dependencies list Choose Use Local Version select the local version of Versionator

Expected behavior

The Versionator package should be set into edit mode, pointing at the local checkout

Environment

~/Developer/Projects/VersionatorTest > versions                                                                                                                                       (main)
+ uname
Darwin
+ sw_vers
ProductName:            macOS
ProductVersion:         14.6.1
BuildVersion:           23G93
+ swift --version
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
+ xcodebuild -version
Xcode 16.1
Build version 16B5001e
+ code --version
1.92.2
fee1edb8d6d72a0ddff41e5f71a671c23ed924b9
arm64

Additional context

Running swift package edit Versionator --path ../Versionator myself from the terminal does work.

michael-weng commented 2 months ago

I will take a look at this.

michael-weng commented 2 months ago

There's a discrepancy between how case is being handle as an identifier/name in swift package manager, I will forward this issue to spm project and let their contributors decide the best course of action.

bripeticca commented 2 months ago

Seems like there is a discrepancy between how SwiftPM is saving package identities (where it's forced to be lowercased via the PackageIdentityParser initializers) and the logic for when a user invokes the swift package edit <package-name> command - the command makes a comparison between the package name argument to the manifest identity as-is, without considering case insensitivity.

nmggithub commented 2 months ago

(where it's forced to be lowercased via the PackageIdentityParser initializers)

How is it being "forced" in this context? Does SwiftPM actually need to lowercase the identities, or is that just convention?

bripeticca commented 2 months ago

(where it's forced to be lowercased via the PackageIdentityParser initializers)

How is it being "forced" in this context? Does SwiftPM actually need to lowercase the identities, or is that just convention?

When initializing a PackageIdentity property (essentially just a wrapper structure that holds onto the string), it will automatically lowercase the string upon assignment in the initializers that are being called in SwiftPM. There is little documented as to why from what I've been able to see, so it seems this is unspoken convention.

bripeticca commented 2 months ago

Further investigation revealed that SwiftPM has two naming conventions for a package, one being the package identity and the other being the display name. The display name is intended to be used in UI as the name suggests, whereas referring to a package in all other cases should rely on the identity - including swift package command line arguments.

The identity is created through parsing the URL of the package's repository (namely just picking off the end of the path and removing .git), and is then lowercased. The display name is specified in the package's manifest with the name parameter, like such:

let package = Package(
    name: "MyDisplayName",
    // ...etc.
)

There are some discrepancies within SwiftPM between its usage of the two, so I think an effort to be more clear on which is expected on the user's end would be a great help here.