Skip to content

Commit

Permalink
Fix generator caching for multi-project setups
Browse files Browse the repository at this point in the history
Test target caching is currently done relative to the source project
which causes improper invalidation when the source and test targets
are in the same Xcode project. The downstream effect is that incremental
Xcode builds are much slower for large projects since the generated mock
file is “modified” each run.

This fixes the test target caching by using the environment-supplied
project and srcroot values for the cache key.
  • Loading branch information
andrewchang-bird committed Jan 6, 2022
1 parent 90a260a commit e73c911
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Sources/MockingbirdCli/Interface/Handlers/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Generator {
func getProjectHash(_ projectPath: Path) -> String? {
if let projectHash = projectHash { return projectHash }
let filePath = projectPath.extension == "xcodeproj"
? projectPath.glob("*.pbxproj").first
? projectPath.glob("*.pbxproj").sorted().first
: projectPath
let projectHash = try? filePath?.read().generateSha1Hash()
self.projectHash = projectHash
Expand All @@ -135,13 +135,15 @@ class Generator {
func getCachedTestTarget(targetName: String) -> TargetType? {
guard config.pruningMethod != .disable,
let cacheDirectory = testTargetCacheDirectory,
let projectHash = getProjectHash(config.projectPath),
let testProjectPath = config.environmentProjectFilePath,
let testSourceRoot = config.environmentSourceRoot,
let projectHash = getProjectHash(testProjectPath),
let cachedTarget = findCachedTestTarget(for: targetName,
projectHash: projectHash,
cliVersion: cliVersion,
configHash: configHash,
cacheDirectory: cacheDirectory,
sourceRoot: config.sourceRoot)
sourceRoot: testSourceRoot)
else { return nil }
return .testTarget(cachedTarget)
}
Expand Down

0 comments on commit e73c911

Please sign in to comment.