Skip to content

fix(swiftpm): Use identity as name for Swift PM registry dependencies #10124

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

Merged
merged 1 commit into from
Apr 15, 2025

Conversation

liedQM
Copy link
Contributor

@liedQM liedQM commented Apr 3, 2025

Currently only the location field is used to derive the name of a Swift PM dependency. For dependencies fetched over a Package Registry Service (Swift PM registry) the location field is empty which leads to incomplete and invalid results. For those dependencies the identity needs to be used instead.

Technical notes:

  • Screenshots of a broken and fixed scan with SPM registries involved:

broken:
broken_spm_registry_deps
fixed:
fixed_spm_registry_deps
Note: Like seen, the scan also stops resolving the broken SPM registries further which results in much shorter scan results.

  • Test outcome of the newly added test without the fix:
    expected:
project:
  id: "SwiftPM::src/funTest/assets/projects/synthetic/only-lockfile-v3-with-SPM-registry-dependency/Package.resolved:e1d45fb08d20491de87deb7decd464633707ebaf"
  definition_file_path: "plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/only-lockfile-v3-with-SPM-registry-dependency/Package.resolved"
  declared_licenses: []
  declared_licenses_processed: {}
  vcs:
    type: ""
    url: ""
    revision: ""
    path: ""
  vcs_processed:
    type: "Git"
    url: "https://github.com/oss-review-toolkit/ort.git"
    revision: "e1d45fb08d20491de87deb7decd464633707ebaf"
    path: "plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/only-lockfile-v3-with-SPM-registry-dependency"
  homepage_url: ""
  scopes:
  - name: "dependencies"
    dependencies:
    - id: "Swift::alamofire.alamofire:5.4.4"
packages:
- id: "Swift::alamofire.alamofire:5.4.4"
  purl: "pkg:swift/[email protected]"
  declared_licenses: []
  declared_licenses_processed: {}
  description: ""
  homepage_url: ""
  binary_artifact:
    url: ""
    hash:
      value: ""
      algorithm: ""
  source_artifact:
    url: ""
    hash:
      value: ""
      algorithm: ""
  vcs:
    type: ""
    url: ""
    revision: ""
    path: ""
  vcs_processed:
    type: ""
    url: ""
    revision: ""
    path: ""

but was:

project:
  id: "SwiftPM::src/funTest/assets/projects/synthetic/only-lockfile-v3-with-SPM-registry-dependency/Package.resolved:e1d45fb08d20491de87deb7decd464633707ebaf"
  definition_file_path: "plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/only-lockfile-v3-with-SPM-registry-dependency/Package.resolved"
  declared_licenses: []
  declared_licenses_processed: {}
  vcs:
    type: ""
    url: ""
    revision: ""
    path: ""
  vcs_processed:
    type: "Git"
    url: "https://github.com/oss-review-toolkit/ort.git"
    revision: "e1d45fb08d20491de87deb7decd464633707ebaf"
    path: "plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/only-lockfile-v3-with-SPM-registry-dependency"
  homepage_url: ""
  scopes:
  - name: "dependencies"
    dependencies:
    - id: "Swift::null:5.4.4"
packages:
- id: "Swift::null:5.4.4"
  purl: "pkg:swift/[email protected]"
  declared_licenses: []
  declared_licenses_processed: {}
  description: ""
  homepage_url: ""
  binary_artifact:
    url: ""
    hash:
      value: ""
      algorithm: ""
  source_artifact:
    url: ""
    hash:
      value: ""
      algorithm: ""
  vcs:
    type: ""
    url: ""
    revision: ""
    path: ""
  vcs_processed:
    type: ""
    url: ""
    revision: ""
    path: ""

@liedQM liedQM requested a review from a team as a code owner April 3, 2025 06:57
@sschuberth
Copy link
Member

Thanks a lot for the contribution @liedQM! Please have a look at the failing commit linter: You should hard-wrap commit message body lines at column 75.

