Skip to content

Commit

Permalink
Fix configurator relative path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewchang-bird committed Jan 10, 2022
1 parent 2c90c82 commit c9a18a8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
14 changes: 9 additions & 5 deletions Sources/MockingbirdCli/Arguments/InferableArgument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ struct ArgumentContext: Codable {
let environment: [String: String]
let arguments: [String]

static var shared = ArgumentContext(
workingPath: Path(FileManager.default.currentDirectoryPath),
environment: ProcessInfo.processInfo.environment,
arguments: CommandLine.arguments
)
static var shared = ArgumentContext()

init(workingPath: Path = Path(FileManager.default.currentDirectoryPath),
environment: [String: String] = ProcessInfo.processInfo.environment,
arguments: [String] = CommandLine.arguments) {
self.workingPath = workingPath
self.environment = environment
self.arguments = arguments
}
}

protocol InferableArgument {
Expand Down
10 changes: 8 additions & 2 deletions Sources/MockingbirdCli/Commands/Configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,15 @@ extension Mockingbird {
mutating func run() throws {
let start = Date()
let parsedConfigureArguments = try infer()
let parsedGenerateArguments = try parsedConfigureArguments.generateCommand.infer()
let parsedGenerateArguments = try parsedConfigureArguments.generateCommand
.infer(context: ArgumentContext(workingPath: parsedConfigureArguments.project.parent()))

logInfo("🛠 Project: \(parsedConfigureArguments.project.abbreviate())")
if parsedConfigureArguments.sourceProject == parsedConfigureArguments.project {
logInfo("🛠 Project: \(parsedConfigureArguments.project.abbreviate())")
} else {
logInfo("🛠 Test Project: \(parsedConfigureArguments.project.abbreviate())")
logInfo("🛠 Source Project: \(parsedConfigureArguments.sourceProject.abbreviate())")
}
logInfo("🎯 Test Target: \(parsedConfigureArguments.testTarget)")
logInfo("🧰 Supporting sources: \(parsedGenerateArguments.support.abbreviate())")

Expand Down
7 changes: 4 additions & 3 deletions Sources/MockingbirdCli/Commands/Generate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ extension Mockingbird {
}

@discardableResult
nonmutating func infer() throws -> Arguments {
let validProject = try validateRequiredArgument(inferArgument(project), name: "project")
nonmutating func infer(context: ArgumentContext = .shared) throws -> Arguments {
let validProject = try validateRequiredArgument(inferArgument(project, in: context),
name: "project")
let validSrcroot = try validateRequiredArgument(
srcroot ?? DirectoryPath(path: validProject.path.parent()), name: "srcroot")
let validTestBundle = try validateOptionalArgument(inferArgument(testbundle),
let validTestBundle = try validateOptionalArgument(inferArgument(testbundle, in: context),
name: "testbundle")
let validSupportPath = support?.path ?? (validSrcroot.path + "MockingbirdSupport")

Expand Down
3 changes: 2 additions & 1 deletion Sources/MockingbirdCli/Handlers/Installer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ struct Installer {
private func rewriteDerivedDataPath(_ path: Path) throws -> String? {
// It's possible to use a custom derived data path (in addition to a custom build products
// location), but this is very uncommon so we won't try to handle it.
guard path.starts(with: Path("~/Library/Developer/Xcode/DerivedData/")) else {
let derivedDataRootPath = Path("~/Library/Developer/Xcode/DerivedData/").absolute().string
guard path.absolute().string.starts(with: derivedDataRootPath) else {
return nil
}
log("Attempting to rewrite the derived data path \(path.abbreviate())")
Expand Down

0 comments on commit c9a18a8

Please sign in to comment.