Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Sources/PackageModel/SwiftSDKs/SwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ public struct SwiftSDK: Equatable {
swiftSDKDirectory: Basics.AbsolutePath? = nil
) throws where Path == Basics.AbsolutePath {
self.init(
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory),
sdkRootPath: try properties.sdkRootPath.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
swiftResourcesPath: try properties.swiftResourcesPath.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
Expand Down Expand Up @@ -1175,7 +1177,7 @@ struct SerializedDestinationV3: Decodable {
struct SwiftSDKMetadataV4: Decodable {
struct TripleProperties: Codable {
/// Path relative to `swift-sdk.json` containing SDK root.
var sdkRootPath: String
var sdkRootPath: String?

/// Path relative to `swift-sdk.json` containing Swift resources for dynamic linking.
var swiftResourcesPath: String?
Expand Down
42 changes: 42 additions & 0 deletions Tests/PackageModelTests/SwiftSDKTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private let hostTriple = try! Triple("arm64-apple-darwin22.1.0")
private let olderHostTriple = try! Triple("arm64-apple-darwin20.1.0")
private let linuxGNUTargetTriple = try! Triple("x86_64-unknown-linux-gnu")
private let linuxMuslTargetTriple = try! Triple("x86_64-unknown-linux-musl")
private let androidTargetTriple = try! Triple("aarch64-unknown-linux-android28")
private let wasiTargetTriple = try! Triple("wasm32-unknown-wasi")
private let extraFlags = BuildFlags(
cCompilerFlags: ["-fintegrated-as"],
Expand Down Expand Up @@ -186,6 +187,20 @@ private let toolsetRootSwiftSDKv4 = (
"""# as SerializedJSON
)

private let androidWithoutSDKRootPathSwiftSDKv4 = (
path: bundleRootPath.appending(component: "androidWithoutSDKRootPathSwiftSDKv4.json"),
json: #"""
{
"targetTriples": {
"\#(androidTargetTriple.tripleString)": {
"toolsetPaths": ["/tools/otherToolsNoRoot.json"]
}
},
"schemaVersion": "4.0"
}
"""# as SerializedJSON
)

private let missingToolsetSwiftSDKv4 = (
path: bundleRootPath.appending(component: "missingToolsetSwiftSDKv4.json"),
json: #"""
Expand Down Expand Up @@ -351,6 +366,23 @@ private let parsedToolsetRootDestination = SwiftSDK(
)
)

private let parsedToolsetNoSDKRootPathDestination = SwiftSDK(
targetTriple: androidTargetTriple,
toolset: .init(
knownTools: [
.librarian: .init(path: try! AbsolutePath(validating: "\(usrBinTools[.librarian]!)")),
.linker: .init(path: try! AbsolutePath(validating: "\(usrBinTools[.linker]!)")),
.debugger: .init(path: try! AbsolutePath(validating: "\(usrBinTools[.debugger]!)")),
],
rootPaths: []
),
pathsConfiguration: .init(
sdkRootPath: nil,
toolsetPaths: ["/tools/otherToolsNoRoot.json"]
.map { try! AbsolutePath(validating: $0) }
)
)

private let testFiles: [(path: AbsolutePath, json: SerializedJSON)] = [
destinationV1,
destinationV2,
Expand All @@ -365,6 +397,7 @@ private let testFiles: [(path: AbsolutePath, json: SerializedJSON)] = [
invalidVersionSwiftSDKv4,
invalidToolsetSwiftSDKv4,
wasiWithoutToolsetsSwiftSDKv4,
androidWithoutSDKRootPathSwiftSDKv4,
otherToolsNoRoot,
someToolsWithRoot,
invalidToolset,
Expand Down Expand Up @@ -488,6 +521,15 @@ final class SwiftSDKTests: XCTestCase {

XCTAssertEqual(toolsetRootSwiftSDKv4Decoded, [parsedToolsetRootDestination])

let androidWithoutSDKRootPathSwiftSDKv4Decoded = try SwiftSDK.decode(
fromFile: androidWithoutSDKRootPathSwiftSDKv4.path,
hostToolchainBinDir: toolchainBinAbsolutePath,
fileSystem: fs,
observabilityScope: observability
)

XCTAssertEqual(androidWithoutSDKRootPathSwiftSDKv4Decoded, [parsedToolsetNoSDKRootPathDestination])

XCTAssertThrowsError(try SwiftSDK.decode(
fromFile: missingToolsetSwiftSDKv4.path,
hostToolchainBinDir: toolchainBinAbsolutePath,
Expand Down