-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPackage.swift
More file actions
223 lines (209 loc) · 7.86 KB
/
Copy pathPackage.swift
File metadata and controls
223 lines (209 loc) · 7.86 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// swift-tools-version: 6.2
//
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import Foundation
import PackageDescription
// The package file for the `google-cloud-swift` monorepo.
//
// This file is only used for development, each package in the `generated/*` and `packages/*`
// subdirectories will have its own repository, this file will play no role in them.
//
// The file uses a helper function to create the full list of packages. The function returns a
// different value in CI builds, so we can compile all the packages using SPM. In the development
// environment this is too slow.
let generated: [Generated] = selectGeneratedPackages()
let generatedDependencies: [Package.Dependency] = generated.map {
let path = "./generated/\($0.name)"
if $0.traits.isEmpty {
return .package(path: path)
}
return .package(path: path, traits: $0.traits)
}
let generatedModules: [Target.Dependency] = generated.map {
.product(name: $0.module, package: $0.name)
}
let package = Package(
name: "GoogleCloudSwift",
platforms: [
.macOS(.v15)
],
traits: [
"IntegrationTests"
],
dependencies: [
// Reference local packages via paths
.package(path: "./packages/auth"),
.package(
path: "./packages/gax",
traits: [
.trait(name: "IntegrationTests", condition: .when(traits: ["IntegrationTests"]))
],
),
.package(path: "./packages/test-helpers"),
.package(path: "./packages/wkt"),
.package(path: "./packages/storage"),
.package(path: "./guide"),
.package(url: "https://github.com/apple/swift-log", from: "1.12.0"),
// Only used for development.
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
] + generatedDependencies,
targets: [
.testTarget(
name: "AllModules",
dependencies: [
.product(name: "UserGuide", package: "guide"),
.product(name: "GoogleCloudAuth", package: "auth"),
.product(name: "GoogleCloudGax", package: "gax"),
.product(name: "GoogleCloudWkt", package: "wkt"),
] + generatedModules,
),
.testTarget(
name: "Discovery",
dependencies: [
.product(name: "GoogleCloudWkt", package: "wkt")
],
exclude: ["disco/"],
),
.testTarget(
name: "ProtoJSON",
dependencies: [
.product(name: "GoogleCloudGax", package: "gax"),
.product(name: "GoogleCloudWkt", package: "wkt"),
],
exclude: ["protos/"],
),
.testTarget(
name: "DiscoveryBasedClient",
dependencies: [
.product(name: "GoogleCloudComputeV1", package: "google-cloud-compute-v1"),
.product(name: "GoogleCloudWkt", package: "wkt"),
.product(name: "GoogleCloudTestHelpers", package: "test-helpers"),
],
exclude: ["README.md"],
),
.testTarget(
name: "ProtoBasedClient",
dependencies: [
.product(name: "GoogleCloudSecretManagerV1", package: "google-cloud-secretmanager-v1"),
.product(name: "GoogleCloudWorkflowsV1", package: "google-cloud-workflows-v1"),
.product(name: "GoogleCloudLocation", package: "google-cloud-location"),
.product(name: "GoogleIAMV1", package: "google-iam-v1"),
.product(name: "GoogleCloudGax", package: "gax"),
.product(name: "GoogleCloudWkt", package: "wkt"),
.product(name: "GoogleCloudStorage", package: "storage"),
.product(name: "GoogleCloudTestHelpers", package: "test-helpers"),
.product(name: "InMemoryLogging", package: "swift-log"),
],
exclude: ["README.md"],
),
.testTarget(
name: "Any",
dependencies: [
.product(name: "GoogleCloudWkt", package: "wkt"),
.product(name: "GoogleCloudSecretManagerV1", package: "google-cloud-secretmanager-v1"),
],
),
.testTarget(
name: "QueryParameter",
dependencies: [
.product(name: "GoogleCloudGax", package: "gax"),
.product(name: "GoogleCloudWkt", package: "wkt"),
.product(
name: "GoogleCloudSecurityPublicCAV1", package: "google-cloud-security-publicca-v1"),
],
),
]
)
// A generated package description.
//
// This is just enough information to populate the `Package` data structure. It needs both the
// package path, its product [^1], and any (optional) traits that we enable for the tests in
// `Tests/`.
//
// [^1]: in general, packages have many products, but our packages in `generated/*` only have one.
struct Generated {
public let name: String
public let module: String
public var traits: Set<Package.Dependency.Trait>
init(name: String, module: String, traits: [String] = []) {
self.name = name
self.module = module
self.traits = Set(traits.map { .init(name: $0) })
}
}
/// Finds the generated packages used for the build.
func selectGeneratedPackages() -> [Generated] {
let fullBuild = ProcessInfo.processInfo.environment["GOOGLE_CLOUD_SWIFT_FULL_BUILD"] == "true"
if fullBuild {
return generatedPackagesFull()
}
return generatedPackagesStatic()
}
/// The packages required to build `Tests/`.
///
/// The tests, particularly the integration tests, use a relatively small set of packages. To find
/// out how we picked which APIs and packages to use in the integration tests, see the README files
/// for each test.
func generatedPackagesStatic() -> [Generated] {
return [
.init(name: "google-cloud-location", module: "GoogleCloudLocation"),
.init(name: "google-iam-v1", module: "GoogleIAMV1"),
.init(name: "google-cloud-secretmanager-v1", module: "GoogleCloudSecretManagerV1"),
.init(name: "google-cloud-security-publicca-v1", module: "GoogleCloudSecurityPublicCAV1"),
.init(name: "google-cloud-workflows-v1", module: "GoogleCloudWorkflowsV1"),
.init(
name: "google-cloud-compute-v1", module: "GoogleCloudComputeV1",
traits: ["Instances", "Images", "ZoneOperations"]),
]
}
/// Finds all the packages available in the generated/ subdirectory.
///
/// These roughly corresponds to GAPICs, but also include type-only packages.
func generatedPackagesFull() -> [Generated] {
let prefix = " name: \""
let suffix = "\","
var generated: [Generated] = generatedPackagesStatic()
let skipped = Set(generated.map { $0.name })
let generatedDir = URL(fileURLWithPath: #filePath).deletingLastPathComponent()
.appendingPathComponent("generated")
let found = try? FileManager.default.contentsOfDirectory(
at: generatedDir, includingPropertiesForKeys: nil)
for name in (found ?? []) {
if skipped.contains(name.lastPathComponent) {
// The package is statically known, skip opening the directory.
continue
}
let packagePath = name.appendingPathComponent("Package.swift")
do {
let contents = try String(contentsOf: packagePath, encoding: .utf8)
let matching = contents.split(separator: "\n").first(where: {
$0.starts(with: prefix) && $0.hasSuffix(suffix)
}).map({ r in
var value = String(r)
value.removeFirst(prefix.count)
value.removeLast(suffix.count)
return value
})
if let pkg = matching {
generated.append(.init(name: name.lastPathComponent, module: pkg))
}
} catch {
// Ignore I/O errors, including missing files, in the development environment this is common,
// as working in multiple branches may create empty directories.
continue
}
}
return generated.sorted(by: { (a, b) in a.name < b.name })
}