File: PackageModel.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (533 lines) | stat: -rw-r--r-- 21,133 bytes parent folder | download
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Foundation

/// Represents a single package in the graph (either the root or a dependency).
public struct Package {
    /// Unique identifier for the package.
    public let id: ID
    public typealias ID = String

    /// The name of the package (for display purposes only).
    public let displayName: String

    /// The absolute path of the package directory in the local file system.
    @available(_PackageDescription, deprecated: 6.0, renamed: "directoryURL")
    public let directory: Path

    /// The absolute path of the package directory in the local file system.
    @available(_PackageDescription, introduced: 6.0)
    public let directoryURL: URL

    /// The origin of the package (root, local, repository, registry, etc).
    public let origin: PackageOrigin

    /// The tools version specified by the resolved version of the package.
    /// Behavior is often gated on the tools version, to make sure older
    /// packages continue to work as intended.
    public let toolsVersion: ToolsVersion

    /// Any dependencies on other packages, in the same order as they are
    /// specified in the package manifest.
    public let dependencies: [PackageDependency]

    /// Any regular products defined in this package (except plugin products),
    /// in the same order as they are specified in the package manifest.
    public let products: [Product]

    /// Any regular targets defined in this package (except plugin targets),
    /// in the same order as they are specified in the package manifest.
    public let targets: [Target]
}

/// Represents the origin of a package as it appears in the graph.
public enum PackageOrigin {
    /// A root package (unversioned).
    case root

    /// A local package, referenced by path (unversioned).
    case local(path: String)

    /// A package from a Git repository, with a URL and with a textual
    /// description of the resolved version or branch name (for display
    /// purposes only), along with the corresponding SCM revision. The
    /// revision is the Git commit hash and may be useful for plugins
    /// that generates source code that includes version information.
    case repository(url: String, displayVersion: String, scmRevision: String)

    /// A package from a registry, with an identity and with a textual
    /// description of the resolved version or branch name (for display
    /// purposes only).
    case registry(identity: String, displayVersion: String)
}

/// Represents a version of SwiftPM on whose semantics a package relies.
public struct ToolsVersion {
    /// The major version.
    public let major: Int

    /// The minor version.
    public let minor: Int

    /// The patch version.
    public let patch: Int
}

/// Represents a resolved dependency of a package on another package. This is a
/// separate entity in order to make it easier for future versions of the API to
/// add information about the dependency itself.
public struct PackageDependency {
    /// The package to which the dependency was resolved.
    public let package: Package

    init(package: Package) {
        self.package = package
    }
}

/// Represents a single product defined in a package.
public protocol Product {
    /// Unique identifier for the product.
    var id: ID { get }
    typealias ID = String

    /// The name of the product, as defined in the package manifest. This name
    /// is unique among the products of the package in which it is defined.
    var name: String { get }

    /// The targets that directly comprise the product, in the order in which
    /// they are declared in the package manifest. The product will contain the
    /// transitive closure of the these targets and their dependencies. Some
    /// kinds of products have further restrictions on the set of targets (for
    /// example, an executable product must have one and only one target that
    /// defines the main entry point for an executable).
    var targets: [Target] { get }
}

/// Represents an executable product defined in a package.
public struct ExecutableProduct: Product {
    /// Unique identifier for the product.
    public let id: ID

    /// The name of the product, as defined in the package manifest. This name
    /// is unique among the products of the package in which it is defined.
    public let name: String

    /// The targets that directly comprise the product, in the order in which
    /// they are declared in the package manifest. The product will contain the
    /// transitive closure of the these targets and their dependencies. For an
    /// ExecutableProduct, exactly one of the targets in this list must be an
    /// ExecutableTarget.
    public let targets: [Target]

    /// The target that contains the main entry point of the executable. Every
    /// executable product has exactly one main executable target. This target
    /// will always be one of the targets in the product's `targets` array.
    public let mainTarget: Target
}

/// Represents a library product defined in a package.
public struct LibraryProduct: Product {
    /// Unique identifier for the product.
    public let id: ID

    /// The name of the product, as defined in the package manifest. This name
    /// is unique among the products of the package in which it is defined.
    public let name: String

