-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add experimental-destination configuration
subcommand
#6252
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aae0852
Add `experimental-destination configuration` subcommand
MaxDesiatov 2ac7d78
Apply SwiftFormat
MaxDesiatov af8c906
Clean up use of `ObservabilitySystem.swiftTool`
MaxDesiatov 04d120d
Merge branch 'main' into maxd/destination-configuration-subcommand
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 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 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
26 changes: 26 additions & 0 deletions
26
Sources/CrossCompilationDestinationsTool/Configuration/ConfigureDestination.swift
This file contains 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,26 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift open source project | ||
// | ||
// Copyright (c) 2023 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 | ||
|
||
struct ConfigureDestination: ParsableCommand { | ||
static let configuration = CommandConfiguration( | ||
commandName: "configuration", | ||
abstract: """ | ||
Manages configuration options for installed cross-compilation destinations. | ||
""", | ||
subcommands: [ | ||
ResetConfiguration.self, | ||
ShowConfiguration.self, | ||
] | ||
) | ||
} |
129 changes: 129 additions & 0 deletions
129
Sources/CrossCompilationDestinationsTool/Configuration/ResetConfiguration.swift
This file contains 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,129 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift open source project | ||
// | ||
// Copyright (c) 2023 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 PackageModel | ||
|
||
import struct TSCBasic.AbsolutePath | ||
|
||
struct ResetConfiguration: DestinationCommand { | ||
static let configuration = CommandConfiguration( | ||
commandName: "reset", | ||
abstract: """ | ||
Resets configuration properties currently applied to a given destination and run-time triple. If no specific \ | ||
property is specified, all of them are reset for the destination. | ||
""" | ||
) | ||
|
||
@OptionGroup(visibility: .hidden) | ||
var locations: LocationOptions | ||
|
||
@Flag(help: "Reset custom configuration for a path to a directory containing the SDK root.") | ||
var sdkRootPath = false | ||
|
||
@Flag(help: "Reset custom configuration for a path to a directory containing Swift resources for dynamic linking.") | ||
var swiftResourcesPath = false | ||
|
||
@Flag(help: "Reset custom configuration for a path to a directory containing Swift resources for static linking.") | ||
var swiftStaticResourcesPath = false | ||
|
||
@Flag(help: "Reset custom configuration for a path to a directory containing headers.") | ||
var includeSearchPath = false | ||
|
||
@Flag(help: "Reset custom configuration for a path to a directory containing libraries.") | ||
var librarySearchPath = false | ||
|
||
@Flag(help: "Reset custom configuration for a path to a toolset file.") | ||
var toolsetPath = false | ||
|
||
@Argument( | ||
help: """ | ||
An identifier of an already installed destination. Use the `list` subcommand to see all available \ | ||
identifiers. | ||
""" | ||
) | ||
var destinationID: String | ||
|
||
@Argument(help: "The run-time triple of the destination to configure.") | ||
var runTimeTriple: String | ||
|
||
func run( | ||
buildTimeTriple: Triple, | ||
_ destinationsDirectory: AbsolutePath, | ||
_ observabilityScope: ObservabilityScope | ||
) throws { | ||
let configurationStore = try DestinationConfigurationStore( | ||
buildTimeTriple: buildTimeTriple, | ||
destinationsDirectoryPath: destinationsDirectory, | ||
fileSystem: fileSystem, | ||
observabilityScope: observabilityScope | ||
) | ||
|
||
let triple = try Triple(runTimeTriple) | ||
|
||
guard var destination = try configurationStore.readConfiguration( | ||
destinationID: destinationID, | ||
runTimeTriple: triple | ||
) else { | ||
throw DestinationError.destinationNotFound( | ||
artifactID: destinationID, | ||
builtTimeTriple: buildTimeTriple, | ||
runTimeTriple: triple | ||
) | ||
} | ||
|
||
var configuration = destination.pathsConfiguration | ||
var shouldResetAll = true | ||
|
||
if sdkRootPath { | ||
configuration.sdkRootPath = nil | ||
shouldResetAll = false | ||
} | ||
|
||
if swiftResourcesPath { | ||
configuration.swiftResourcesPath = nil | ||
shouldResetAll = false | ||
} | ||
|
||
if swiftStaticResourcesPath { | ||
configuration.swiftResourcesPath = nil | ||
shouldResetAll = false | ||
} | ||
|
||
if includeSearchPath { | ||
configuration.includeSearchPaths = nil | ||
shouldResetAll = false | ||
} | ||
|
||
if librarySearchPath { | ||
configuration.librarySearchPaths = nil | ||
shouldResetAll = false | ||
} | ||
|
||
if toolsetPath { | ||
configuration.toolsetPaths = nil | ||
shouldResetAll = false | ||
} | ||
|
||
if shouldResetAll { | ||
if try !configurationStore.resetConfiguration(destinationID: destinationID, runTimeTriple: triple) { | ||
observabilityScope.emit( | ||
warning: "No configuration for destination \(destinationID)" | ||
) | ||
} | ||
} else { | ||
try configurationStore.updateConfiguration(destinationID: destinationID, destination: destination) | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
Sources/CrossCompilationDestinationsTool/Configuration/ShowConfiguration.swift
This file contains 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,94 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift open source project | ||
// | ||
// Copyright (c) 2023 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 PackageModel | ||
|
||
import struct TSCBasic.AbsolutePath | ||
|
||
struct ShowConfiguration: DestinationCommand { | ||
static let configuration = CommandConfiguration( | ||
commandName: "show", | ||
abstract: """ | ||
Prints all configuration properties currently applied to a given destination and run-time triple. | ||
""" | ||
) | ||
|
||
@OptionGroup(visibility: .hidden) | ||
var locations: LocationOptions | ||
|
||
@Argument( | ||
help: """ | ||
An identifier of an already installed destination. Use the `list` subcommand to see all available \ | ||
identifiers. | ||
""" | ||
) | ||
var destinationID: String | ||
|
||
@Argument(help: "The run-time triple of the destination to configure.") | ||
var runTimeTriple: String | ||
|
||
func run( | ||
buildTimeTriple: Triple, | ||
_ destinationsDirectory: AbsolutePath, | ||
_ observabilityScope: ObservabilityScope | ||
) throws { | ||
let configurationStore = try DestinationConfigurationStore( | ||
buildTimeTriple: buildTimeTriple, | ||
destinationsDirectoryPath: destinationsDirectory, | ||
fileSystem: fileSystem, | ||
observabilityScope: observabilityScope | ||
) | ||
|
||
let triple = try Triple(runTimeTriple) | ||
|
||
guard let configuration = try configurationStore.readConfiguration( | ||
destinationID: destinationID, | ||
runTimeTriple: triple | ||
)?.pathsConfiguration else { | ||
throw DestinationError.destinationNotFound( | ||
artifactID: destinationID, | ||
builtTimeTriple: buildTimeTriple, | ||
runTimeTriple: triple | ||
) | ||
} | ||
|
||
print(configuration) | ||
} | ||
} | ||
|
||
extension Destination.PathsConfiguration: CustomStringConvertible { | ||
public var description: String { | ||
""" | ||
sdkRootPath: \(sdkRootPath.configurationString) | ||
swiftResourcesPath: \(swiftResourcesPath.configurationString) | ||
swiftStaticResourcesPath: \(swiftStaticResourcesPath.configurationString) | ||
includeSearchPaths: \(includeSearchPaths.configurationString) | ||
librarySearchPaths: \(librarySearchPaths.configurationString) | ||
toolsetPaths: \(toolsetPaths.configurationString) | ||
""" | ||
} | ||
} | ||
|
||
extension Optional where Wrapped == AbsolutePath { | ||
fileprivate var configurationString: String { | ||
self?.pathString ?? "not set" | ||
} | ||
} | ||
|
||
extension Optional where Wrapped == [AbsolutePath] { | ||
fileprivate var configurationString: String { | ||
self?.map(\.pathString).description ?? "not set" | ||
} | ||
} |
This file contains 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 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.
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.
This change is needed to allow getting a reference to
SwiftToolObservabilityHandler
and callingwait(timeout:)
on it.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 think this is fine, but at some point we should consider if these new command should become aligned with the other commands so they dont need this kind of external access
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 found a better way to address that within this PR. Turns out
static func swiftTool
was used just once inDestinationCommand
, it made more sense to move its implementation over there, so there's no need for this tuple-returning function anymore.