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

Wrong Package names with Package.resolved JSON version 2 #179

Closed
AF-cgi opened this issue Mar 24, 2022 · 8 comments
Closed

Wrong Package names with Package.resolved JSON version 2 #179

AF-cgi opened this issue Mar 24, 2022 · 8 comments

Comments

@AF-cgi
Copy link

AF-cgi commented Mar 24, 2022

With the new Package.resolved JSON version 2 (#174), which Apple introduce with Xcode 13.3 and Swift 5.6, I miss the correct package names. The possibility to improve the names is the rename-feature of your tool. Do you have any idea if there is a better way, to get the correct package names?
An example:

// Version 1
{
  "package": "AppCenter",
  "repositoryURL": "https://github.com/microsoft/appcenter-sdk-apple.git",
  "state": {
    "branch": null,
    "revision": "b84bc8a39ff04bc8d5ae7b4d230c171c562891aa",
    "version": "4.4.1"
  }
}

// Version 2
{
  "identity" : "appcenter-sdk-apple",
  "kind" : "remoteSourceControl",
  "location" : "https://github.com/microsoft/appcenter-sdk-apple.git",
  "state" : {
    "revision" : "b84bc8a39ff04bc8d5ae7b4d230c171c562891aa",
    "version" : "4.4.1"
  }
}

Each package name is lowercase. Most package names ends with -sdk, -iOS-sdk or -apple.

@BetweenTwoBits
Copy link

@mono0926 are you already working on support for this?

@mono0926
Copy link
Owner

mono0926 commented Apr 8, 2022

@BetweenTwoBits

Not yet, and not planned, sorry.
I'm welcome the pull request 🐶

@ykws
Copy link

ykws commented Jun 20, 2022

We can use rename Configuration.

rename:
  appcenter-sdk-apple: AppCenter

@AF-cgi
Copy link
Author

AF-cgi commented Jun 20, 2022

@ykws Yes, I know. That's the way what we currently do. But it's pretty hard to rename all your dependencies and find the correct naming for each of this dependencies.

@ykws
Copy link

ykws commented Jun 20, 2022

@AF-cgi Good!

I think too, however it is impossible to rename automatically, because of the breaking change that the source of the origin package name was lost.

I think we can only manually renaming as mention above configuration.

@ykws
Copy link

ykws commented Jun 21, 2022

Just an idea,

We may be able to pick up the name from Package(name: in Package.swift,
we can access each location in Package.resolved as repository url.

@bennokress
Copy link
Contributor

Just an idea,

We may be able to pick up the name from Package(name: in Package.swift, we can access each location in Package.resolved as repository url.

That's a good idea and I implemented it in my fork. However there are caveats to this: since Package.swift is not a JSON where we can rely on standardized parsing, we might encounter problems with some Packages. As an example from my own Swift Package, I don't like repeating myself in Swift and since the Package Definition is written in Swift, I defined my Package Name as a String variable. That's perfectly valid, but breaks any attempts I took when trying to parse the name in a globally valid way.

What I did in the end is a 3-step process to get the best name possible from the new version of Package.resolved:

  1. Make sure we parse a v2 Package, not a v1 and get the name from the Package.resolved as a last resort (current implementation here)
  2. Take the Repository Name from the Github Conversion Step that is already implemented in LicensePlist which is already an improvement on the result of Step 1, since it has uppercased characters in all the right places. We still have some issues when dealing with Packages containing spaces though (those have dashes instead, but replacing those would break Packages that really have dashes in their names).
  3. Parse the Package.swift from the Repository by looking for the first Package object, removing all nested code inside [...] to eliminate dependency and target names and finally getting the remaining value for name. If anything fails we return nil which lets us fall back to the result of Step 2.

Let me know if you see room for improvement since this is my first draft and all the parsing made me dizzy at times (trying a lot of Regex before landing on my solution). Edge cases I encountered are also added as Unit Tests, so you can play around in the parser with confidence.

@stmitt
Copy link
Contributor

stmitt commented Aug 2, 2022

A more robust way of parsing the Package.swift would be to run swift package dump-package and parse its JSON output. With that approach, all future formats would be supported.

@AF-cgi AF-cgi closed this as completed Aug 3, 2022
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

No branches or pull requests

6 participants