Skip to content

Commit

Permalink
Fix tuist generate when a binary dependency is removed (#6298)
Browse files Browse the repository at this point in the history
  • Loading branch information
fortmarek committed May 20, 2024
1 parent f9f3f98 commit e157ebd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Sources/TuistLoader/SwiftPackageManager/PackageInfoMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,24 @@ 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 ignore a missing binary artifact.
// 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
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 e157ebd

Please sign in to comment.