Skip to content

Commit

Permalink
feat(swiftpm): Support lockfile format version 3
Browse files Browse the repository at this point in the history
The lockfile format version 2 and 3 are quite similar, so that the same
parsing logic can be used.

Note that the updated `Package.resolved` files have been manually
created, as XCode wasn't available.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Mar 15, 2024
1 parent f8b76d7 commit 786d3a6
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,34 @@ project:
revision: "<REPLACE_REVISION>"
path: "<REPLACE_PATH>"
homepage_url: ""
scopes: []
packages: []
issues:
- timestamp: "1970-01-01T00:00:00Z"
source: "SwiftPM"
message: "Could not parse lockfile '<REPLACE_ABSOLUTE_DEFINITION_FILE_PATH>'.\
\ Unknown file format version '3'."
severity: "ERROR"
scopes:
- name: "dependencies"
dependencies:
- id: "Swift::github.com/alamofire/alamofire:5.4.4"
packages:
- id: "Swift::github.com/alamofire/alamofire:5.4.4"
purl: "pkg:swift/github.com%2Falamofire%[email protected]"
declared_licenses: []
declared_licenses_processed: {}
description: ""
homepage_url: ""
binary_artifact:
url: ""
hash:
value: ""
algorithm: ""
source_artifact:
url: ""
hash:
value: ""
algorithm: ""
vcs:
type: "Git"
url: "https://github.com/Alamofire/Alamofire.git"
revision: "d120af1e8638c7da36c8481fd61a66c0c08dc4fc"
path: ""
vcs_processed:
type: "Git"
url: "https://github.com/Alamofire/Alamofire.git"
revision: "d120af1e8638c7da36c8481fd61a66c0c08dc4fc"
path: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
project:
id: "SwiftPM::src/funTest/assets/projects/synthetic/only-lockfile-v4/Package.resolved:<REPLACE_REVISION>"
definition_file_path: "<REPLACE_DEFINITION_FILE_PATH>"
declared_licenses: []
declared_licenses_processed: {}
vcs:
type: ""
url: ""
revision: ""
path: ""
vcs_processed:
type: "Git"
url: "<REPLACE_URL_PROCESSED>"
revision: "<REPLACE_REVISION>"
path: "<REPLACE_PATH>"
homepage_url: ""
scopes: []
packages: []
issues:
- timestamp: "1970-01-01T00:00:00Z"
source: "SwiftPM"
message: "Could not parse lockfile '<REPLACE_ABSOLUTE_DEFINITION_FILE_PATH>'.\
\ Unknown file format version '4'."
severity: "ERROR"
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{
"version": 3
}
"pins" : [
{
"identity" : "alamofire",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire.git",
"state" : {
"revision" : "d120af1e8638c7da36c8481fd61a66c0c08dc4fc",
"version" : "5.4.4"
}
}
],
"version" : 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version" : 4
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SwiftPmFunTest : WordSpec({
}
}

"Analyzing a lockfile with unsupported file format version 3" should {
"Analyzing a lockfile with file format version 3" should {
"return the correct result" {
val definitionFile = getAssetFile("projects/synthetic/only-lockfile-v3/Package.resolved")
val expectedResultFile = getAssetFile("projects/synthetic/expected-output-only-lockfile-v3.yml")
Expand All @@ -63,6 +63,17 @@ class SwiftPmFunTest : WordSpec({
}
}

"Analyzing a lockfile with unsupported file format version 4" should {
"return the correct result" {
val definitionFile = getAssetFile("projects/synthetic/only-lockfile-v4/Package.resolved")
val expectedResultFile = getAssetFile("projects/synthetic/expected-output-only-lockfile-v4.yml")

val result = create(PROJECT_TYPE).resolveSingleProject(definitionFile)

result.withInvariantIssues().toYaml() should matchExpectedResult(expectedResultFile, definitionFile)
}
}

"Analyzing a definition file with a sibling lockfile" should {
"return the correct result" {
val definitionFile = getAssetFile("projects/synthetic/project-with-lockfile/Package.swift")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ internal fun parseLockfile(packageResolvedFile: File): Result<Set<PinV2>> =
pinsJson?.let { json.decodeFromJsonElement<List<PinV1>>(it) }.orEmpty().map { it.toPinV2(projectDir) }
}

"2" -> {
// See https://github.com/apple/swift-package-manager/blob/3ef830dddff459e569d6e49c186c3ded33c39bcc/Sources/PackageGraph/PinsStore.swift#L387.
"2", "3" -> {
// See https://github.com/apple/swift-package-manager/blob/3ef830dddff459e569d6e49c186c3ded33c39bcc/Sources/PackageGraph/PinsStore.swift#L387
// and https://github.com/apple/swift-package-manager/blob/3ef830dddff459e569d6e49c186c3ded33c39bcc/Sources/PackageGraph/PinsStore.swift#L465.
val pinsJson = root["pins"]
pinsJson?.let { json.decodeFromJsonElement<List<PinV2>>(it) }.orEmpty()
}
Expand Down

0 comments on commit 786d3a6

Please sign in to comment.