From 345c2251924afbbb575025495fc9e49128d9cff7 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Thu, 14 Mar 2024 09:36:46 +0100 Subject: [PATCH 1/2] docs(swiftpm): Add links to the data model of the lockfile Signed-off-by: Frank Viernau --- .../package-managers/swiftpm/src/main/kotlin/SwiftPmModel.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPmModel.kt b/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPmModel.kt index 1538aa8f26e03..074ccdfbd6099 100644 --- a/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPmModel.kt +++ b/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPmModel.kt @@ -91,12 +91,14 @@ internal fun parseLockfile(packageResolvedFile: File): Result> = 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>(it) }.orEmpty().map { it.toPinV2(projectDir) } } "2" -> { + // See https://github.com/apple/swift-package-manager/blob/3ef830dddff459e569d6e49c186c3ded33c39bcc/Sources/PackageGraph/PinsStore.swift#L387. val pinsJson = root["pins"] pinsJson?.let { json.decodeFromJsonElement>(it) }.orEmpty() } From e2ec8a3296c9315b548a94e5b433ca013cb770b8 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Thu, 14 Mar 2024 10:45:19 +0100 Subject: [PATCH 2/2] feat(swiftpm): Support lockfile format version 3 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 --- .../expected-output-only-lockfile-v3.yml | 39 +++++++++++++++---- .../expected-output-only-lockfile-v4.yml | 25 ++++++++++++ .../only-lockfile-v3/Package.resolved | 15 ++++++- .../only-lockfile-v4/Package.resolved | 3 ++ .../src/funTest/kotlin/SwiftPmFunTest.kt | 13 ++++++- .../swiftpm/src/main/kotlin/SwiftPmModel.kt | 5 ++- 6 files changed, 87 insertions(+), 13 deletions(-) create mode 100644 plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/expected-output-only-lockfile-v4.yml create mode 100644 plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/only-lockfile-v4/Package.resolved diff --git a/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/expected-output-only-lockfile-v3.yml b/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/expected-output-only-lockfile-v3.yml index 81c40d1ed47bc..a14c4de07fbf3 100644 --- a/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/expected-output-only-lockfile-v3.yml +++ b/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/expected-output-only-lockfile-v3.yml @@ -15,11 +15,34 @@ project: revision: "" path: "" homepage_url: "" - scopes: [] -packages: [] -issues: -- timestamp: "1970-01-01T00:00:00Z" - source: "SwiftPM" - message: "Could not parse lockfile ''.\ - \ 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%2Falamofire@5.4.4" + 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: "" diff --git a/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/expected-output-only-lockfile-v4.yml b/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/expected-output-only-lockfile-v4.yml new file mode 100644 index 0000000000000..b7630f1ffba65 --- /dev/null +++ b/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/expected-output-only-lockfile-v4.yml @@ -0,0 +1,25 @@ +--- +project: + id: "SwiftPM::src/funTest/assets/projects/synthetic/only-lockfile-v4/Package.resolved:" + definition_file_path: "" + declared_licenses: [] + declared_licenses_processed: {} + vcs: + type: "" + url: "" + revision: "" + path: "" + vcs_processed: + type: "Git" + url: "" + revision: "" + path: "" + homepage_url: "" + scopes: [] +packages: [] +issues: +- timestamp: "1970-01-01T00:00:00Z" + source: "SwiftPM" + message: "Could not parse lockfile ''.\ + \ Unknown file format version '4'." + severity: "ERROR" diff --git a/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/only-lockfile-v3/Package.resolved b/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/only-lockfile-v3/Package.resolved index cd2f236b292fc..8ad10b52a43e9 100644 --- a/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/only-lockfile-v3/Package.resolved +++ b/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/only-lockfile-v3/Package.resolved @@ -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 +} \ No newline at end of file diff --git a/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/only-lockfile-v4/Package.resolved b/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/only-lockfile-v4/Package.resolved new file mode 100644 index 0000000000000..d31cbf115c7ff --- /dev/null +++ b/plugins/package-managers/swiftpm/src/funTest/assets/projects/synthetic/only-lockfile-v4/Package.resolved @@ -0,0 +1,3 @@ +{ + "version" : 4 +} \ No newline at end of file diff --git a/plugins/package-managers/swiftpm/src/funTest/kotlin/SwiftPmFunTest.kt b/plugins/package-managers/swiftpm/src/funTest/kotlin/SwiftPmFunTest.kt index 2c3e5da01f8ce..f5167a574dac1 100644 --- a/plugins/package-managers/swiftpm/src/funTest/kotlin/SwiftPmFunTest.kt +++ b/plugins/package-managers/swiftpm/src/funTest/kotlin/SwiftPmFunTest.kt @@ -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") @@ -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") diff --git a/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPmModel.kt b/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPmModel.kt index 074ccdfbd6099..c55d4844435b1 100644 --- a/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPmModel.kt +++ b/plugins/package-managers/swiftpm/src/main/kotlin/SwiftPmModel.kt @@ -97,8 +97,9 @@ internal fun parseLockfile(packageResolvedFile: File): Result> = pinsJson?.let { json.decodeFromJsonElement>(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>(it) }.orEmpty() }