Skip to content

Commit 0be9c3c

Browse files
authored
JSON models got moved to separate module (#14)
See swiftlang/swift-package-manager#3199
1 parent 7817f0b commit 0be9c3c

File tree

7 files changed

+57
-30
lines changed

7 files changed

+57
-30
lines changed

Sources/PackageCollectionDiff/PackageCollectionDiff.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift Package Collection Generator open source project
44
//
5-
// Copyright (c) 2020 Apple Inc. and the Swift Package Collection Generator project authors
5+
// Copyright (c) 2020-2021 Apple Inc. and the Swift Package Collection Generator project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -14,7 +14,7 @@
1414

1515
import ArgumentParser
1616
import Foundation
17-
import PackageCollections
17+
import PackageCollectionsModel
1818
import TSCBasic
1919
import Utilities
2020

@@ -32,7 +32,7 @@ public struct PackageCollectionDiff: ParsableCommand {
3232
@Flag(name: .long, help: "Show extra logging for debugging purposes")
3333
private var verbose: Bool = false
3434

35-
typealias Model = JSONPackageCollectionModel.V1
35+
typealias Model = PackageCollectionModel.V1
3636

3737
public init() {}
3838

Sources/PackageCollectionGenerator/Models/PackageCollectionExtensions.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift Package Collection Generator open source project
44
//
5-
// Copyright (c) 2020 Apple Inc. and the Swift Package Collection Generator project authors
5+
// Copyright (c) 2020-2021 Apple Inc. and the Swift Package Collection Generator project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -12,9 +12,9 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import PackageCollections
15+
import PackageCollectionsModel
1616

17-
extension JSONPackageCollectionModel.V1.Collection: CustomStringConvertible {
17+
extension PackageCollectionModel.V1.Collection: CustomStringConvertible {
1818
public var description: String {
1919
"""
2020
Collection {
@@ -31,13 +31,13 @@ extension JSONPackageCollectionModel.V1.Collection: CustomStringConvertible {
3131
}
3232
}
3333

34-
extension JSONPackageCollectionModel.V1.Collection.Author: CustomStringConvertible {
34+
extension PackageCollectionModel.V1.Collection.Author: CustomStringConvertible {
3535
public var description: String {
3636
self.name
3737
}
3838
}
3939

40-
extension JSONPackageCollectionModel.V1.Collection.Package: CustomStringConvertible {
40+
extension PackageCollectionModel.V1.Collection.Package: CustomStringConvertible {
4141
public var description: String {
4242
"""
4343
Package {
@@ -52,7 +52,7 @@ extension JSONPackageCollectionModel.V1.Collection.Package: CustomStringConverti
5252
}
5353
}
5454

55-
extension JSONPackageCollectionModel.V1.Collection.Package.Version: CustomStringConvertible {
55+
extension PackageCollectionModel.V1.Collection.Package.Version: CustomStringConvertible {
5656
public var description: String {
5757
"""
5858
Version {
@@ -69,7 +69,7 @@ extension JSONPackageCollectionModel.V1.Collection.Package.Version: CustomString
6969
}
7070
}
7171

72-
extension JSONPackageCollectionModel.V1.Target: CustomStringConvertible {
72+
extension PackageCollectionModel.V1.Target: CustomStringConvertible {
7373
public var description: String {
7474
"""
7575
Target(
@@ -80,7 +80,7 @@ extension JSONPackageCollectionModel.V1.Target: CustomStringConvertible {
8080
}
8181
}
8282

83-
extension JSONPackageCollectionModel.V1.Product: CustomStringConvertible {
83+
extension PackageCollectionModel.V1.Product: CustomStringConvertible {
8484
public var description: String {
8585
"""
8686
Product(
@@ -92,25 +92,25 @@ extension JSONPackageCollectionModel.V1.Product: CustomStringConvertible {
9292
}
9393
}
9494

95-
extension JSONPackageCollectionModel.V1.PlatformVersion: CustomStringConvertible {
95+
extension PackageCollectionModel.V1.PlatformVersion: CustomStringConvertible {
9696
public var description: String {
9797
"\(self.name)(\(self.version))"
9898
}
9999
}
100100

101-
extension JSONPackageCollectionModel.V1.Compatibility: CustomStringConvertible {
101+
extension PackageCollectionModel.V1.Compatibility: CustomStringConvertible {
102102
public var description: String {
103103
"(\(self.platform), \(self.swiftVersion))"
104104
}
105105
}
106106

107-
extension JSONPackageCollectionModel.V1.Platform: CustomStringConvertible {
107+
extension PackageCollectionModel.V1.Platform: CustomStringConvertible {
108108
public var description: String {
109109
self.name
110110
}
111111
}
112112

113-
extension JSONPackageCollectionModel.V1.License: CustomStringConvertible {
113+
extension PackageCollectionModel.V1.License: CustomStringConvertible {
114114
public var description: String {
115115
"License(\(self.url)\(self.name.map { ", \($0)" } ?? ""))"
116116
}

Sources/PackageCollectionGenerator/Models/PackageCollectionGeneratorInput.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift Package Collection Generator open source project
44
//
5-
// Copyright (c) 2020 Apple Inc. and the Swift Package Collection Generator project authors
5+
// Copyright (c) 2020-2021 Apple Inc. and the Swift Package Collection Generator project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -13,7 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import Foundation
16-
import PackageCollections
16+
import PackageCollectionsModel
1717

1818
/// Input for the `package-collection-generate` command
1919
public struct PackageCollectionGeneratorInput: Equatable, Codable {
@@ -30,14 +30,14 @@ public struct PackageCollectionGeneratorInput: Equatable, Codable {
3030
public let packages: [Package]
3131

3232
/// The author of this package collection.
33-
public let author: JSONPackageCollectionModel.V1.Collection.Author?
33+
public let author: PackageCollectionModel.V1.Collection.Author?
3434

3535
public init(
3636
name: String,
3737
overview: String? = nil,
3838
keywords: [String]? = nil,
3939
packages: [Package],
40-
author: JSONPackageCollectionModel.V1.Collection.Author? = nil
40+
author: PackageCollectionModel.V1.Collection.Author? = nil
4141
) {
4242
self.name = name
4343
self.overview = overview

Sources/PackageCollectionGenerator/PackageCollectionGenerate.swift

+31-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift Package Collection Generator open source project
44
//
5-
// Copyright (c) 2020 Apple Inc. and the Swift Package Collection Generator project authors
5+
// Copyright (c) 2020-2021 Apple Inc. and the Swift Package Collection Generator project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -14,7 +14,8 @@
1414

1515
import ArgumentParser
1616
import Foundation
17-
import PackageCollections
17+
import PackageCollectionsModel
18+
import PackageModel
1819
import TSCBasic
1920
import TSCUtility
2021
import Utilities
@@ -47,7 +48,7 @@ public struct PackageCollectionGenerate: ParsableCommand {
4748
@Flag(name: .long, help: "Show extra logging for debugging purposes")
4849
private var verbose: Bool = false
4950

50-
typealias Model = JSONPackageCollectionModel.V1
51+
typealias Model = PackageCollectionModel.V1
5152

5253
public init() {}
5354

@@ -226,7 +227,7 @@ public struct PackageCollectionGenerate: ParsableCommand {
226227
.map { product in
227228
Model.Product(
228229
name: product.name,
229-
type: product.type,
230+
type: Model.ProductType(from: product.type),
230231
targets: product.targets
231232
)
232233
}
@@ -294,3 +295,29 @@ public struct PackageCollectionGenerate: ParsableCommand {
294295
return versions
295296
}
296297
}
298+
299+
extension PackageCollectionModel.V1.ProductType {
300+
init(from: PackageModel.ProductType) {
301+
switch from {
302+
case .library(let libraryType):
303+
self = .library(.init(from: libraryType))
304+
case .executable:
305+
self = .executable
306+
case .test:
307+
self = .test
308+
}
309+
}
310+
}
311+
312+
extension PackageCollectionModel.V1.ProductType.LibraryType {
313+
init(from: PackageModel.ProductType.LibraryType) {
314+
switch from {
315+
case .static:
316+
self = .static
317+
case .dynamic:
318+
self = .dynamic
319+
case .automatic:
320+
self = .automatic
321+
}
322+
}
323+
}

Sources/PackageCollectionValidator/PackageCollectionValidate.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift Package Collection Generator open source project
44
//
5-
// Copyright (c) 2020 Apple Inc. and the Swift Package Collection Generator project authors
5+
// Copyright (c) 2020-2021 Apple Inc. and the Swift Package Collection Generator project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -14,9 +14,9 @@
1414

1515
import ArgumentParser
1616
import Foundation
17-
import enum PackageCollections.JSONPackageCollectionModel
1817
import enum PackageCollections.ValidationError
1918
import struct PackageCollections.ValidationMessage
19+
import enum PackageCollectionsModel.PackageCollectionModel
2020
import TSCBasic
2121
import Utilities
2222

@@ -34,7 +34,7 @@ public struct PackageCollectionValidate: ParsableCommand {
3434
@Flag(name: .long, help: "Show extra logging for debugging purposes")
3535
private var verbose: Bool = false
3636

37-
typealias Model = JSONPackageCollectionModel.V1
37+
typealias Model = PackageCollectionModel.V1
3838

3939
public init() {}
4040

Tests/PackageCollectionGeneratorExecutableTests/PackageCollectionGenerateTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift Package Collection Generator open source project
44
//
5-
// Copyright (c) 2020 Apple Inc. and the Swift Package Collection Generator project authors
5+
// Copyright (c) 2020-2021 Apple Inc. and the Swift Package Collection Generator project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -14,14 +14,14 @@
1414

1515
import Foundation
1616
@testable import PackageCollectionGenerator
17-
import PackageCollections
17+
import PackageCollectionsModel
1818
@testable import TestUtilities
1919
import TSCBasic
2020
import TSCUtility
2121
import XCTest
2222

2323
final class PackageCollectionGenerateTests: XCTestCase {
24-
typealias Model = JSONPackageCollectionModel.V1
24+
typealias Model = PackageCollectionModel.V1
2525

2626
func test_help() throws {
2727
XCTAssert(try executeCommand(command: "package-collection-generate --help")

scripts/sanity.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1919

2020
function replace_acceptable_years() {
2121
# this needs to replace all acceptable forms with 'YEARS'
22-
sed -e 's/2017-2018/YEARS/' -e 's/2019-2020/YEARS/' -e 's/2019/YEARS/' -e 's/2020/YEARS/'
22+
sed -e 's/2020-2021/YEARS/' -e 's/2020/YEARS/' -e 's/2021/YEARS/'
2323
}
2424

2525
printf "=> Checking format... "

0 commit comments

Comments
 (0)