@@ -244,7 +244,12 @@ private fun PinV2.toId(): Identifier =
Identifier(
type = PACKAGE_TYPE,
namespace = "",
name = getCanonicalName(location),
// For SPM registry dependencies the `location` field is blank -> Use `identity` instead
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please make this a sentence as "written in a book" (e.g. with a dot at the end):

// For SPM registry dependencies the `location` field is blank, so use the `identity` field instead.

Copy link
Member

Choose a reason for hiding this comment

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

Shall we move this comment to the location property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the sentence suggestion, I've applied it.

Copy link

codecov bot commented Apr 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.60%. Comparing base (86de3cc) to head (f3980be).
Report is 85 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main   #10124   +/-   ##
=========================================
  Coverage     69.60%   69.60%           
  Complexity     1454     1454           
=========================================
  Files           270      270           
  Lines          9668     9668           
  Branches       1028     1028           
=========================================
  Hits           6729     6729           
  Misses         2487     2487           
  Partials        452      452           
Flag Coverage Δ
funTest-docker 68.80% <ø> (+0.02%) ⬆️
funTest-non-docker 33.32% <ø> (ø)
test-ubuntu-24.04 39.14% <ø> (ø)
test-windows-2022 39.12% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -244,7 +244,12 @@ private fun PinV2.toId(): Identifier =
Identifier(
type = PACKAGE_TYPE,
namespace = "",
name = getCanonicalName(location),
// For SPM registry dependencies the `location` field is blank -> Use `identity` instead
Copy link
Member

Choose a reason for hiding this comment

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

Shall we move this comment to the location property?

@liedQM
Copy link
Contributor Author

liedQM commented Apr 3, 2025

Thanks a lot for the contribution @liedQM! Please have a look at the failing commit linter: You should hard-wrap commit message body lines at column 75.

Thanks for the fast feedback. Just a short note: You refer to https://robertcooper.me/post/git-commit-messages in your Contribution Guideline which limits the commit messages to 80 characters (which I've followed). It would be nice to add a note in your guidelines regarding the smaller character count :)

@sschuberth
Copy link
Member

Just a short note: You refer to https://robertcooper.me/post/git-commit-messages in your Contribution Guideline which limits the commit messages to 80 characters (which I've followed). It would be nice to add a note in your guidelines regarding the smaller character count :)

Thanks for letting us now, here's the proposed addition to the docs.

@liedQM liedQM force-pushed the fix-spm-registry-support branch from d72561e to 37c2438 Compare April 3, 2025 11:07
@fviernau
Copy link
Member

fviernau commented Apr 3, 2025

commit-msg: Should say identity instead of identifier ?

@liedQM liedQM changed the title fix(swiftpm): Use identifier as name for Swift PM registry dependencies to fix(swiftpm): Use identifier as name for Swift PM registry dependencies Apr 3, 2025
@liedQM
Copy link
Contributor Author

liedQM commented Apr 3, 2025

commit-msg: Should say identity instead of identifier ?

Thanks it seems I've mixed the terms up. Will fix it.

@liedQM liedQM changed the title fix(swiftpm): Use identifier as name for Swift PM registry dependencies fix(swiftpm): Use identity as name for Swift PM registry dependencies Apr 3, 2025
- id: "Swift::alamofire.alamofire:5.4.4"
packages:
- id: "Swift::alamofire.alamofire:5.4.4"
purl: "pkg:swift/[email protected]"
Copy link
Member

Choose a reason for hiding this comment

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

question: What do you guys think about the purl? Is the current logic appropriate which sets it, as we're dealing with private registries, could this be ambigous?

Copy link
Member

@sschuberth sschuberth Apr 3, 2025

Choose a reason for hiding this comment

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

could this be ambigous?

Theoretically it would be. If we can be sure the registry to be a non-default one, it's probably a good idea to add the repository_url qualifier to the purl.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could this be ambigous?

Theoretically it would be. If we can be sure the registry to be a non-default one, it's probably a good idea to add the repository_url qualifier to the purl.

We don't get any information regarding the used registry from the Package.resolved or Package.swift since they are defined outside the project using the swift package-registry set command for a specific scope, e.g. alarmofire (the one before the .) in the test example.

Note: The Package.swift entry for the test example would be:

.package(
   id: "alamofire.alamofire",
   from: 5.4.4
)

Currently only the `location` field is used to derive the `name` of a Swift
PM dependency. For dependencies fetched over a Package Registry Service
(Swift PM registry) the `location` field is empty which leads to incomplete
and invalid results. For those dependencies the `identity` needs to be used
instead.

Signed-off-by: Marco Lied <[email protected]>
@liedQM liedQM force-pushed the fix-spm-registry-support branch from 37c2438 to f3980be Compare April 3, 2025 11:16
@sschuberth sschuberth requested a review from fviernau April 4, 2025 06:07
@liedQM
Copy link
Contributor Author

liedQM commented Apr 7, 2025

Do you need anything from me for the PR to be merged? The missing registry support blocks us to switch to ORT since a lot of dependencies are missed in the scan.
I'll create another PR which adds target (different dependency types) support of SPM similar to maven which allows excluding test-only dependencies but that will take some time and a bigger PR to make it work.

@sschuberth
Copy link
Member

sschuberth commented Apr 7, 2025

Do you need anything from me for the PR to be merged?

@fviernau could you please do another review?

@sschuberth
Copy link
Member

Do you need anything from me for the PR to be merged?

@fviernau could you please do another review?

@fviernau are you okay to merge this (or to dismiss your review)?

@fviernau
Copy link
Member

@fviernau are you okay to merge this (or to dismiss your review)?

yes, I'm ok to merge this as a "partial" solution, even though identity may be only an SwiftPM-internal project-local unique id, for which it is questionable whether the string value is always suitable for use withing the ORT package identifier. However, it can be improved later on. (Same for the purl).


@liedQM just out of curiosity: Would you know whether SwiftPM has a command to retrieve metadata for such package from the remote registry. E.g. the name, description and so forth?

@fviernau fviernau dismissed their stale review April 15, 2025 09:01

I'm ok with this.

@sschuberth sschuberth merged commit 3e310dc into oss-review-toolkit:main Apr 15, 2025
25 checks passed
@liedQM
Copy link
Contributor Author

liedQM commented Apr 22, 2025

@fviernau currently I'm not aware of any way despite reading it out of the a global settings file. I've been looking into the available swift pm commands and haven't found any to read the current scope configuration yet.
Nevertheless the SPM registry works like the maven repositories where a dependency can be loaded from any registry which provides the library, so it can be multiple ones.
Are you saving this information for maven dependencies as well? If yes I can dig deeper after my scope fix PR but if not I would leave it out for SPM as well.

@liedQM
Copy link
Contributor Author

liedQM commented Apr 22, 2025

Thanks for merging my PR :)

@sschuberth
Copy link
Member

Are you saving this information for maven dependencies as well?

Yes, we do.

@liedQM liedQM deleted the fix-spm-registry-support branch April 23, 2025 07:22
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.

3 participants