-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.swift
130 lines (106 loc) · 4.33 KB
/
Package.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// swift-tools-version: 5.7
// © 2022 TomTom N.V. All rights reserved.
//
// This software is the proprietary copyright of TomTom N.V. and its subsidiaries and may be
// used for internal evaluation purposes or commercial use strictly subject to separate
// license agreement between you and TomTom N.V. If you are the licensee, you are only permitted
// to use this software in accordance with the terms of your license agreement. If you are
// not the licensee, you are not authorized to use this software in any manner and should
// immediately return or destroy it.
import PackageDescription
let sdkVersion = "0.67.0"
let package = Package(
name: "TomTomSDKTelemetryFrameworks",
defaultLocalization: "en",
platforms: [.iOS(.v14)],
products: [ /* products are set later */ ],
dependencies: [
.package(url: "https://github.com/tomtom-international/tomtom-sdk-spm-core", exact: Version(stringLiteral: sdkVersion)),
.package(url: "https://github.com/apple/swift-protobuf.git", exact: "1.25.2"),
.package(url: "https://github.com/antlr/antlr4.git", exact: "4.13.1"),
],
targets: [ /* targets are set later */ ],
swiftLanguageVersions: [.v5]
)
let modules: [Module] = [
Module("TomTomSDKTelemetryConfigProvider", sha: "d75d1e26084237288882c1cef7b0c3dea81babe6826175dcadef463aacd59533", version: "0.67.0", dependencies: [
.corePackageModule("TomTomSDKCommon"),
.corePackageModule("TomTomSDKLocationProvider"),
.corePackageModule("TomTomSDKTelemetry"),
.corePackageModule("TomTomSDKRoute"),
.thirdpartyPackageModule("SwiftProtobuf", package: "swift-protobuf"),
.thirdpartyPackageModule("Antlr4", package: "antlr4"),
]),
]
package.products = modules.products
package.targets = modules.targets
private extension String {
func artefactUrl(version: String) -> String {
"https://repositories.tomtom.com/artifactory/spm/TomTomSDK/Telemetry/binaries/\(self)/\(version)/\(self).zip"
}
var wrapperName: String {
return self + "Wrapper"
}
}
struct Module {
let frameworkName: String
let sha: String
let dependencies: [ModuleDependency]
let version: String
let isProduct: Bool
init(_ frameworkName: String, sha: String, version: String, isProduct: Bool = true, dependencies: [ModuleDependency] = []) {
self.frameworkName = frameworkName
self.sha = sha
self.version = version
self.isProduct = isProduct
self.dependencies = dependencies
}
var product: Product? {
return isProduct ? .library(name: frameworkName, targets: [wrapperName]) : nil
}
var wrapperName: String {
frameworkName.wrapperName
}
var targets: [Target] {
let binaryTargetDependency: Target.Dependency = .target(name: frameworkName)
let dependenciesTargets: [Target.Dependency] = dependencies.map { $0.dependency }
let mainTargetDependencies = [binaryTargetDependency] + dependenciesTargets
let mainTarget: Target = .target(name: wrapperName, dependencies: mainTargetDependencies)
let binaryUrl = frameworkName.artefactUrl(version: version)
let binaryTarget: Target = .binaryTarget(name: frameworkName, url: binaryUrl, checksum: sha)
return [mainTarget, binaryTarget]
}
}
struct ModuleDependency {
let name: String
let package: String?
var dependency: Target.Dependency {
if let package = package {
return .product(name: name, package: package)
}
return .target(name: name.wrapperName)
}
static func thirdpartyPackageModule(_ name: String, package: String) -> ModuleDependency {
ModuleDependency(name: name, package: package)
}
static func corePackageModule(_ name: String) -> ModuleDependency {
ModuleDependency(name: name, package: "tomtom-sdk-spm-core")
}
static func telemetryPackageModule(_ name: String) -> ModuleDependency {
ModuleDependency(name: name, package: nil)
}
}
extension ModuleDependency: ExpressibleByStringLiteral {
init(stringLiteral value: String) {
self.init(name: value, package: nil)
}
public typealias StringLiteralType = String
}
extension Array where Element == Module {
var products: [Product] {
compactMap { $0.product }
}
var targets: [Target] {
flatMap { $0.targets }
}
}