Skip to content
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

Fix tuist generate when a binary SPM dependency is removed #6298

Merged
merged 1 commit into from
May 20, 2024
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Apple for continuing to make developers' life harder every day πŸ˜†

// 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