Skip to content

Commit 41a7476

Browse files
committed
Move more parsing code to DestinationsBundle.swift
1 parent 2ed4589 commit 41a7476

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

Sources/Commands/DestinationTools/ListDestinations.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,7 @@ extension DestinationCommand {
6060
// Enumerate available bundles and parse manifests for each of them, then validate supplied destinations.
6161
for bundlePath in destinationBundles {
6262
do {
63-
let parsedManifest = try ArtifactsArchiveMetadata.parse(
64-
fileSystem: fileSystem,
65-
rootPath: bundlePath
66-
)
67-
68-
let destinationsBundle = try parsedManifest.validateDestinationsBundle(
63+
let destinationsBundle = try DestinationsBundle.parseAndValidate(
6964
bundlePath: bundlePath,
7065
fileSystem: fileSystem,
7166
observabilityScope: observabilityScope

Sources/SPMBuildCore/DestinationsBundle.swift

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,35 @@ public struct DestinationsBundle {
2525

2626
/// Mapping of artifact IDs to variants available for a corresponding artifact.
2727
public fileprivate(set) var artifacts = [String: [Variant]]()
28+
29+
/// Parses metadata of an `.artifactbundle` and validates it as a bundle containing
30+
/// cross-compilation destinations.
31+
/// - Parameters:
32+
/// - bundlePath: path to the bundle root directory.
33+
/// - fileSystem: filesystem containing the bundle.
34+
/// - observabilityScope: observability scope to log validation warnings.
35+
/// - Returns: Validated `DestinationsBundle` containing validated `Destination` values for
36+
/// each artifact and its variants.
37+
public static func parseAndValidate(
38+
bundlePath: AbsolutePath,
39+
fileSystem: FileSystem,
40+
observabilityScope: ObservabilityScope
41+
) throws -> Self {
42+
let parsedManifest = try ArtifactsArchiveMetadata.parse(
43+
fileSystem: fileSystem,
44+
rootPath: bundlePath
45+
)
46+
47+
return try parsedManifest.validateDestinationsBundle(
48+
bundlePath: bundlePath,
49+
fileSystem: fileSystem,
50+
observabilityScope: observabilityScope
51+
)
52+
}
2853
}
2954

30-
extension ArtifactsArchiveMetadata {
31-
public func validateDestinationsBundle(
55+
private extension ArtifactsArchiveMetadata {
56+
func validateDestinationsBundle(
3257
bundlePath: AbsolutePath,
3358
fileSystem: FileSystem,
3459
observabilityScope: ObservabilityScope

0 commit comments

Comments
 (0)