Skip to content

Commit

Permalink
Merge pull request #42 from marinofelipe/feat/5_9_package_dump
Browse files Browse the repository at this point in the history
Fix decoding Swift 5.9 package content
  • Loading branch information
marinofelipe authored Sep 4, 2023
2 parents 7d34abe + 656b732 commit 1d0c284
Show file tree
Hide file tree
Showing 3 changed files with 263 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Sources/Core/Models/PackageContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,20 @@ public struct PackageContent: Decodable, Equatable {
public let revision: [String]
public let branch: [String]
}

#if compiler(<5.9)
public struct Location: Decodable, Equatable, Hashable {
public let remote: [String]
}
#else
public struct Location: Decodable, Hashable {
public struct RemoteURL: Decodable, Hashable {
let urlString: String
}

public let remote: [RemoteURL]
}
#endif

public let name: String
public let urlString: String
Expand Down Expand Up @@ -291,7 +302,11 @@ extension PackageContent.Dependency: Decodable {
let location = try? container.decode(Location.self, forKey: .location),
let remote = location.remote.first
{
#if compiler(<5.9)
self.urlString = remote
#else
self.urlString = remote.urlString
#endif
} else {
self.urlString = try container.decodeIfPresent(String.self, forKey: .urlString)
?? container.decodeIfPresent(String.self, forKey: .path)
Expand Down
42 changes: 42 additions & 0 deletions Tests/CoreTests/Models/PackageContentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ final class PackageContentTests: XCTestCase {
)
}

#if compiler(>=5.5)
func testWhenPackageContentIsGeneratedFromSwift5Dot5Toolchain() throws {
let fixtureData = try dataFromJSON(
named: "package_full_swift_5_5",
Expand All @@ -236,7 +237,10 @@ final class PackageContentTests: XCTestCase {
.defaultExpectedFullPackage()
)
}
#endif


#if compiler(<5.7)
func testWhenPackageContentIsGeneratedFromSwift5Dot6Toolchain() throws {
let fixtureData = try dataFromJSON(
named: "package_full_swift_5_6",
Expand Down Expand Up @@ -271,6 +275,44 @@ final class PackageContentTests: XCTestCase {
)
)
}
#endif

#if compiler(>=5.9)
func testWhenPackageContentIsGeneratedFromSwift5Dot9Toolchain() throws {
let fixtureData = try dataFromJSON(
named: "package_full_swift_5_9",
bundle: .module
)
let packageContent = try jsonDecoder.decode(PackageContent.self, from: fixtureData)

XCTAssertEqual(
packageContent,
.defaultExpectedFullPackage(
dependencies: [
.init(
name: "swift-argument-parser",
urlString: "https://github.com/apple/swift-argument-parser",
requirement: .init(
range: [
.init(
lowerBound: "0.3.0",
upperBound: "0.4.0"
)
],
revision: [],
branch: []
)
),
.init(
name: "packages",
urlString: "path/Packages",
requirement: nil
)
]
)
)
}
#endif

func testWhenPackageDependencyHasIdentityOnly() throws {
let fixtureData = try dataFromJSON(
Expand Down
206 changes: 206 additions & 0 deletions Tests/CoreTests/Resources/package_full_swift_5_9.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
{
"cLanguageStandard" : null,
"cxxLanguageStandard" : null,
"dependencies" : [
{
"sourceControl" : [
{
"identity": "swift-argument-parser",
"location" : {
"remote" : [
{
"urlString": "https://github.com/apple/swift-argument-parser"
}
]
},
"productFilter" : null,
"requirement" : {
"range" : [
{
"lowerBound" : "0.3.0",
"upperBound" : "0.4.0"
}
]
}
}
],
},
{
"fileSystem" : [
{
"identity" : "packages",
"path" : "path/Packages",
"productFilter" : null
}
]
}
],
"name" : "SomePackage",
"packageKind" : {
"root" : [
"path/swift-argument-parser"
]
},
"pkgConfig" : null,
"platforms" : [
{
"options" : [

],
"platformName" : "ios",
"version" : "9.0"
},
{
"options" : [

],
"platformName" : "macos",
"version" : "10.15"
}
],
"products" : [
{
"name" : "Product1",
"targets" : [
"Target1",
"Target2"
],
"type" : {
"library" : [
"automatic"
]
}
},
{
"name" : "Product2",
"targets" : [
"Target1",
"Target3"
],
"type" : {
"library" : [
"static"
]
}
},
{
"name" : "Product3",
"targets" : [
"Target2"
],
"type" : {
"executable" : null
}
},
{
"name" : "Product4",
"targets" : [
"Target1"
],
"type" : {
"library" : [
"dynamic"
]
}
}
],
"providers" : null,
"swiftLanguageVersions" : [
"5"
],
"targets" : [
{
"dependencies" : [
{
"product" : [
"swift-argument-parser",
null
]
}
],
"exclude" : [

],
"name" : "Target1",
"path" : "Path1",
"resources" : [

],
"settings" : [

],
"type" : "regular"
},
{
"dependencies" : [
{
"byName" : [
"Target1",
null
]
}
],
"exclude" : [

],
"name" : "Target2",
"path" : "Sources/2",
"resources" : [

],
"settings" : [

],
"type" : "binary"
},
{
"dependencies" : [
{
"product" : [
"ArgumentParser",
"swift-argument-parser",
null
]
},
{
"target" : [
"Target1",
null
]
}
],
"exclude" : [

],
"name" : "Target3",
"path" : "Tests",
"resources" : [

],
"settings" : [

],
"type" : "test"
},
{
"dependencies" : [

],
"exclude" : [

],
"name" : "Target4",
"path" : "Path",
"resources" : [

],
"settings" : [

],
"type" : "system"
}
],
"toolsVersion" : {
"_version" : "5.3.0"
}
}

0 comments on commit 1d0c284

Please sign in to comment.