Skip to content

Make sdkRootPath property of swift-sdk.json targetTriples object optional #8687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions Sources/PackageModel/SwiftSDKs/SwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ public struct SwiftSDK: Equatable {
fileprivate init(_ properties: SwiftSDKMetadataV4.TripleProperties, swiftSDKDirectory: Basics.AbsolutePath? = nil) throws {
if let swiftSDKDirectory {
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 All @@ -369,7 +371,9 @@ public struct SwiftSDK: Equatable {
)
} else {
self.init(
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath),
sdkRootPath: try properties.sdkRootPath.map {
try AbsolutePath(validating: $0)
},
swiftResourcesPath: try properties.swiftResourcesPath.map {
try AbsolutePath(validating: $0)
},
Expand Down Expand Up @@ -1167,7 +1171,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