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

Fix mapping of registry SwiftPackageManager dependencies #5563

Merged
merged 2 commits into from
Nov 19, 2023

Conversation

danieleformichelli
Copy link
Collaborator

#5398

Short description πŸ“

Looking at the code this should work, but I have not been able to properly define a registry dependency to test it

Contributor checklist βœ…

  • The code has been linted using run make workspace/lint-fix
  • The change is tested via unit testing or acceptance testing, or both
  • The title of the PR is formulated in a way that is usable as a changelog entry
  • In case the PR introduces changes that affect users, the documentation has been updated

Reviewer checklist βœ…

  • The code architecture and patterns are consistent with the rest of the codebase
  • Reviewer has checked that, if needed, the PR includes the label changelog:added, changelog:fixed, or changelog:changed, and the title is usable as a changelog entry

@danieleformichelli danieleformichelli added the changelog:fixed PR will be listed in the Fixed section of CHANGELOG label Nov 12, 2023
@regularberry
Copy link
Contributor

@danyf90 I don't have a sample project, but I can provide some example output when I point a package at our internal registry.
I set one up for swift-algorithms.

Package.swift

// swift-tools-version: 5.8
import PackageDescription

let package = Package(
    name: "PackageName",
    dependencies: [
        .package(
            id: "sean-test.swift-algorithms",
            from: "1.0.0"
         ),
    ]
)

Package.resolved

{
  "pins" : [
    {
      "identity" : "sean-test.swift-algorithms",
      "kind" : "registry",
      "location" : "",
      "state" : {
        "version" : "1.0.0"
      }
    },
    {
      "identity" : "swift-numerics",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/apple/swift-numerics.git",
      "state" : {
        "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
        "version" : "1.0.2"
      }
    }
  ],
  "version" : 2
}

workspace-state.json

{
  "object" : {
    "artifacts" : [

    ],
    "dependencies" : [
      {
        "basedOn" : null,
        "packageRef" : {
          "identity" : "sean-test.swift-algorithms",
          "kind" : "registry",
          "location" : "sean-test.swift-algorithms",
          "name" : "sean-test.swift-algorithms"
        },
        "state" : {
          "name" : "registryDownload",
          "version" : "1.0.0"
        },
        "subpath" : "sean-test/swift-algorithms/1.0.0"
      },
      {
        "basedOn" : null,
        "packageRef" : {
          "identity" : "swift-numerics",
          "kind" : "remoteSourceControl",
          "location" : "https://github.com/apple/swift-numerics.git",
          "name" : "swift-numerics"
        },
        "state" : {
          "checkoutState" : {
            "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
            "version" : "1.0.2"
          },
          "name" : "sourceControlCheckout"
        },
        "subpath" : "swift-numerics"
      }
    ]
  },
  "version" : 6
}

I tried the commit in this PR, but it crashes due to the provided subpath sean-test/algorithms/1.0.0 not pointing to anything.

I think the solution could be to just skip it for the registry type, since it adds a second entry in Package.resolved.

So:

case "registry":
    return nil

And then change the .map to a .compactMap. This worked for me locally!

@danieleformichelli
Copy link
Collaborator Author

Returning null there it would ignore the swift-algorithms package entirely and just import swift-numeric (its dependency) πŸ€”
What's the path on disk of that inside Tuist/Dependencies/SwiftPackageManager/.build folder?

@danieleformichelli danieleformichelli merged commit f33d340 into main Nov 19, 2023
28 checks passed
@danieleformichelli danieleformichelli deleted the fix/swift-package-registry-mapping branch November 19, 2023 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:fixed PR will be listed in the Fixed section of CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants