-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
experimental-destination configuration
subcommand (#6252)
For configuring destination bundles that can't be self-contained and have to reference absolute paths we need new to provide a CLI. This comes as a new `swift experimental-destination configuration` subcommand per the proposed changes in swiftlang/swift-evolution#1942. `DestinationCommand` protocol is refined to wait for the observability handler to flush all output. Existing destination-related subcommands are modified to conform to it. Additionally, it now passes a newly initialized observability scope and configuration values. Two new subcommands are added: `configuration show` and `configuration reset`. For actually updating configuration values a third subcommand `configuration set` will be added in a separate PR.
- Loading branch information
1 parent
5a7b7fe
commit 52d9590
Showing
12 changed files
with
425 additions
and
95 deletions.
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.