Skip to content

Commit

Permalink
Pass storages to CacheSystem.cacheFrameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo committed Nov 8, 2024
1 parent 8c13df7 commit 9f7018b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
11 changes: 4 additions & 7 deletions Sources/ScipioKit/Producer/Cache/CacheSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ struct CacheSystem: Sendable {
static let defaultParalellNumber = 8
private let pinsStore: PinsStore
private let outputDirectory: URL
private let writableStorages: [any CacheStorage]
private let fileSystem: any FileSystem

struct CacheTarget: Hashable, Sendable {
Expand Down Expand Up @@ -139,23 +138,21 @@ struct CacheSystem: Sendable {
init(
pinsStore: PinsStore,
outputDirectory: URL,
writableStorages: [any CacheStorage],
fileSystem: any FileSystem = localFileSystem
) {
self.pinsStore = pinsStore
self.outputDirectory = outputDirectory
self.writableStorages = writableStorages
self.fileSystem = fileSystem
}

func cacheFrameworks(_ targets: Set<CacheTarget>) async {
guard !writableStorages.isEmpty else {
// About `CacheMode.project` which does not have any writableStorages, we don't need to do anything.
func cacheFrameworks(_ targets: Set<CacheTarget>, storages: [any CacheStorage]?) async {
guard let storages, !storages.isEmpty else {
// About `CacheMode.project` which is not tied to any (external) storages, we don't need to do anything.
// The built frameworks under the project themselves are treated as valid caches.
return
}

for storage in writableStorages {
for storage in storages {
await cacheFrameworks(targets, storage: storage)
}
}
Expand Down
8 changes: 5 additions & 3 deletions Sources/ScipioKit/Producer/FrameworkProducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ struct FrameworkProducer {

let cacheSystem = CacheSystem(
pinsStore: pinsStore,
outputDirectory: outputDir,
writableStorages: cacheStorages(for: .producer) ?? []
outputDirectory: outputDir
)
let cacheEnabledTargets: Set<CacheSystem.CacheTarget>
if cacheMode.isConsumingCacheEnabled {
Expand All @@ -141,7 +140,10 @@ struct FrameworkProducer {
}

if isProducingCacheEnabled {
await cacheSystem.cacheFrameworks(Set(targetsToBuild))
await cacheSystem.cacheFrameworks(
Set(targetsToBuild),
storages: cacheStorages(for: .producer)
)
}

if shouldGenerateVersionFile {
Expand Down
3 changes: 1 addition & 2 deletions Tests/ScipioKitTests/CacheSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ final class CacheSystemTests: XCTestCase {
)
let cacheSystem = CacheSystem(
pinsStore: try descriptionPackage.workspace.pinsStore.load(),
outputDirectory: FileManager.default.temporaryDirectory.appendingPathComponent("XCFrameworks"),
writableStorages: []
outputDirectory: FileManager.default.temporaryDirectory.appendingPathComponent("XCFrameworks")
)
let testingPackage = descriptionPackage
.graph
Expand Down
6 changes: 2 additions & 4 deletions Tests/ScipioKitTests/RunnerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ final class RunnerTests: XCTestCase {
let pinsStore = try descriptionPackage.workspace.pinsStore.load()
let cacheSystem = CacheSystem(
pinsStore: pinsStore,
outputDirectory: frameworkOutputDir,
writableStorages: []
outputDirectory: frameworkOutputDir
)
let packages = descriptionPackage.graph.packages
.filter { $0.manifest.displayName != descriptionPackage.manifest.displayName }
Expand Down Expand Up @@ -436,8 +435,7 @@ final class RunnerTests: XCTestCase {
let pinsStore = try descriptionPackage.workspace.pinsStore.load()
let cacheSystem = CacheSystem(
pinsStore: pinsStore,
outputDirectory: frameworkOutputDir,
writableStorages: []
outputDirectory: frameworkOutputDir
)
let packages = descriptionPackage.graph.packages
.filter { $0.manifest.displayName != descriptionPackage.manifest.displayName }
Expand Down

0 comments on commit 9f7018b

Please sign in to comment.