Skip to content

Commit 7210759

Browse files
committed
PackageModel: make some of the private API more public
This extends the visibility of some of the private implementation to the package level to allow use for testing without `@testable` imports.
1 parent 6ce584c commit 7210759

File tree

7 files changed

+43
-11
lines changed

7 files changed

+43
-11
lines changed

Sources/PackageModel/MinimumDeploymentTarget.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ public struct MinimumDeploymentTarget {
5858
return nil
5959
}
6060

61-
static func computeXCTestMinimumDeploymentTarget(with runResult: AsyncProcessResult, platform: PackageModel.Platform) throws -> PlatformVersion? {
61+
package static func computeXCTestMinimumDeploymentTarget(with runResult: AsyncProcessResult, platform: PackageModel.Platform) throws -> PlatformVersion? {
6262
guard let output = try runResult.utf8Output().spm_chuzzle() else { return nil }
6363
let sdkPath = try Basics.AbsolutePath(validating: output)
6464
let xcTestPath = try Basics.AbsolutePath(validating: "Developer/Library/Frameworks/XCTest.framework/XCTest", relativeTo: sdkPath)
6565
return try computeMinimumDeploymentTarget(of: xcTestPath, platform: platform)
6666
}
6767

68-
static func computeXCTestMinimumDeploymentTarget(for platform: PackageModel.Platform) -> PlatformVersion {
68+
package static func computeXCTestMinimumDeploymentTarget(for platform: PackageModel.Platform) -> PlatformVersion {
6969
guard let (sdkName, _) = platform.sdkNameAndPlatform else {
7070
return platform.oldestSupportedVersion
7171
}

Sources/PackageModel/PackageIdentity.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public struct PackageIdentity: CustomStringConvertible, Sendable {
2121

2222
/// Creates a package identity from a string.
2323
/// - Parameter value: A string used to identify a package.
24-
init(_ value: String) {
24+
package init(_ value: String) {
2525
self.description = value
2626
}
2727

@@ -296,7 +296,7 @@ extension PackageIdentity {
296296

297297
// MARK: -
298298

299-
struct PackageIdentityParser {
299+
package struct PackageIdentityParser {
300300
/// A textual representation of this instance.
301301
public let description: String
302302

Sources/PackageModel/Snippets/Model/Snippet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public struct Snippet {
2323
path.basenameWithoutExt
2424
}
2525

26-
init(parsing source: String, path: AbsolutePath) {
26+
package init(parsing source: String, path: AbsolutePath) {
2727
let extractor = PlainTextSnippetExtractor(source: source)
2828
self.path = path
2929
self.explanation = extractor.explanation

Sources/PackageModel/SwiftSDKs/SwiftSDK.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ extension SwiftSDK {
962962
/// - properties: properties of the Swift SDK for the given triple.
963963
/// - toolset: combined toolset used by this Swift SDK.
964964
/// - swiftSDKDirectory: directory used for converting relative paths in `properties` to absolute paths.
965-
init(
965+
package init(
966966
targetTriple: Triple,
967967
properties: SwiftSDKMetadataV4.TripleProperties,
968968
toolset: Toolset = .init(),
@@ -1164,8 +1164,8 @@ struct SerializedDestinationV3: Decodable {
11641164
}
11651165

11661166
/// Represents v4 schema of `swift-sdk.json` (previously `destination.json`) files used for cross-compilation.
1167-
struct SwiftSDKMetadataV4: Decodable {
1168-
struct TripleProperties: Codable {
1167+
package struct SwiftSDKMetadataV4: Decodable {
1168+
package struct TripleProperties: Codable {
11691169
/// Path relative to `swift-sdk.json` containing SDK root.
11701170
var sdkRootPath: String
11711171

@@ -1183,6 +1183,15 @@ struct SwiftSDKMetadataV4: Decodable {
11831183

11841184
/// Array of paths relative to `swift-sdk.json` containing toolset files.
11851185
var toolsetPaths: [String]?
1186+
1187+
package init(sdkRootPath: String, swiftResourcesPath: String? = nil, swiftStaticResourcesPath: String? = nil, includeSearchPaths: [String]? = nil, librarySearchPaths: [String]? = nil, toolsetPaths: [String]? = nil) {
1188+
self.sdkRootPath = sdkRootPath
1189+
self.swiftResourcesPath = swiftResourcesPath
1190+
self.swiftStaticResourcesPath = swiftStaticResourcesPath
1191+
self.includeSearchPaths = includeSearchPaths
1192+
self.librarySearchPaths = librarySearchPaths
1193+
self.toolsetPaths = toolsetPaths
1194+
}
11861195
}
11871196

11881197
/// Mapping of triple strings to corresponding properties of such target triple.

Sources/PackageModel/SwiftSDKs/SwiftSDKBundle.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public struct SwiftSDKBundle {
2121
public struct Variant: Equatable {
2222
let metadata: ArtifactsArchiveMetadata.Variant
2323
let swiftSDKs: [SwiftSDK]
24+
25+
package init(metadata: ArtifactsArchiveMetadata.Variant, swiftSDKs: [SwiftSDK]) {
26+
self.metadata = metadata
27+
self.swiftSDKs = swiftSDKs
28+
}
2429
}
2530

2631
// Path to the bundle root directory.
@@ -31,6 +36,11 @@ public struct SwiftSDKBundle {
3136

3237
/// Name of the Swift SDK bundle that can be used to distinguish it from other bundles.
3338
public var name: String { path.basename }
39+
40+
package init(path: AbsolutePath, artifacts: [String:[SwiftSDKBundle.Variant]] = [:]) {
41+
self.path = path
42+
self.artifacts = artifacts
43+
}
3444
}
3545

3646
extension SwiftSDKBundle.Variant {
@@ -81,7 +91,7 @@ extension [SwiftSDKBundle] {
8191
/// - hostTriple: triple of the host building with these Swift SDKs.
8292
/// - observabilityScope: observability scope to log warnings about multiple matches.
8393
/// - Returns: ``SwiftSDK`` value matching `query` either by artifact ID or target triple, `nil` if none found.
84-
func selectSwiftSDK(
94+
package func selectSwiftSDK(
8595
matching selector: String,
8696
hostTriple: Triple,
8797
observabilityScope: ObservabilityScope

Sources/PackageModel/Toolset.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public struct Toolset: Equatable {
3838

3939
/// Command-line options to be passed to the tool when it's invoked.
4040
public internal(set) var extraCLIOptions: [String]
41+
42+
package init(path: AbsolutePath? = nil, extraCLIOptions: [String] = []) {
43+
self.path = path
44+
self.extraCLIOptions = extraCLIOptions
45+
}
4146
}
4247

4348
/// A dictionary of known tools in this toolset.
@@ -46,10 +51,18 @@ public struct Toolset: Equatable {
4651
/// An array of paths specified as `rootPath` in toolset files from which this toolset was formed. May be used
4752
/// for locating tools that aren't currently listed in ``Toolset/KnownTool``.
4853
public internal(set) var rootPaths: [AbsolutePath] = []
54+
55+
package init(
56+
knownTools: [KnownTool: ToolProperties] = [:],
57+
rootPaths: [AbsolutePath] = []
58+
) {
59+
self.knownTools = knownTools
60+
self.rootPaths = rootPaths
61+
}
4962
}
5063

5164
extension Toolset.ToolProperties {
52-
init(path: AbsolutePath) {
65+
package init(path: AbsolutePath) {
5366
self.init(path: path, extraCLIOptions: [])
5467
}
5568
}

Sources/PackageModel/UserToolchain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public final class UserToolchain: Toolchain {
508508
}
509509
#endif
510510

511-
internal static func deriveSwiftCFlags(
511+
package static func deriveSwiftCFlags(
512512
triple: Basics.Triple,
513513
swiftSDK: SwiftSDK,
514514
environment: Environment,

0 commit comments

Comments
 (0)