Skip to content

Commit 23e8991

Browse files
committed
Add swift-experimental-destination tool
1 parent 56c7b52 commit 23e8991

File tree

9 files changed

+126
-89
lines changed

9 files changed

+126
-89
lines changed

Package.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,18 @@ let package = Package(
368368
exclude: ["CMakeLists.txt", "README.md"]
369369
),
370370

371+
.target(
372+
/** Interacts with cross-compilation destinations */
373+
name: "CrossCompilationDestinationsTool",
374+
dependencies: [
375+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
376+
"Basics",
377+
"CoreCommands",
378+
"SPMBuildCore",
379+
"PackageModel",
380+
]
381+
),
382+
371383
.target(
372384
/** Interacts with package collections */
373385
name: "PackageCollectionsTool",
@@ -417,6 +429,11 @@ let package = Package(
417429
dependencies: ["CoreCommands"],
418430
exclude: ["CMakeLists.txt"]
419431
),
432+
.executableTarget(
433+
/** Interacts with cross-compilation destinations */
434+
name: "swift-experimental-destination",
435+
dependencies: ["Commands", "CrossCompilationDestinationsTool"]
436+
),
420437
.executableTarget(
421438
/** Runs package tests */
422439
name: "swift-test",
@@ -437,7 +454,13 @@ let package = Package(
437454
.executableTarget(
438455
/** Multi-tool entry point for SwiftPM. */
439456
name: "swift-package-manager",
440-
dependencies: ["Commands", "Basics", "PackageCollectionsTool", "PackageRegistryTool"]
457+
dependencies: [
458+
"Basics",
459+
"Commands",
460+
"CrossCompilationDestinationsTool",
461+
"PackageCollectionsTool",
462+
"PackageRegistryTool"
463+
]
441464
),
442465
.executableTarget(
443466
/** Interact with package registry */

Sources/Commands/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
add_library(Commands
10-
DestinationTools/DestinationCommand.swift
11-
DestinationTools/ListDestinations.swift
1210
PackageTools/APIDiff.swift
1311
PackageTools/ArchiveSource.swift
1412
PackageTools/CompletionTool.swift

Sources/Commands/DestinationTools/ListDestinations.swift

Lines changed: 0 additions & 80 deletions
This file was deleted.

Sources/Commands/PackageTools/SwiftPackageTool.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ public struct SwiftPackageTool: ParsableCommand {
5656
Resolve.self,
5757
Fetch.self,
5858

59-
DestinationCommand.self,
60-
6159
ShowDependencies.self,
6260
ToolsVersionCommand.self,
6361
ComputeChecksum.self,
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2014-2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import ArgumentParser
14+
import Basics
15+
import CoreCommands
16+
import SPMBuildCore
17+
import PackageModel
18+
import TSCBasic
19+
20+
struct ListDestinations: ParsableCommand {
21+
static let configuration = CommandConfiguration(
22+
commandName: "list",
23+
abstract:
24+
"""
25+
Print a list of IDs of available cross-compilation destinations available on the filesystem.
26+
"""
27+
)
28+
29+
@OptionGroup()
30+
var locations: LocationOptions
31+
32+
func run() throws {
33+
let fileSystem = localFileSystem
34+
let observabilitySystem = ObservabilitySystem(
35+
SwiftToolObservabilityHandler(outputStream: stdoutStream, logLevel: .warning)
36+
)
37+
let observabilityScope = observabilitySystem.topScope
38+
39+
guard var destinationsDirectory = try fileSystem.getSharedCrossCompilationDestinationsDirectory(
40+
explicitDirectory: locations.crossCompilationDestinationsDirectory
41+
) else {
42+
let expectedPath = try fileSystem.swiftPMCrossCompilationDestinationsDirectory
43+
throw StringError(
44+
"Couldn't find or create a directory where cross-compilation destinations are stored: \(expectedPath)"
45+
)
46+
}
47+
48+
if !fileSystem.exists(destinationsDirectory) {
49+
destinationsDirectory = try fileSystem.getOrCreateSwiftPMCrossCompilationDestinationsDirectory()
50+
}
51+
52+
// Get absolute paths to available destination bundles.
53+
let destinationBundles = try fileSystem.getDirectoryContents(destinationsDirectory).filter {
54+
$0.hasSuffix(BinaryTarget.Kind.artifactsArchive.fileExtension)
55+
}.map {
56+
destinationsDirectory.appending(components: [$0])
57+
}
58+
59+
// Enumerate available bundles and parse manifests for each of them, then validate supplied destinations.
60+
for bundlePath in destinationBundles {
61+
do {
62+
let destinationsBundle = try DestinationsBundle.parseAndValidate(
63+
bundlePath: bundlePath,
64+
fileSystem: fileSystem,
65+
observabilityScope: observabilityScope
66+
)
67+
68+
destinationsBundle.artifacts.keys.forEach { print($0) }
69+
} catch {
70+
observabilityScope.emit(
71+
.warning(
72+
"Couldn't parse `info.json` manifest of a destination bundle at \(bundlePath): \(error)"
73+
)
74+
)
75+
}
76+
}
77+
}
78+
}

Sources/Commands/DestinationTools/DestinationCommand.swift renamed to Sources/CrossCompilationDestinationsTool/SwiftDestinationCommand.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import ArgumentParser
14+
import Basics
1415

15-
public struct DestinationCommand: ParsableCommand {
16-
public static var configuration = CommandConfiguration(
16+
public struct SwiftDestinationTool: ParsableCommand {
17+
public static let configuration = CommandConfiguration(
1718
commandName: "experimental-destination",
18-
_superCommandName: "package",
19+
_superCommandName: "swift",
1920
abstract: "Perform operations on Swift cross-compilation destinations.",
21+
version: SwiftVersion.current.completeDisplayString,
2022
subcommands: [
2123
ListDestinations.self,
2224
],
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import CrossCompilationDestinationsTool
14+
15+
SwiftDestinationTool.main()

Sources/swift-package-manager/main.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Commands
14+
import CrossCompilationDestinationsTool
1415
import PackageCollectionsTool
1516
import PackageRegistryTool
1617
import TSCBasic
@@ -24,6 +25,8 @@ case "swift-package":
2425
SwiftPackageTool.main()
2526
case "swift-build":
2627
SwiftBuildTool.main()
28+
case "swift-destination":
29+
SwiftDestinationTool.main()
2730
case "swift-test":
2831
SwiftTestTool.main()
2932
case "swift-run":

Utilities/bootstrap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def install_swiftpm(prefix, args):
426426
# Install the swift-package-manager tool and create symlinks to it.
427427
cli_tool_dest = os.path.join(prefix, "bin")
428428
install_binary(args, "swift-package-manager", os.path.join(cli_tool_dest, "swift-package"), destination_is_directory=False)
429-
for tool in ["swift-build", "swift-test", "swift-run", "swift-package-collection", "swift-package-registry"]:
429+
for tool in ["swift-build", "swift-test", "swift-run", "swift-package-collection", "swift-package-registry", "swift-experimental-destination"]:
430430
src = "swift-package"
431431
dest = os.path.join(cli_tool_dest, tool)
432432
note("Creating tool symlink from %s to %s" % (src, dest))

0 commit comments

Comments
 (0)