    /// The targets that directly comprise the product, in the order in which
    /// they are declared in the package manifest. The product will contain the
    /// transitive closure of the these targets and their dependencies.
    public let targets: [Target]

    /// Whether the library is static, dynamic, or automatically determined.
    public let kind: Kind

    /// Represents a kind of library product.
    public enum Kind {
        /// A static library, whose code is copied into its clients.
        case `static`

        /// Dynamic library, whose code is referenced by its clients.
        case dynamic

        /// The kind of library produced is unspecified and will be determined
        /// by the build system based on how the library is used.
        case automatic
    }
}

/// Represents a single target defined in a package.
public protocol Target {
    /// Unique identifier for the target.
    var id: ID { get }
    typealias ID = String

    /// The name of the target, as defined in the package manifest. This name
    /// is unique among the targets of the package in which it is defined.
    var name: String { get }

    /// The absolute path of the target directory in the local file system.
    var directory: Path { get }

    /// Any other targets on which this target depends, in the same order as
    /// they are specified in the package manifest. Conditional dependencies
    /// that do not apply have already been filtered out.
    var dependencies: [TargetDependency] { get }
}

/// Represents a dependency of a target on a product or on another target.
public enum TargetDependency {
    /// A dependency on a target in the same package.
    case target(Target)

    /// A dependency on a product in another package.
    case product(Product)
}

/// Represents a target consisting of a source code module, containing either
/// Swift or source files in one of the C-based languages.
public protocol SourceModuleTarget: Target {
    /// The name of the module produced by the target (derived from the target
    /// name, though future SwiftPM versions may allow this to be customized).
    var moduleName: String { get }

    /// The kind of module, describing whether it contains unit tests, contains
    /// the main entry point of an executable, or neither.
    var kind: ModuleKind { get }

    /// The source files that are associated with this target (any files that
    /// have been excluded in the manifest have already been filtered out).
    var sourceFiles: FileList { get }

    /// Any custom linked libraries required by the module, as specified in the
    /// package manifest.
    var linkedLibraries: [String] { get }

    /// Any custom linked frameworks required by the module, as specified in the
    /// package manifest.
    var linkedFrameworks: [String] { get }

    /// Paths of any sources generated by other plugins that have been applied to the given target before the plugin
    /// currently being executed.
    ///
    /// Note: Plugins are applied in order of declaration in the package manifest. Generated files are vended to the
    /// target the current plugin is being applied to, but not necessarily to other targets in the package graph.
    @available(_PackageDescription, introduced: 6.0)
    var pluginGeneratedSources: [URL] { get }

    /// Paths of any resources generated by other plugins that have been applied to the given target before the plugin
    /// currently being executed.
    ///
    /// Note: Plugins are applied in order of declaration in the package manifest. Generated files are vended to the
    /// target the current plugin is being applied to, but not necessarily to other targets in the package graph.
    @available(_PackageDescription, introduced: 6.0)
    var pluginGeneratedResources: [URL] { get }
}

/// Represents the kind of module.
public enum ModuleKind {
    /// A module that contains generic code (not a test nor an executable).
    case generic
    /// A module that contains code for an executable's main module.
    case executable
    /// A module that contains code for a snippet.
    @available(_PackageDescription, introduced: 5.8)
    case snippet
    /// A module that contains unit tests.
    case test
    /// A module that contains code for a macro.
    @available(_PackageDescription, introduced: 5.9)
    case macro // FIXME: This should really come from `CompilerPluginSupport` somehow, but we lack the infrastructure to allow that currently.
}

/// Represents a target consisting of a source code module compiled using Swift.
public struct SwiftSourceModuleTarget: SourceModuleTarget {
    /// Unique identifier for the target.
    public let id: ID

    /// The name of the target, as defined in the package manifest. This name
    /// is unique among the targets of the package in which it is defined.
    public let name: String

    /// The kind of module, describing whether it contains unit tests, contains
    /// the main entry point of an executable, or neither.
    public let kind: ModuleKind

    /// The absolute path of the target directory in the local file system.
    @available(_PackageDescription, deprecated: 6.0, renamed: "directoryURL")
    public let directory: Path

