Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Add test bundle name to lock file name (typealiased#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter-Nagy authored Feb 23, 2021
1 parent 064f866 commit c8cd317
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Sources/MockingbirdCli/Interface/Generator+Pipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extension Generator {
})
}
private let mockedTypesResult: FindMockedTypesOperation.Result?
private let environmentTargetName: String?

init(inputTarget: TargetType,
outputPath: Path,
Expand All @@ -31,6 +32,7 @@ extension Generator {
environment: @escaping () -> [String: Any]) throws {
self.inputTarget = inputTarget
self.outputPath = outputPath
self.environmentTargetName = config.environmentTargetName

// Extract sources.
let extractSources: ExtractSourcesAbstractOperation
Expand Down Expand Up @@ -173,7 +175,7 @@ extension Generator {
}

let data = try JSONEncoder().encode(target)
let filePath = cacheDirectory.targetLockFilePath(for: target.name)
let filePath = cacheDirectory.targetLockFilePath(for: target.name, testBundle: self.environmentTargetName)
try filePath.write(data)
log("Cached pipeline input target \(inputTarget.name.singleQuoted) to \(filePath.absolute())")
}
Expand All @@ -185,7 +187,7 @@ extension Generator {
configHash: String,
cacheDirectory: Path,
sourceRoot: Path) -> SourceTarget? {
let filePath = cacheDirectory.targetLockFilePath(for: targetName)
let filePath = cacheDirectory.targetLockFilePath(for: targetName, testBundle: self.config.environmentTargetName)

guard filePath.exists else {
log("No cached source target metadata exists for \(targetName.singleQuoted) at \(filePath.absolute())")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extension Generator {
let operations: [BasicOperation]
let testTarget: TargetType
let findMockedTypesOperation: FindMockedTypesOperation
private let environmentTargetName: String

init?(config: Configuration,
getCachedTarget: (String) -> TargetType?,
Expand All @@ -25,6 +26,7 @@ extension Generator {
let environmentSourceRoot = config.environmentSourceRoot,
let environmentTargetName = config.environmentTargetName
else { return nil }
self.environmentTargetName = environmentTargetName

let isTestTarget: (TargetType) -> Bool = { target in
switch target {
Expand Down Expand Up @@ -144,7 +146,7 @@ extension Generator {
}

let data = try JSONEncoder().encode(target)
let filePath = cacheDirectory.targetLockFilePath(for: target.name)
let filePath = cacheDirectory.targetLockFilePath(for: target.name, testBundle: environmentTargetName)
try filePath.write(data)
log("Cached pipeline test target \(target.name.singleQuoted) to \(filePath.absolute())")
}
Expand All @@ -156,7 +158,7 @@ extension Generator {
configHash: String,
cacheDirectory: Path,
sourceRoot: Path) -> TestTarget? {
let filePath = cacheDirectory.targetLockFilePath(for: targetName)
let filePath = cacheDirectory.targetLockFilePath(for: targetName, testBundle: self.config.environmentTargetName)

guard filePath.exists else {
log("No cached test target metadata exists for \(targetName.singleQuoted) at \(filePath.absolute())")
Expand Down
10 changes: 8 additions & 2 deletions Sources/MockingbirdCli/Interface/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,14 @@ extension Path {
return absolute() + Path("MockingbirdMocks")
}

func targetLockFilePath(for targetName: String) -> Path {
return self + "\(targetName).lock"
func targetLockFilePath(for targetName: String, testBundle: String?) -> Path {
var lockFileName: String
if let testBundle = testBundle {
lockFileName = "\(targetName)-\(testBundle).lock"
} else {
lockFileName = "\(targetName).lock"
}
return self + lockFileName
}
}

Expand Down

0 comments on commit c8cd317

Please sign in to comment.