diff --git a/Sources/ScipioKit/Producer/Cache/CacheSystem.swift b/Sources/ScipioKit/Producer/Cache/CacheSystem.swift index 33d5ee0..a3842ec 100644 --- a/Sources/ScipioKit/Producer/Cache/CacheSystem.swift +++ b/Sources/ScipioKit/Producer/Cache/CacheSystem.swift @@ -96,9 +96,10 @@ extension PinsStore.PinState: @retroactive Hashable { } public struct SwiftPMCacheKey: CacheKey { - public var canonicalPackageLocation: String - public var targetName: String + /// The canonical repository URL the manifest was loaded from, for local packages only. + public var localPackageCanonicalLocation: String? public var pin: PinsStore.PinState + public var targetName: String var buildOptions: BuildOptions public var clangVersion: String public var xcodeVersion: XcodeVersion @@ -231,9 +232,18 @@ struct CacheSystem: Sendable { } func calculateCacheKey(of target: CacheTarget) async throws -> SwiftPMCacheKey { - let canonicalPackageLocation = target.buildProduct.package.manifest.canonicalPackageLocation + let package = target.buildProduct.package + + let localPackageCanonicalLocation: String? = switch package.manifest.packageKind { + case .fileSystem, .localSourceControl: + package.manifest.canonicalPackageLocation.description + case .root, .remoteSourceControl, .registry: + nil + } + + let pin = try retrievePin(package: package) + let targetName = target.buildProduct.target.name - let pin = try retrievePin(package: target.buildProduct.package) let buildOptions = target.buildOptions guard let clangVersion = try await ClangChecker().fetchClangVersion() else { throw Error.compilerVersionNotDetected @@ -242,9 +252,9 @@ struct CacheSystem: Sendable { throw Error.xcodeVersionNotDetected } return SwiftPMCacheKey( - canonicalPackageLocation: canonicalPackageLocation.description, - targetName: targetName, + localPackageCanonicalLocation: localPackageCanonicalLocation, pin: pin.state, + targetName: targetName, buildOptions: buildOptions, clangVersion: clangVersion, xcodeVersion: xcodeVersion, diff --git a/Tests/ScipioKitTests/CacheSystemTests.swift b/Tests/ScipioKitTests/CacheSystemTests.swift index 4a632da..55a7a4b 100644 --- a/Tests/ScipioKitTests/CacheSystemTests.swift +++ b/Tests/ScipioKitTests/CacheSystemTests.swift @@ -2,6 +2,7 @@ import Foundation @testable import ScipioKit import XCTest import Basics +import struct PackageModel.CanonicalPackageLocation private let fixturePath = URL(fileURLWithPath: #filePath) .deletingLastPathComponent() @@ -19,9 +20,9 @@ final class CacheSystemTests: XCTestCase { func testEncodeCacheKey() throws { let cacheKey = SwiftPMCacheKey( - canonicalPackageLocation: "/path/to/MyPackage", - targetName: "MyTarget", + localPackageCanonicalLocation: "/path/to/MyPackage", pin: .revision("111111111"), + targetName: "MyTarget", buildOptions: .init( buildConfiguration: .release, isDebugSymbolsEmbedded: false, @@ -64,7 +65,7 @@ final class CacheSystemTests: XCTestCase { "iOS" ] }, - "canonicalPackageLocation" : "\\/path\\/to\\/MyPackage", + "localPackageCanonicalLocation" : "\\/path\\/to\\/MyPackage", "clangVersion" : "clang-1400.0.29.102", "pin" : { "revision" : "111111111" @@ -147,7 +148,11 @@ final class CacheSystemTests: XCTestCase { let scipioTestingRemote = try await scipioTestingCacheKey(fixture: "AsRemotePackage") let scipioTestingLocal = try await scipioTestingCacheKey(fixture: "AsLocalPackage") - XCTAssertNotEqual(scipioTestingRemote.canonicalPackageLocation, scipioTestingLocal.canonicalPackageLocation) + XCTAssertNil(scipioTestingRemote.localPackageCanonicalLocation) + XCTAssertEqual( + scipioTestingLocal.localPackageCanonicalLocation, + CanonicalPackageLocation(tempDir.appending(component: "scipio-testing").pathString).description + ) XCTAssertEqual(scipioTestingRemote.targetName, scipioTestingLocal.targetName) XCTAssertEqual(scipioTestingRemote.pin, scipioTestingLocal.pin) }