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

SwiftPM: Support lockfile format v3 #8413

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -91,12 +91,15 @@ internal fun parseLockfile(packageResolvedFile: File): Result<Set<PinV2>> =

when (val version = root.getValue("version").jsonPrimitive.content) {
"1" -> {
// See https://github.com/apple/swift-package-manager/blob/3ef830dddff459e569d6e49c186c3ded33c39bcc/Sources/PackageGraph/PinsStore.swift#L285.
val projectDir = packageResolvedFile.parentFile
val pinsJson = root["object"]?.jsonObject?.get("pins")
pinsJson?.let { json.decodeFromJsonElement<List<PinV1>>(it) }.orEmpty().map { it.toPinV2(projectDir) }
}

"2" -> {
"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
Loading