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 registry package swizzling when package name casing differs #8194

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

fortmarek
Copy link
Contributor

Fix registry package swizzling when package name casing differs

Motivation:

When swizzling dependencies when running swift package --replace-scm-with-registry resolve, package references that have different casing don't get swizzled.

You can find an example of this scenario in the Firebase SDK that boils down to:

import PackageDescription


let package = Package(
  name: "Firebase",
  dependencies: [
    .package(
      url: "https://github.com/google/promises.git", // lowercase
      "2.4.0" ..< "3.0.0"
    ),
  ],
  targets: [
    .target(
      name: "FirebaseCrashlytics",
      dependencies: [
        .product(name: "FBLPromises", package: "Promises"), // uppercase
      ]
    )
  ]
)

The .product(name: "FBLPromises", package: "Promises")should be swizzled to use the google.promises identifier, but because of the different casing, it's not.

Modifications:

When creating the map for packages to be swizzled, make the key lowercase. When we access the map, we again use a lowercase variant of the package name, so we don't unexpectedly miss an entry because of a different casing.

Result:

Packages with different casing are swizzled when using the swift package --replace-scm-with-registry resolve command.

@MaxDesiatov
Copy link
Contributor

@swift-ci test

Copy link
Contributor

@plemarquand plemarquand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch, appreciate the contribution! I just have one small comment.

@@ -220,7 +220,7 @@ extension Workspace {
info: "swizzling '\(dependency.locationString)' with registry dependency '\(registryIdentity)'."
)
targetDependencyPackageNameTransformations[dependency
.nameForModuleDependencyResolutionOnly] = registryIdentity.description
.nameForModuleDependencyResolutionOnly.lowercased()] = registryIdentity.description
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because package names/identifiers are case insensitive I think it makes more sense to update the .registry case in nameForModuleDependencyResolutionOnly to return a lowercased name so we're consistent everywhere going forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that in the latest commit 👍

However, .lowercased() still needs to be kept as dependency is not necessarily the registry case as that's done the line below. This could also be rewritten to:

                            modifiedDependency = .registry(
                                identity: registryIdentity,
                                requirement: requirement,
                                productFilter: settings.productFilter,
                                traits: settings.traits
                            )
                            targetDependencyPackageNameTransformations[modifiedDependency
                                .nameForModuleDependencyResolutionOnly] = registryIdentity.description

Let me know what you prefer, I don't have a clear preference here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your proposed rewrite here to create the modifiedDependency first makes more sense, since it doesn't duplicate the lowercasing logic in nameForModuleDependencyResolutionOnly

@plemarquand
Copy link
Contributor

@swift-ci please test

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

Successfully merging this pull request may close these issues.

4 participants