Skip to content

Commit

Permalink
Adding a package location to SwiftPMCacheKey for local packages only
Browse files Browse the repository at this point in the history
For remote packages, dependency mirroring will be a problem, so avoiding.
  • Loading branch information
ikesyo committed Dec 13, 2024
1 parent f02498c commit 0f6e237
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
22 changes: 16 additions & 6 deletions Sources/ScipioKit/Producer/Cache/CacheSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
13 changes: 9 additions & 4 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 struct PackageModel.CanonicalPackageLocation

private let fixturePath = URL(fileURLWithPath: #filePath)
.deletingLastPathComponent()
Expand All @@ -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,
Expand Down Expand Up @@ -64,8 +65,8 @@ final class CacheSystemTests: XCTestCase {
"iOS"
]
},
"canonicalPackageLocation" : "\\/path\\/to\\/MyPackage",
"clangVersion" : "clang-1400.0.29.102",
"localPackageCanonicalLocation" : "\\/path\\/to\\/MyPackage",
"pin" : {
"revision" : "111111111"
},
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 0f6e237

Please sign in to comment.