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

Add canonical package location to SwiftPMCacheKey to differentiate the same target when its package is changed from remote one to local one (or vice-versa) #168

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions Sources/ScipioKit/Producer/Cache/CacheSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ extension PinsStore.PinState: @retroactive Hashable {
}

public struct SwiftPMCacheKey: CacheKey {
public var packageIdentity: PackageIdentity
public var targetName: String
public var pin: PinsStore.PinState
var buildOptions: BuildOptions
Expand Down Expand Up @@ -230,6 +231,7 @@ struct CacheSystem: Sendable {
}

func calculateCacheKey(of target: CacheTarget) async throws -> SwiftPMCacheKey {
let packageIdentity = target.buildProduct.package.identity
let targetName = target.buildProduct.target.name
let pin = try retrievePin(package: target.buildProduct.package)
let buildOptions = target.buildOptions
Expand All @@ -240,6 +242,7 @@ struct CacheSystem: Sendable {
throw Error.xcodeVersionNotDetected
}
return SwiftPMCacheKey(
packageIdentity: packageIdentity,
targetName: targetName,
pin: pin.state,
buildOptions: buildOptions,
Expand Down
3 changes: 3 additions & 0 deletions Tests/ScipioKitTests/CacheSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation
@testable import ScipioKit
import XCTest
import Basics
import PackageModel

private let fixturePath = URL(fileURLWithPath: #filePath)
.deletingLastPathComponent()
Expand All @@ -19,6 +20,7 @@ final class CacheSystemTests: XCTestCase {

func testEncodeCacheKey() throws {
let cacheKey = SwiftPMCacheKey(
packageIdentity: PackageIdentity.plain("MyPackage"),
targetName: "MyTarget",
pin: .revision("111111111"),
buildOptions: .init(
Expand Down Expand Up @@ -64,6 +66,7 @@ final class CacheSystemTests: XCTestCase {
]
},
"clangVersion" : "clang-1400.0.29.102",
"packageIdentity" : "MyPackage",
"pin" : {
"revision" : "111111111"
},
Expand Down