From e73c911abe9869107eb14dd6adff4a8bfb89f7ff Mon Sep 17 00:00:00 2001 From: Andrew Chang Date: Thu, 23 Dec 2021 16:42:17 -1000 Subject: [PATCH] Fix generator caching for multi-project setups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Sources/MockingbirdCli/Interface/Handlers/Generator.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/MockingbirdCli/Interface/Handlers/Generator.swift b/Sources/MockingbirdCli/Interface/Handlers/Generator.swift index 889f5b10..ea3519e1 100644 --- a/Sources/MockingbirdCli/Interface/Handlers/Generator.swift +++ b/Sources/MockingbirdCli/Interface/Handlers/Generator.swift @@ -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 @@ -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) }