Skip to content
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

Dependency resolution with registry identity substitution does not work correctly with tools-version >= 5.8 #7912

Open
1 task done
robinkunde opened this issue Aug 23, 2024 · 1 comment
Labels

Comments

@robinkunde
Copy link

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

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

Dependency resolution with registry identity substitution does not work correctly if any of the packages in the graph use a tools-version >= 5.8.

Example error:

error: 'swiftpackagemanagerbug': product 'Alamofire' required by package 'swiftpackagemanagerbug' target 'SwiftPackageManagerBug' not found in package 'Alamofire'. Did you mean 'Alamofire'?

With the aliasing rules introduced in 5.8, SPM uses package identities instead of the names, but generates an invalid package graph when trying to apply registry lookup rules. However, I'm not using aliasing feature in this case and do not know how it would impact this particular issue.
Additional issues can be caused when specifying Target.Dependency using a string literal, but I don't know when this feature was introduced.
Please note that different commands can exhibit different behaviors. In my testing, swift package show-dependencies is most susceptible to these issues. swift build, swift package resolve, and swift package update are less impacted for some reason.

--use-registry-identity-for-scm and --replace-scm-with-registry are also not impacted in the same way, but I need to do more testing here.

I believe these issue where missed because the relevant tests only run against tools-version < 5.8. I will open a PR with some of these tests update to reproduce the problem.

Expected behavior

Output with tools-version 5.7

$ swift package show-dependencies --use-registry-identity-for-scm
Updating https://github.com/Alamofire/Alamofire.git
Updated https://github.com/Alamofire/Alamofire.git (0.29s)
Computing version for https://github.com/Alamofire/Alamofire.git
Computed https://github.com/Alamofire/Alamofire.git at 5.9.1 (0.01s)
Removing https://github.com/Alamofire/Alamofire.git
Fetching https://github.com/Alamofire/Alamofire.git from cache
Fetched https://github.com/Alamofire/Alamofire.git from cache (0.00s)
Creating working copy for https://github.com/Alamofire/Alamofire.git
Working copy of https://github.com/Alamofire/Alamofire.git resolved at 5.9.1
.
└── default.alamofire<https://github.com/Alamofire/Alamofire.git@5.9.1>

Actual behavior

Output with tools-version 5.8

$ swift package show-dependencies --use-registry-identity-for-scm
error: 'swiftpackagemanagerbug': product 'Alamofire' required by package 'swiftpackagemanagerbug' target 'SwiftPackageManagerBug' not found in package 'Alamofire'. Did you mean 'Alamofire'?

Steps to reproduce

Reproduction steps

  1. Publish Alamofire 5.9.1 to registry (I used AWS CodeArtifact) with package-metadata.json below
  2. Create package with the Package.swift file below
  3. Set registry locally for package or globally
  4. Run swift package show-dependencies --use-registry-identity-for-scm

Package.swift

// swift-tools-version: 5.8
import PackageDescription

let package = Package(
    name: "SwiftPackageManagerBug",
    products: [
        .library(name: "SwiftPackageManagerBug", targets: ["SwiftPackageManagerBug"]),
    ],
    dependencies: [
        .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.9.1")),
    ],
    targets: [
        .target(
            name: "SwiftPackageManagerBug",
            dependencies: [
                .product(name: "Alamofire", package: "Alamofire"),
            ]
        ),
    ]
)

package-metadata.json

{
  "repositoryURLs": [
    "https://github.com/Alamofire/Alamofire.git",
    "https://github.com/Alamofire/Alamofire"
  ]
}

Swift Package Manager version/commit hash

Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)

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

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
Darwin nalendar.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:46 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6031 arm64

@SomeRandomiOSDev
Copy link

+1. I'm having this same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants