Skip to content

Commit fd4e5ee

Browse files
committed
cleanup
1 parent 19d50cc commit fd4e5ee

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,8 @@ public class BuildPlan {
18321832
case .artifactsArchive:
18331833
let tools = try self.parseArtifactsArchive(for: binaryTarget)
18341834
tools.forEach { availableTools[$0.name] = $0.executablePath }
1835+
case.unknown:
1836+
throw InternalError("unknown binary target '\(target.name)' type")
18351837
}
18361838
case .plugin:
18371839
continue

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
405405

406406
var validExtensions = [self.supportedArchiveExtension]
407407
if target.isLocal {
408-
validExtensions += BinaryTarget.Kind.allCases.map { $0.fileExtension }
408+
validExtensions += BinaryTarget.Kind.allCases.filter{ $0 != .unknown }.map { $0.fileExtension }
409409
}
410410

411411
if !validExtensions.contains(location.pathExtension) {

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public enum ModuleError: Swift.Error {
3232
/// The artifact for the binary target could not be found.
3333
case artifactNotFound(String)
3434

35+
/// The artifact is not available on disk
36+
case artifactNotAvailable(String)
37+
3538
/// Invalid custom path.
3639
case invalidCustomPath(target: String, path: String)
3740

@@ -83,6 +86,8 @@ extension ModuleError: CustomStringConvertible {
8386
return "Source files for target \(target) should be located under '\(folderName)/\(target)', or a custom sources path can be set with the 'path' property in Package.swift"
8487
case .artifactNotFound(let target):
8588
return "artifact not found for target '\(target)'"
89+
case .artifactNotAvailable(let target):
90+
return "artifact not available for target '\(target)'"
8691
case .invalidLayout(let type):
8792
return "package has unsupported layout; \(type)"
8893
case .invalidManifestConfig(let package, let message):
@@ -195,9 +200,9 @@ public struct BinaryArtifact {
195200
public let originURL: String?
196201

197202
/// The path to the artifact.
198-
public let path: AbsolutePath
203+
public let path: AbsolutePath?
199204

200-
public init(kind: BinaryTarget.Kind, originURL: String?, path: AbsolutePath) {
205+
public init(kind: BinaryTarget.Kind, originURL: String?, path: AbsolutePath?) {
201206
self.kind = kind
202207
self.originURL = originURL
203208
self.path = path
@@ -533,10 +538,13 @@ public final class PackageBuilder {
533538
/// Returns the path of the given target.
534539
func findPath(for target: TargetDescription) throws -> AbsolutePath {
535540
if target.type == .binary {
536-
guard let artifact = self.binaryArtifacts.first(where: { $0.path.basenameWithoutExt == target.name }) else {
541+
guard let artifact = self.binaryArtifacts.first(where: { $0.path?.basenameWithoutExt == target.name }) else {
537542
throw ModuleError.artifactNotFound(target.name)
538543
}
539-
return artifact.path
544+
guard let path = artifact.path else {
545+
throw ModuleError.artifactNotAvailable(target.name)
546+
}
547+
return path
540548
} else if let subpath = target.path { // If there is a custom path defined, use that.
541549
if subpath == "" || subpath == "." {
542550
return packagePath

Sources/PackageModel/Target.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,16 @@ public final class BinaryTarget: Target {
551551
public enum Kind: String, RawRepresentable, Codable, CaseIterable {
552552
case xcframework
553553
case artifactsArchive
554+
case unknown // for non-downloaded artifacts
554555

555556
public var fileExtension: String {
556557
switch self {
557558
case .xcframework:
558559
return "xcframework"
559560
case .artifactsArchive:
560561
return "artifactbundle"
562+
case .unknown:
563+
return "unknown"
561564
}
562565
}
563566

Sources/Workspace/Workspace.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,14 +1021,13 @@ extension Workspace {
10211021

10221022
// radar/82263304
10231023
// compute binary artifacts for the sake of constructing a project model
1024-
// note this does not actually download remote artifacts and as such does not have the artifact's correct path
1024+
// note this does not actually download remote artifacts and as such does not have the artifact's type or path
10251025
let binaryArtifacts = try manifest.targets.filter{ $0.type == .binary }.map { target -> BinaryArtifact in
10261026
if let path = target.path {
10271027
let absolutePath = try manifest.path.parentDirectory.appending(RelativePath(validating: path))
10281028
return try BinaryArtifact(kind: .forFileExtension(absolutePath.extension ?? "unknown") , originURL: .none, path: absolutePath)
10291029
} else if let url = target.url.flatMap(URL.init(string:)) {
1030-
let fakePath = try manifest.path.parentDirectory.appending(components: "remote", "archive").appending(RelativePath(validating: url.lastPathComponent))
1031-
return BinaryArtifact(kind: .xcframework , originURL: url.absoluteString, path: fakePath)
1030+
return BinaryArtifact(kind: .unknown, originURL: url.absoluteString, path: .none)
10321031
} else {
10331032
throw InternalError("a binary target should have either a path or a URL and a checksum")
10341033
}

0 commit comments

Comments
 (0)