Skip to content

Commit 2fed024

Browse files
authored
Fix swift package describe for packages with binary artifacts that has a .zip extension. (#8809)
Fix `swift package describe` for packages with binary artifacts that has a .zip extension. ### Motivation: Fixes #4387 I want to avoid an error when running `swift package describe` on a package that contains a binary artifact target with a `.zip` extension. ### Modifications: I modified the `Workspace.loadRootPackage(at:observabilityScope:completion)` method. Specifically, I updated the logic for local binary targets to also return a `BinaryArtifact` object when the file extension is `.zip`. This change is also based on the comment referenced [here](#5826 (comment)). ### Result: When running `swift package describe` on a package that contains a binary artifact target with a `.zip` extension, the package description is now output without throwing an error.
1 parent e289541 commit 2fed024

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

Sources/Workspace/Workspace.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,18 +1161,25 @@ extension Workspace {
11611161
if let path = target.path {
11621162
let artifactPath = try manifest.path.parentDirectory
11631163
.appending(RelativePath(validating: path))
1164-
guard let (_, artifactKind) = try BinaryArtifactsManager.deriveBinaryArtifact(
1164+
if artifactPath.extension?.lowercased() == "zip" {
1165+
partial[target.name] = BinaryArtifact(
1166+
kind: .unknown,
1167+
originURL: .none,
1168+
path: artifactPath
1169+
)
1170+
} else if let (_, artifactKind) = try BinaryArtifactsManager.deriveBinaryArtifact(
11651171
fileSystem: self.fileSystem,
11661172
path: artifactPath,
11671173
observabilityScope: observabilityScope
1168-
) else {
1174+
) {
1175+
partial[target.name] = BinaryArtifact(
1176+
kind: artifactKind,
1177+
originURL: .none,
1178+
path: artifactPath
1179+
)
1180+
} else {
11691181
throw StringError("\(artifactPath) does not contain binary artifact")
11701182
}
1171-
partial[target.name] = BinaryArtifact(
1172-
kind: artifactKind,
1173-
originURL: .none,
1174-
path: artifactPath
1175-
)
11761183
} else if let url = target.url.flatMap(URL.init(string:)) {
11771184
let fakePath = try manifest.path.parentDirectory.appending(components: "remote", "archive")
11781185
.appending(RelativePath(validating: url.lastPathComponent))

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9231,6 +9231,11 @@ final class WorkspaceTests: XCTestCase {
92319231
url: "https://a.com/a2.zip.zip",
92329232
checksum: "a3"
92339233
),
9234+
MockTarget(
9235+
name: "A4",
9236+
type: .binary,
9237+
path: "a4.zip"
9238+
),
92349239
],
92359240
products: []
92369241
),

0 commit comments

Comments
 (0)