-
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.
Restore all commands as deprecated, add test coverage, fix bugs
- Loading branch information
1 parent
1ef0209
commit 46aec78
Showing
15 changed files
with
742 additions
and
141 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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
85 changes: 85 additions & 0 deletions
85
Sources/SwiftSDKCommand/Configuration/ConfigurationSubcommand.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,85 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 Foundation | ||
import PackageModel | ||
|
||
protocol ConfigurationSubcommand: SwiftSDKSubcommand { | ||
/// An identifier of an already installed Swift SDK. | ||
var sdkID: String { get } | ||
|
||
/// A target triple of the Swift SDK. | ||
var targetTriple: String { get } | ||
|
||
/// Run a command related to configuration of Swift SDKs, passing it required configuration | ||
/// values. | ||
/// - Parameters: | ||
/// - hostTriple: triple of the machine this command is running on. | ||
/// - targetTriple: triple of the machine on which cross-compiled code will run on. | ||
/// - swiftSDK: Swift SDK configuration fetched that matches currently set `sdkID` and | ||
/// `targetTriple`. | ||
/// - configurationStore: storage for configuration properties that this command operates on. | ||
/// - swiftSDKsDirectory: directory containing Swift SDK artifact bundles and their configuration. | ||
/// - observabilityScope: observability scope used for logging. | ||
func run( | ||
hostTriple: Triple, | ||
targetTriple: Triple, | ||
_ swiftSDK: SwiftSDK, | ||
_ configurationStore: SwiftSDKConfigurationStore, | ||
_ swiftSDKsDirectory: AbsolutePath, | ||
_ observabilityScope: ObservabilityScope | ||
) throws | ||
} | ||
|
||
extension ConfigurationSubcommand { | ||
func run( | ||
hostTriple: Triple, | ||
_ swiftSDKsDirectory: AbsolutePath, | ||
_ observabilityScope: ObservabilityScope | ||
) throws { | ||
fputs("warning: `swift sdk configuration` command is deprecated and will be removed in a future version of SwiftPM. Use `swift sdk configure` instead.\n", stderr) | ||
|
||
let bundleStore = SwiftSDKBundleStore( | ||
swiftSDKsDirectory: swiftSDKsDirectory, | ||
fileSystem: self.fileSystem, | ||
observabilityScope: observabilityScope, | ||
outputHandler: { print($0) } | ||
) | ||
let configurationStore = try SwiftSDKConfigurationStore( | ||
hostTimeTriple: hostTriple, | ||
swiftSDKBundleStore: bundleStore | ||
) | ||
let targetTriple = try Triple(self.targetTriple) | ||
|
||
guard let swiftSDK = try configurationStore.readConfiguration( | ||
sdkID: sdkID, | ||
targetTriple: targetTriple | ||
) else { | ||
throw SwiftSDKError.swiftSDKNotFound( | ||
artifactID: sdkID, | ||
hostTriple: hostTriple, | ||
targetTriple: targetTriple | ||
) | ||
} | ||
|
||
try run( | ||
hostTriple: hostTriple, | ||
targetTriple: targetTriple, | ||
swiftSDK, | ||
configurationStore, | ||
swiftSDKsDirectory, | ||
observabilityScope | ||
) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Sources/SwiftSDKCommand/Configuration/DeprecatedSwiftSDKConfigurationCommand.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,33 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 PackageModel | ||
|
||
package struct DeprecatedSwiftSDKConfigurationCommand: ParsableCommand { | ||
package static let configuration = CommandConfiguration( | ||
commandName: "configuration", | ||
abstract: """ | ||
Deprecated: use `swift sdk configure` instead. | ||
Manages configuration options for installed Swift SDKs. | ||
""", | ||
subcommands: [ | ||
ResetConfiguration.self, | ||
SetConfiguration.self, | ||
ShowConfiguration.self, | ||
] | ||
) | ||
|
||
package init() {} | ||
} |
133 changes: 133 additions & 0 deletions
133
Sources/SwiftSDKCommand/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,133 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
|
||
struct ResetConfiguration: ConfigurationSubcommand { | ||
static let configuration = CommandConfiguration( | ||
commandName: "reset", | ||
abstract: """ | ||
Resets configuration properties currently applied to a given Swift SDK and target triple. If no specific \ | ||
property is specified, all of them are reset for the Swift SDK. | ||
""" | ||
) | ||
|
||
@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 Swift SDK. Use the `list` subcommand to see all available \ | ||
identifiers. | ||
""" | ||
) | ||
var sdkID: String | ||
|
||
@Argument(help: "A target triple of the Swift SDK specified by `sdk-id` identifier string.") | ||
var targetTriple: String | ||
|
||
func run( | ||
hostTriple: Triple, | ||
targetTriple: Triple, | ||
_ swiftSDK: SwiftSDK, | ||
_ configurationStore: SwiftSDKConfigurationStore, | ||
_ swiftSDKsDirectory: AbsolutePath, | ||
_ observabilityScope: ObservabilityScope | ||
) throws { | ||
var configuration = swiftSDK.pathsConfiguration | ||
var shouldResetAll = true | ||
var resetProperties = [String]() | ||
|
||
if sdkRootPath { | ||
configuration.sdkRootPath = nil | ||
shouldResetAll = false | ||
resetProperties.append(CodingKeys.sdkRootPath.stringValue) | ||
} | ||
|
||
if swiftResourcesPath { | ||
configuration.swiftResourcesPath = nil | ||
shouldResetAll = false | ||
resetProperties.append(CodingKeys.swiftResourcesPath.stringValue) | ||
} | ||
|
||
if swiftStaticResourcesPath { | ||
configuration.swiftResourcesPath = nil | ||
shouldResetAll = false | ||
resetProperties.append(CodingKeys.swiftStaticResourcesPath.stringValue) | ||
} | ||
|
||
if includeSearchPath { | ||
configuration.includeSearchPaths = nil | ||
shouldResetAll = false | ||
resetProperties.append(CodingKeys.includeSearchPath.stringValue) | ||
} | ||
|
||
if librarySearchPath { | ||
configuration.librarySearchPaths = nil | ||
shouldResetAll = false | ||
resetProperties.append(CodingKeys.librarySearchPath.stringValue) | ||
} | ||
|
||
if toolsetPath { | ||
configuration.toolsetPaths = nil | ||
shouldResetAll = false | ||
resetProperties.append(CodingKeys.toolsetPath.stringValue) | ||
} | ||
|
||
if shouldResetAll { | ||
if try !configurationStore.resetConfiguration(sdkID: sdkID, targetTriple: targetTriple) { | ||
observabilityScope.emit( | ||
warning: "No configuration for Swift SDK `\(sdkID)`" | ||
) | ||
} else { | ||
observabilityScope.emit( | ||
info: """ | ||
All configuration properties of Swift SDK `\(sdkID)` for target triple \ | ||
`\(targetTriple)` were successfully reset. | ||
""" | ||
) | ||
} | ||
} else { | ||
var swiftSDK = swiftSDK | ||
swiftSDK.pathsConfiguration = configuration | ||
try configurationStore.updateConfiguration(sdkID: sdkID, swiftSDK: swiftSDK) | ||
|
||
observabilityScope.emit( | ||
info: """ | ||
These properties of Swift SDK `\(sdkID)` for target triple \ | ||
`\(targetTriple)` were successfully reset: \(resetProperties.joined(separator: ", ")). | ||
""" | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.