Skip to content

Commit 3e310dc

Browse files
liedQMsschuberth
authored andcommitted
fix(swiftpm): Use identity as name for Swift PM registry deps
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]>
1 parent f17867c commit 3e310dc

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
project:
3+
id: "SwiftPM::src/funTest/assets/projects/synthetic/only-lockfile-v3-with-SPM-registry-dependency/Package.resolved:<REPLACE_REVISION>"
4+
definition_file_path: "<REPLACE_DEFINITION_FILE_PATH>"
5+
declared_licenses: []
6+
declared_licenses_processed: {}
7+
vcs:
8+
type: ""
9+
url: ""
10+
revision: ""
11+
path: ""
12+
vcs_processed:
13+
type: "Git"
14+
url: "<REPLACE_URL_PROCESSED>"
15+
revision: "<REPLACE_REVISION>"
16+
path: "<REPLACE_PATH>"
17+
homepage_url: ""
18+
scopes:
19+
- name: "dependencies"
20+
dependencies:
21+
- id: "Swift::alamofire.alamofire:5.4.4"
22+
packages:
23+
- id: "Swift::alamofire.alamofire:5.4.4"
24+
purl: "pkg:swift/[email protected]"
25+
declared_licenses: []
26+
declared_licenses_processed: {}
27+
description: ""
28+
homepage_url: ""
29+
binary_artifact:
30+
url: ""
31+
hash:
32+
value: ""
33+
algorithm: ""
34+
source_artifact:
35+
url: ""
36+
hash:
37+
value: ""
38+
algorithm: ""
39+
vcs:
40+
type: ""
41+
url: ""
42+
revision: ""
43+
path: ""
44+
vcs_processed:
45+
type: ""
46+
url: ""
47+
revision: ""
48+
path: ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"pins" : [
3+
{
4+
"identity" : "alamofire.alamofire",
5+
"kind" : "registry",
6+
"location" : "",
7+
"state" : {
8+
"version" : "5.4.4"
9+
}
10+
}
11+
],
12+
"version" : 3
13+
}

plugins/package-managers/swiftpm/src/funTest/kotlin/SwiftPmFunTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ class SwiftPmFunTest : WordSpec({
7373
}
7474
}
7575

76+
"Analyzing a lockfile with a dependency loaded over SPM registry instead of source control" should {
77+
"return the correct result" {
78+
val definitionFile =
79+
getAssetFile("projects/synthetic/only-lockfile-v3-with-SPM-registry-dependency/Package.resolved")
80+
val expectedResultFile =
81+
getAssetFile("projects/synthetic/expected-output-only-lockfile-v3-with-SPM-registry-dependency.yml")
82+
83+
val result = SwiftPmFactory.create().resolveSingleProject(definitionFile)
84+
85+
result.withInvariantIssues().toYaml() should matchExpectedResult(expectedResultFile, definitionFile)
86+
}
87+
}
88+
7689
"Analyzing a definition file with a sibling lockfile" should {
7790
"return the correct result" {
7891
val definitionFile = getAssetFile("projects/synthetic/project-with-lockfile/Package.swift")

plugins/package-managers/swiftpm/src/main/kotlin/SwiftPm.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,12 @@ private fun PinV2.toId(): Identifier =
244244
Identifier(
245245
type = PACKAGE_TYPE,
246246
namespace = "",
247-
name = getCanonicalName(location),
247+
// For SPM registry dependencies the `location` field is blank, so use the `identity` field instead.
248+
name = if (kind == PinV2.Kind.REGISTRY) {
249+
identity
250+
} else {
251+
getCanonicalName(location)
252+
},
248253
version = state?.run {
249254
when {
250255
!version.isNullOrBlank() -> version

0 commit comments

Comments
 (0)