Skip to content

Fail early if expected XCFramework is not present #2725

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

Merged
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
4 changes: 4 additions & 0 deletions Sources/SPMTestSupport/TestWorkspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public final class TestWorkspace {
return sandbox.appending(component: "pkgs")
}

public var artifactsDir: AbsolutePath {
return sandbox.appending(components: ".build", "artifacts")
}

public func urlForPackage(withName name: String) -> String {
return packagesDir.appending(RelativePath(name)).pathString
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/Workspace/Diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,8 @@ extension Diagnostic.Message {
static func artifactFailedExtraction(targetName: String, reason: String) -> Diagnostic.Message {
.error("artifact of binary target '\(targetName)' failed extraction: \(reason)")
}

static func artifactNotFound(targetName: String, artifactName: String) -> Diagnostic.Message {
.error("downloaded archive of binary target '\(targetName)' does not contain expected binary artifact '\(artifactName)'")
}
}
3 changes: 3 additions & 0 deletions Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,9 @@ extension Workspace {
self.archiver.extract(from: archivePath, to: parentDirectory, completion: { extractResult in
switch extractResult {
case .success:
if let expectedPath = self.path(for: artifact), !self.fileSystem.isDirectory(expectedPath) {
tempDiagnostics.emit(.artifactNotFound(targetName: artifact.targetName, artifactName: expectedPath.basename))
}
break
case .failure(let error):
let reason = (error as? LocalizedError)?.errorDescription ?? error.localizedDescription
Expand Down
7 changes: 6 additions & 1 deletion Tests/WorkspaceTests/WorkspaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4205,6 +4205,11 @@ final class WorkspaceTests: XCTestCase {
let a4FrameworkPath = workspace.packagesDir.appending(components: "A", "A4.xcframework")
try fs.createDirectory(a4FrameworkPath, recursive: true)

try [("A", "A1.xcframework"), ("A", "A2.xcframework"), ("B", "B.xcframework")].forEach {
let frameworkPath = workspace.artifactsDir.appending(components: $0.0, $0.1)
try fs.createDirectory(frameworkPath, recursive: true)
}

// Pin A to 1.0.0, Checkout B to 1.0.0
let aPath = workspace.urlForPackage(withName: "A")
let aRef = PackageReference(identity: "a", path: aPath)
Expand Down Expand Up @@ -4252,7 +4257,7 @@ final class WorkspaceTests: XCTestCase {
)

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