    /// The absolute path of the target directory in the local file system.
    @available(_PackageDescription, introduced: 6.0)
    public let directoryURL: URL

    /// Any other targets on which this target depends, in the same order as
    /// they are specified in the package manifest. Conditional dependencies
    /// that do not apply have already been filtered out.
    public let dependencies: [TargetDependency]

    /// The name of the module produced by the target (derived from the target
    /// name, though future SwiftPM versions may allow this to be customized).
    public let moduleName: String

    /// The source files that are associated with this target (any files that
    /// have been excluded in the manifest have already been filtered out).
    public let sourceFiles: FileList

    /// Any custom compilation conditions specified for the Swift target in the
    /// package manifest.
    public let compilationConditions: [String]

    /// Any custom linked libraries required by the module, as specified in the
    /// package manifest.
    public let linkedLibraries: [String]

    /// Any custom linked frameworks required by the module, as specified in the
    /// package manifest.
    public let linkedFrameworks: [String]

    /// Paths of any sources generated by other plugins that have been applied to the given target before the plugin
    /// currently being executed.
    @available(_PackageDescription, introduced: 6.0)
    public let pluginGeneratedSources: [URL]

    /// Paths of any resources generated by other plugins that have been applied to the given target before the plugin
    /// currently being executed.
    @available(_PackageDescription, introduced: 6.0)
    public let pluginGeneratedResources: [URL]
}

/// Represents a target consisting of a source code module compiled using Clang.
public struct ClangSourceModuleTarget: SourceModuleTarget {
    /// Unique identifier for the target.
    public let id: ID

    /// The name of the target, as defined in the package manifest. This name
    /// is unique among the targets of the package in which it is defined.
    public let name: String

    /// The kind of module, describing whether it contains unit tests, contains
    /// the main entry point of an executable, or neither.
    public let kind: ModuleKind

    /// The absolute path of the target directory in the local file system.
    @available(_PackageDescription, deprecated: 6.0, renamed: "directoryURL")
    public let directory: Path

    /// The absolute path of the target directory in the local file system.
    @available(_PackageDescription, introduced: 6.0)
    public let directoryURL: URL

    /// Any other targets on which this target depends, in the same order as
    /// they are specified in the package manifest. Conditional dependencies
    /// that do not apply have already been filtered out.
    public let dependencies: [TargetDependency]

    /// The name of the module produced by the target (derived from the target
    /// name, though future SwiftPM versions may allow this to be customized).
    public let moduleName: String

    /// The source files that are associated with this target (any files that
    /// have been excluded in the manifest have already been filtered out).
    public let sourceFiles: FileList

    /// Any preprocessor definitions specified for the Clang target.
    public let preprocessorDefinitions: [String]

    /// Any custom header search paths specified for the Clang target.
    public let headerSearchPaths: [String]

    /// The directory containing public C headers, if applicable. This will
    /// only be set for targets that have a directory of a public headers.
    @available(_PackageDescription, deprecated: 6.0, renamed: "publicHeadersDirectoryURL")
    public let publicHeadersDirectory: Path?

    /// The directory containing public C headers, if applicable. This will
    /// only be set for targets that have a directory of a public headers.
    @available(_PackageDescription, deprecated: 6.0)
    public let publicHeadersDirectoryURL: URL?

    /// Any custom linked libraries required by the module, as specified in the
    /// package manifest.
    public let linkedLibraries: [String]

    /// Any custom linked frameworks required by the module, as specified in the
    /// package manifest.
    public let linkedFrameworks: [String]

    /// Paths of any sources generated by other plugins that have been applied to the given target before the plugin
    /// currently being executed.
    @available(_PackageDescription, introduced: 6.0)
    public let pluginGeneratedSources: [URL]

    /// Paths of any resources generated by other plugins that have been applied to the given target before the plugin
    /// currently being executed.
    @available(_PackageDescription, introduced: 6.0)
    public let pluginGeneratedResources: [URL]
}

/// Represents a target describing an artifact (e.g. a library or executable)
/// that is distributed as a binary.
public struct BinaryArtifactTarget: Target {
    /// Unique identifier for the target.
    public let id: ID

