Skip to content

Commit 0647265

Browse files
authored
Fail early if expected XCFramework is not present (#2722)
Currently, we rely on a build failure if an expected XCFramework isn't present in a downloaded ZIP. We should instead check if the expected XCFramework is present while extracting the ZIP so that we can surface this error already during package loading. rdar://problem/60619547
1 parent 07ae5a9 commit 0647265

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

Sources/SPMTestSupport/TestWorkspace.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public final class TestWorkspace {
7272
return sandbox.appending(component: "pkgs")
7373
}
7474

75+
public var artifactsDir: AbsolutePath {
76+
return sandbox.appending(components: ".build", "artifacts")
77+
}
78+
7579
public func urlForPackage(withName name: String) -> String {
7680
return packagesDir.appending(RelativePath(name)).pathString
7781
}

Sources/Workspace/Diagnostics.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,8 @@ extension Diagnostic.Message {
148148
static func artifactFailedExtraction(targetName: String, reason: String) -> Diagnostic.Message {
149149
.error("artifact of binary target '\(targetName)' failed extraction: \(reason)")
150150
}
151+
152+
static func artifactNotFound(targetName: String, artifactName: String) -> Diagnostic.Message {
153+
.error("downloaded archive of binary target '\(targetName)' does not contain expected binary artifact '\(artifactName)'")
154+
}
151155
}

Sources/Workspace/Workspace.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,9 @@ extension Workspace {
14081408
self.archiver.extract(from: archivePath, to: parentDirectory, completion: { extractResult in
14091409
switch extractResult {
14101410
case .success:
1411+
if let expectedPath = self.path(for: artifact), !self.fileSystem.isDirectory(expectedPath) {
1412+
tempDiagnostics.emit(.artifactNotFound(targetName: artifact.targetName, artifactName: expectedPath.basename))
1413+
}
14111414
break
14121415
case .failure(let error):
14131416
let reason = (error as? LocalizedError)?.errorDescription ?? error.localizedDescription

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4205,6 +4205,11 @@ final class WorkspaceTests: XCTestCase {
42054205
let a4FrameworkPath = workspace.packagesDir.appending(components: "A", "A4.xcframework")
42064206
try fs.createDirectory(a4FrameworkPath, recursive: true)
42074207

4208+
try [("A", "A1.xcframework"), ("A", "A2.xcframework"), ("B", "B.xcframework")].forEach {
4209+
let frameworkPath = workspace.artifactsDir.appending(components: $0.0, $0.1)
4210+
try fs.createDirectory(frameworkPath, recursive: true)
4211+
}
4212+
42084213
// Pin A to 1.0.0, Checkout B to 1.0.0
42094214
let aPath = workspace.urlForPackage(withName: "A")
42104215
let aRef = PackageReference(identity: "a", path: aPath)
@@ -4252,7 +4257,7 @@ final class WorkspaceTests: XCTestCase {
42524257
)
42534258

42544259
workspace.checkPackageGraph(roots: ["Foo"]) { graph, diagnostics in
4255-
XCTAssert(!diagnostics.hasErrors, "\(diagnostics.diagnostics)")
4260+
XCTAssertEqual(diagnostics.diagnostics.map { $0.message.text }, ["downloaded archive of binary target 'A3' does not contain expected binary artifact 'A3.xcframework'"])
42564261
XCTAssert(fs.isDirectory(AbsolutePath("/tmp/ws/.build/artifacts/B")))
42574262
XCTAssert(!fs.exists(AbsolutePath("/tmp/ws/.build/artifacts/A/A3.xcframework")))
42584263
XCTAssert(!fs.exists(AbsolutePath("/tmp/ws/.build/artifacts/A/A4.xcframework")))

0 commit comments

Comments
 (0)