Skip to content

Commit

Permalink
Fix tuist generate when a binary dependency is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
fortmarek committed May 20, 2024
1 parent f9f3f98 commit db03ad9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Sources/TuistLoader/SwiftPackageManager/PackageInfoMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,18 @@ public final class PackageInfoMapper: PackageInfoMapping {
packageToFolder[packageInfo.key]!.appending(try RelativePath(validating: path))
.pathString
)
} else {
// remote binaries are checked out by SPM in artifacts/<Package.name>/<Target>.xcframework
// or in artifacts/<Package.identity>/<Target>.xcframework when using SPM 5.6 and later
guard let artifactPath = packageToTargetsToArtifactPaths[packageInfo.key]?[target.name] else {
throw PackageInfoMapperError.missingBinaryArtifact(package: packageInfo.key, target: target.name)
}
}
// remote binaries are checked out by SPM in artifacts/<Package.name>/<Target>.xcframework
// or in artifacts/<Package.identity>/<Target>.xcframework when using SPM 5.6 and later
else if let artifactPath = packageToTargetsToArtifactPaths[packageInfo.key]?[target.name] {
result[target.name] = .path(artifactPath.pathString)
}
// If the binary path is not present in the `.build/workspace-state.json`, we try to use a default path.
// If the target is not used by a downstream target, the generation will succeed.
// Otherwise, users will get an error that the xcframework was not found.
else {
result[target.name] = .path(packageToFolder[packageInfo.key]!.appending(components: target.name, "\(target.name).xcframework")
.pathString)
}
}
}
Expand Down Expand Up @@ -339,7 +344,7 @@ public final class PackageInfoMapper: PackageInfoMapping {
targetSettings: targetSettings
)
}

guard !targets.isEmpty else {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,42 @@ final class PackageInfoMapperTests: TuistUnitTestCase {
)
}

func testResolveDependencies_whenProductContainsBinaryTargetMissingFrom_packageToTargetsToArtifactPaths() throws {
let basePath = try temporaryPath()
try fileHandler.createFolder(basePath.appending(try RelativePath(validating: "Sources/Target_1")))
try fileHandler.createFolder(basePath.appending(try RelativePath(validating: "Sources/Target_2")))
let resolvedDependencies = try subject.resolveExternalDependencies(
packageInfos: [
"Package": .init(
name: "Package",
products: [
.init(name: "Product1", type: .library(.automatic), targets: ["Target_1", "Target_2"]),
],
targets: [
.test(name: "Target_1", type: .binary, url: "https://binary.target.com"),
.test(name: "Target_2"),
],
platforms: [.ios],
cLanguageStandard: nil,
cxxLanguageStandard: nil,
swiftLanguageVersions: nil
),
],
packageToFolder: ["Package": basePath],
packageToTargetsToArtifactPaths: [:]
)

XCTAssertEqual(
resolvedDependencies,
[
"Product1": [
.xcframework(path: "\(basePath.pathString)/Target_1/Target_1.xcframework"),
.project(target: "Target_2", path: .relativeToManifest(basePath.pathString)),
],
]
)
}

func testResolveDependencies_whenPackageIDDifferentThanName() throws {
let basePath = try temporaryPath()
try fileHandler.createFolder(basePath.appending(try RelativePath(validating: "Package/Sources/Target_1")))
Expand Down

0 comments on commit db03ad9

Please sign in to comment.