Skip to content

Commit 46aec78

Browse files
committed
Restore all commands as deprecated, add test coverage, fix bugs
1 parent 1ef0209 commit 46aec78

15 files changed

+742
-141
lines changed
376 Bytes
Binary file not shown.
-42 Bytes
Binary file not shown.

Sources/PackageModel/SwiftSDKs/SwiftSDKBundle.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,18 @@ extension [SwiftSDKBundle] {
5353
/// - hostTriple: triple of the machine on which the Swift SDK is building.
5454
/// - targetTriple: triple of the machine for which the Swift SDK is building.
5555
/// - Returns: ``SwiftSDK`` value with a given artifact ID, `nil` if none found.
56-
public func selectSwiftSDK(id: String, hostTriple: Triple, targetTriple: Triple) -> SwiftSDK? {
56+
public func selectSwiftSDK(id: String, hostTriple: Triple?, targetTriple: Triple) -> SwiftSDK? {
5757
for bundle in self {
5858
for (artifactID, variants) in bundle.artifacts {
5959
guard artifactID == id else {
6060
continue
6161
}
6262

6363
for variant in variants {
64-
guard variant.isSupporting(hostTriple: hostTriple) else {
65-
continue
64+
if let hostTriple {
65+
guard variant.isSupporting(hostTriple: hostTriple) else {
66+
continue
67+
}
6668
}
6769

6870
return variant.swiftSDKs.first { $0.targetTriple == targetTriple }

Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public final class SwiftSDKConfigurationStore {
9797

9898
guard var swiftSDK = swiftSDKs.selectSwiftSDK(
9999
id: sdkID,
100-
hostTriple: hostTriple,
100+
hostTriple: nil,
101101
targetTriple: targetTriple
102102
) else {
103103
return nil
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2023 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 Foundation
16+
import PackageModel
17+
18+
protocol ConfigurationSubcommand: SwiftSDKSubcommand {
19+
/// An identifier of an already installed Swift SDK.
20+
var sdkID: String { get }
21+
22+
/// A target triple of the Swift SDK.
23+
var targetTriple: String { get }
24+
25+
/// Run a command related to configuration of Swift SDKs, passing it required configuration
26+
/// values.
27+
/// - Parameters:
28+
/// - hostTriple: triple of the machine this command is running on.
29+
/// - targetTriple: triple of the machine on which cross-compiled code will run on.
30+
/// - swiftSDK: Swift SDK configuration fetched that matches currently set `sdkID` and
31+
/// `targetTriple`.
32+
/// - configurationStore: storage for configuration properties that this command operates on.
33+
/// - swiftSDKsDirectory: directory containing Swift SDK artifact bundles and their configuration.
34+
/// - observabilityScope: observability scope used for logging.
35+
func run(
36+
hostTriple: Triple,
37+
targetTriple: Triple,
38+
_ swiftSDK: SwiftSDK,
39+
_ configurationStore: SwiftSDKConfigurationStore,
40+
_ swiftSDKsDirectory: AbsolutePath,
41+
_ observabilityScope: ObservabilityScope
42+
) throws
43+
}
44+
45+
extension ConfigurationSubcommand {
46+
func run(
47+
hostTriple: Triple,
48+
_ swiftSDKsDirectory: AbsolutePath,
49+
_ observabilityScope: ObservabilityScope
50+
) throws {
51+
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)
52+
53+
let bundleStore = SwiftSDKBundleStore(
54+
swiftSDKsDirectory: swiftSDKsDirectory,
55+
fileSystem: self.fileSystem,
56+
observabilityScope: observabilityScope,
57+
outputHandler: { print($0) }
58+
)
59+
let configurationStore = try SwiftSDKConfigurationStore(
60+
hostTimeTriple: hostTriple,
61+
swiftSDKBundleStore: bundleStore
62+
)
63+
let targetTriple = try Triple(self.targetTriple)
64+
65+
guard let swiftSDK = try configurationStore.readConfiguration(
66+
sdkID: sdkID,
67+
targetTriple: targetTriple
68+
) else {
69+
throw SwiftSDKError.swiftSDKNotFound(
70+
artifactID: sdkID,
71+
hostTriple: hostTriple,
72+
targetTriple: targetTriple
73+
)
74+
}
75+
76+
try run(
77+
hostTriple: hostTriple,
78+
targetTriple: targetTriple,
79+
swiftSDK,
80+
configurationStore,
81+
swiftSDKsDirectory,
82+
observabilityScope
83+
)
84+
}
85+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2023 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 PackageModel
16+
17+
package struct DeprecatedSwiftSDKConfigurationCommand: ParsableCommand {
18+
package static let configuration = CommandConfiguration(
19+
commandName: "configuration",
20+
abstract: """
21+
Deprecated: use `swift sdk configure` instead.
22+
23+
Manages configuration options for installed Swift SDKs.
24+
""",
25+
subcommands: [
26+
ResetConfiguration.self,
27+
SetConfiguration.self,
28+
ShowConfiguration.self,
29+
]
30+
)
31+
32+
package init() {}
33+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2023 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 PackageModel
17+
18+
struct ResetConfiguration: ConfigurationSubcommand {
19+
static let configuration = CommandConfiguration(
20+
commandName: "reset",
21+
abstract: """
22+
Resets configuration properties currently applied to a given Swift SDK and target triple. If no specific \
23+
property is specified, all of them are reset for the Swift SDK.
24+
"""
25+
)
26+
27+
@OptionGroup(visibility: .hidden)
28+
var locations: LocationOptions
29+
30+
@Flag(help: "Reset custom configuration for a path to a directory containing the SDK root.")
31+
var sdkRootPath = false
32+
33+
@Flag(help: "Reset custom configuration for a path to a directory containing Swift resources for dynamic linking.")
34+
var swiftResourcesPath = false
35+
36+
@Flag(help: "Reset custom configuration for a path to a directory containing Swift resources for static linking.")
37+
var swiftStaticResourcesPath = false
38+
39+
@Flag(help: "Reset custom configuration for a path to a directory containing headers.")
40+
var includeSearchPath = false
41+
42+
@Flag(help: "Reset custom configuration for a path to a directory containing libraries.")
43+
var librarySearchPath = false
44+
45+
@Flag(help: "Reset custom configuration for a path to a toolset file.")
46+
var toolsetPath = false
47+
48+
@Argument(
49+
help: """
50+
An identifier of an already installed Swift SDK. Use the `list` subcommand to see all available \
51+
identifiers.
52+
"""
53+
)
54+
var sdkID: String
55+
56+
@Argument(help: "A target triple of the Swift SDK specified by `sdk-id` identifier string.")
57+
var targetTriple: String
58+
59+
func run(
60+
hostTriple: Triple,
61+
targetTriple: Triple,
62+
_ swiftSDK: SwiftSDK,
63+
_ configurationStore: SwiftSDKConfigurationStore,
64+
_ swiftSDKsDirectory: AbsolutePath,
65+
_ observabilityScope: ObservabilityScope
66+
) throws {
67+
var configuration = swiftSDK.pathsConfiguration
68+
var shouldResetAll = true
69+
var resetProperties = [String]()
70+
71+
if sdkRootPath {
72+
configuration.sdkRootPath = nil
73+
shouldResetAll = false
74+
resetProperties.append(CodingKeys.sdkRootPath.stringValue)
75+
}
76+
77+
if swiftResourcesPath {
78+
configuration.swiftResourcesPath = nil
79+
shouldResetAll = false
80+
resetProperties.append(CodingKeys.swiftResourcesPath.stringValue)
81+
}
82+
83+
if swiftStaticResourcesPath {
84+
configuration.swiftResourcesPath = nil
85+
shouldResetAll = false
86+
resetProperties.append(CodingKeys.swiftStaticResourcesPath.stringValue)
87+
}
88+
89+
if includeSearchPath {
90+
configuration.includeSearchPaths = nil
91+
shouldResetAll = false
92+
resetProperties.append(CodingKeys.includeSearchPath.stringValue)
93+
}
94+
95+
if librarySearchPath {
96+
configuration.librarySearchPaths = nil
97+
shouldResetAll = false
98+
resetProperties.append(CodingKeys.librarySearchPath.stringValue)
99+
}
100+
101+
if toolsetPath {
102+
configuration.toolsetPaths = nil
103+
shouldResetAll = false
104+
resetProperties.append(CodingKeys.toolsetPath.stringValue)
105+
}
106+
107+
if shouldResetAll {
108+
if try !configurationStore.resetConfiguration(sdkID: sdkID, targetTriple: targetTriple) {
109+
observabilityScope.emit(
110+
warning: "No configuration for Swift SDK `\(sdkID)`"
111+
)
112+
} else {
113+
observabilityScope.emit(
114+
info: """
115+
All configuration properties of Swift SDK `\(sdkID)` for target triple \
116+
`\(targetTriple)` were successfully reset.
117+
"""
118+
)
119+
}
120+
} else {
121+
var swiftSDK = swiftSDK
122+
swiftSDK.pathsConfiguration = configuration
123+
try configurationStore.updateConfiguration(sdkID: sdkID, swiftSDK: swiftSDK)
124+
125+
observabilityScope.emit(
126+
info: """
127+
These properties of Swift SDK `\(sdkID)` for target triple \
128+
`\(targetTriple)` were successfully reset: \(resetProperties.joined(separator: ", ")).
129+
"""
130+
)
131+
}
132+
}
133+
}

0 commit comments

Comments
 (0)