-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commands: add experimental-destination
command
#5911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5827f63
Commands: add `experimental-destination` command
MaxDesiatov 4750207
Refactor `DestinationCommand.ListDestinations`
MaxDesiatov 2ed4589
Introduce `DestinationsBundle` to `SPMBuildCore`
MaxDesiatov 41a7476
Move more parsing code to `DestinationsBundle.swift`
MaxDesiatov 56c7b52
Clean up variable naming, fix CMake filename mismatch
MaxDesiatov 23e8991
Add `swift-experimental-destination` tool
MaxDesiatov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
Sources/CrossCompilationDestinationsTool/ListDestinations.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift open source project | ||
// | ||
// Copyright (c) 2014-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 ArgumentParser | ||
import Basics | ||
import CoreCommands | ||
import SPMBuildCore | ||
import PackageModel | ||
import TSCBasic | ||
|
||
struct ListDestinations: ParsableCommand { | ||
static let configuration = CommandConfiguration( | ||
commandName: "list", | ||
abstract: | ||
""" | ||
Print a list of IDs of available cross-compilation destinations available on the filesystem. | ||
""" | ||
) | ||
|
||
@OptionGroup() | ||
var locations: LocationOptions | ||
|
||
func run() throws { | ||
let fileSystem = localFileSystem | ||
let observabilitySystem = ObservabilitySystem( | ||
SwiftToolObservabilityHandler(outputStream: stdoutStream, logLevel: .warning) | ||
) | ||
let observabilityScope = observabilitySystem.topScope | ||
|
||
guard var destinationsDirectory = try fileSystem.getSharedCrossCompilationDestinationsDirectory( | ||
explicitDirectory: locations.crossCompilationDestinationsDirectory | ||
) else { | ||
let expectedPath = try fileSystem.swiftPMCrossCompilationDestinationsDirectory | ||
throw StringError( | ||
"Couldn't find or create a directory where cross-compilation destinations are stored: \(expectedPath)" | ||
) | ||
} | ||
|
||
if !fileSystem.exists(destinationsDirectory) { | ||
destinationsDirectory = try fileSystem.getOrCreateSwiftPMCrossCompilationDestinationsDirectory() | ||
} | ||
|
||
// Get absolute paths to available destination bundles. | ||
let destinationBundles = try fileSystem.getDirectoryContents(destinationsDirectory).filter { | ||
$0.hasSuffix(BinaryTarget.Kind.artifactsArchive.fileExtension) | ||
}.map { | ||
destinationsDirectory.appending(components: [$0]) | ||
} | ||
|
||
// Enumerate available bundles and parse manifests for each of them, then validate supplied destinations. | ||
for bundlePath in destinationBundles { | ||
do { | ||
let destinationsBundle = try DestinationsBundle.parseAndValidate( | ||
bundlePath: bundlePath, | ||
fileSystem: fileSystem, | ||
observabilityScope: observabilityScope | ||
) | ||
|
||
destinationsBundle.artifacts.keys.forEach { print($0) } | ||
} catch { | ||
observabilityScope.emit( | ||
.warning( | ||
"Couldn't parse `info.json` manifest of a destination bundle at \(bundlePath): \(error)" | ||
) | ||
) | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Sources/CrossCompilationDestinationsTool/SwiftDestinationCommand.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift open source project | ||
// | ||
// Copyright (c) 2014-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 ArgumentParser | ||
import Basics | ||
|
||
public struct SwiftDestinationTool: ParsableCommand { | ||
public static let configuration = CommandConfiguration( | ||
commandName: "experimental-destination", | ||
_superCommandName: "swift", | ||
abstract: "Perform operations on Swift cross-compilation destinations.", | ||
version: SwiftVersion.current.completeDisplayString, | ||
subcommands: [ | ||
ListDestinations.self, | ||
], | ||
helpNames: [.short, .long, .customLong("help", withSingleDash: true)]) | ||
|
||
public init() {} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this feels right. I think on macOS, we probably want this to be inside
~/Library/Application\ Support/org.swift.swiftpm
and not sure what a canonical place for other OSes would be.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm modeling this after all other path options boilerplate, for which a symlink is created to
idiomaticSwiftPMDirectory
where possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but isn't the primary location
~/Library/org.swift.swiftpm
right now?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. Is your point that
dotSwiftPMCrossCompilationDestinationsDirectory
property should be deleted altogether? It's only called fromswiftPMCrossCompilationDestinationsDirectory
, which checks if~/Library/org.swift.swiftpm
is a valid path on the host platform and prefers that one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering whether these should be in "Application Support" instead since they're more "data" than "configuration", but now looking at it, we should probably not have a
~/Library/org.swift.swiftpm
in the first place, but rather place things into subdirectories of "Preferences" and "Application Support"? Let's not worry about it for this PR.