    /// The name of the target, as defined in the package manifest. This name
    /// is unique among the targets of the package in which it is defined.
    public let name: String

    /// The absolute path of the target directory in the local file system.
    @available(_PackageDescription, deprecated: 6.0, renamed: "directoryURL")
    public let directory: Path

    /// The absolute path of the target directory in the local file system.
    @available(_PackageDescription, introduced: 6.0)
    public let directoryURL: URL

    /// Any other targets on which this target depends, in the same order as
    /// they are specified in the package manifest. Conditional dependencies
    /// that do not apply have already been filtered out.
    public let dependencies: [TargetDependency]

    /// The kind of binary artifact.
    public let kind: Kind

    /// The original source of the binary artifact.
    public let origin: Origin

    /// The location of the binary artifact in the local file system.
    @available(_PackageDescription, deprecated: 6.0, renamed: "artifactURL")
    public let artifact: Path

    /// The location of the binary artifact in the local file system.
    @available(_PackageDescription, introduced: 6.0)
    public let artifactURL: URL

    /// Represents a kind of binary artifact.
    public enum Kind {
        case xcframework
        case artifactsArchive
    }

    // Represents the original location of a binary artifact.
    public enum Origin: Equatable {
        /// Represents an artifact that was available locally.
        case local

        /// Represents an artifact that was downloaded from a remote URL.
        case remote(url: String)
    }
}

/// Represents a target describing a system library that is expected to be
/// present on the host system.
public struct SystemLibraryTarget: Target {
    /// Unique identifier for the target.
    public let id: ID

    /// The name of the target, as defined in the package manifest. This name
    /// is unique among the targets of the package in which it is defined.
    public var name: String

    /// The absolute path of the target directory in the local file system.
    @available(_PackageDescription, deprecated: 6.0, renamed: "directoryURL")
    public var directory: Path

    /// The absolute path of the target directory in the local file system.
    @available(_PackageDescription, introduced: 6.0)
    public var directoryURL: URL

    /// Any other targets on which this target depends, in the same order as
    /// they are specified in the package manifest. Conditional dependencies
    /// that do not apply have already been filtered out.
    public var dependencies: [TargetDependency]

    /// The name of the `pkg-config` file, if any, describing the library.
    public let pkgConfig: String?

    /// Flags from `pkg-config` to pass to Clang (and to SwiftC via `-Xcc`).
    public let compilerFlags: [String]

    /// Flags from `pkg-config` to pass to the platform linker.
    public let linkerFlags: [String]
}

/// Provides information about a list of files. The order is not defined
/// but is guaranteed to be stable. This allows the implementation to be
/// more efficient than a static file list.
public struct FileList {
    private var files: [File]

    init(_ files: [File]) {
        self.files = files
    }
}

extension FileList: Sequence {
    public struct Iterator: IteratorProtocol {
        private var files: ArraySlice<File>
        fileprivate init(files: ArraySlice<File>) {
            self.files = files
        }

        public mutating func next() -> File? {
            guard let nextInfo = self.files.popFirst() else {
                return nil
            }
            return nextInfo
        }
    }

    public func makeIterator() -> Iterator {
        Iterator(files: ArraySlice(self.files))
    }
}

@available(_PackageDescription, introduced: 5.10)
extension FileList: RandomAccessCollection {
    public var startIndex: Int { 0 }
    public var endIndex: Int { self.files.endIndex }
    public subscript(i: Int) -> File { self.files[i] }
}

/// Provides information about a single file in a FileList.
public struct File {
    /// The path of the file.
    @available(_PackageDescription, deprecated: 6.0, renamed: "url")
    public let path: Path

    /// The path of the file.
    @available(_PackageDescription, introduced: 6.0)
    public let url: URL

    /// File type, as determined by SwiftPM.
    public let type: FileType
}

/// Provides information about the type of a file. Any future cases will
/// use availability annotations to make sure existing plugins still work
/// until they increase their required tools version.
public enum FileType {
    /// A source file.
    case source

    /// A header file.
    case header

    /// A resource file (either processed or copied).
    case resource

    /// A file not covered by any other rule.
    case unknown
}