diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index 5a4aa0dd..c1a6259c 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -1059,6 +1059,7 @@ A multiline script can be written using the various YAML multiline methods, for ### Run Action - [ ] **executable**: **String** - the name of the target to launch as an executable. Defaults to the first runnable build target in the scheme, or the first build target if a runnable build target is not found - [ ] **customLLDBInit**: **String** - the absolute path to the custom `.lldbinit` file +- [ ] **customWorkingDirectory**: **String** - a path to use as the working directory when launching the executable. ### Test Action diff --git a/Sources/ProjectSpec/Scheme.swift b/Sources/ProjectSpec/Scheme.swift index a83dff58..a19951fe 100644 --- a/Sources/ProjectSpec/Scheme.swift +++ b/Sources/ProjectSpec/Scheme.swift @@ -161,6 +161,7 @@ public struct Scheme: Equatable { public var storeKitConfiguration: String? public var customLLDBInit: String? public var macroExpansion: String? + public var customWorkingDirectory: String? public init( config: String? = nil, @@ -186,7 +187,8 @@ public struct Scheme: Equatable { simulateLocation: SimulateLocation? = nil, storeKitConfiguration: String? = nil, customLLDBInit: String? = nil, - macroExpansion: String? = nil + macroExpansion: String? = nil, + customWorkingDirectory: String? = nil ) { self.config = config self.commandLineArguments = commandLineArguments @@ -211,6 +213,7 @@ public struct Scheme: Equatable { self.storeKitConfiguration = storeKitConfiguration self.customLLDBInit = customLLDBInit self.macroExpansion = macroExpansion + self.customWorkingDirectory = customWorkingDirectory } } @@ -559,6 +562,7 @@ extension Scheme.Run: JSONObjectConvertible { } customLLDBInit = jsonDictionary.json(atKeyPath: "customLLDBInit") macroExpansion = jsonDictionary.json(atKeyPath: "macroExpansion") + customWorkingDirectory = jsonDictionary.json(atKeyPath: "customWorkingDirectory") } } @@ -627,6 +631,9 @@ extension Scheme.Run: JSONEncodable { if let customLLDBInit = customLLDBInit { dict["customLLDBInit"] = customLLDBInit } + if let customWorkingDirectory = customWorkingDirectory { + dict["customWorkingDirectory"] = customWorkingDirectory + } return dict } } diff --git a/Sources/XcodeGenKit/SchemeGenerator.swift b/Sources/XcodeGenKit/SchemeGenerator.swift index aa99923f..c29faac4 100644 --- a/Sources/XcodeGenKit/SchemeGenerator.swift +++ b/Sources/XcodeGenKit/SchemeGenerator.swift @@ -359,6 +359,8 @@ public class SchemeGenerator { selectedDebuggerIdentifier: selectedDebuggerIdentifier(for: schemeTarget, run: scheme.run), selectedLauncherIdentifier: selectedLauncherIdentifier(for: schemeTarget, run: scheme.run), askForAppToLaunch: scheme.run?.askForAppToLaunch, + customWorkingDirectory: scheme.run?.customWorkingDirectory, + useCustomWorkingDirectory: scheme.run?.customWorkingDirectory != nil, allowLocationSimulation: allowLocationSimulation, locationScenarioReference: locationScenarioReference, enableGPUFrameCaptureMode: scheme.run?.enableGPUFrameCaptureMode ?? XCScheme.LaunchAction.defaultGPUFrameCaptureMode, diff --git a/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift b/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift index edad2183..d876b3f8 100644 --- a/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift @@ -53,7 +53,7 @@ class SchemeGeneratorTests: XCTestCase { let scheme = try Scheme( name: "MyScheme", build: Scheme.Build(targets: [buildTarget], preActions: [preAction]), - run: Scheme.Run(config: "Debug", enableGPUFrameCaptureMode: .metal, askForAppToLaunch: true, launchAutomaticallySubstyle: "2", simulateLocation: simulateLocation, storeKitConfiguration: storeKitConfiguration, customLLDBInit: "/sample/.lldbinit"), + run: Scheme.Run(config: "Debug", enableGPUFrameCaptureMode: .metal, askForAppToLaunch: true, launchAutomaticallySubstyle: "2", simulateLocation: simulateLocation, storeKitConfiguration: storeKitConfiguration, customLLDBInit: "/sample/.lldbinit", customWorkingDirectory: "/test"), test: Scheme.Test(config: "Debug", targets: [ Scheme.Test.TestTarget(targetReference: TestableTargetReference(framework.name), location: "test.gpx"), Scheme.Test.TestTarget(targetReference: TestableTargetReference(framework.name), location: "New York, NY, USA") @@ -114,7 +114,10 @@ class SchemeGeneratorTests: XCTestCase { try expect(xcscheme.launchAction?.enableGPUFrameCaptureMode) == .metal try expect(xcscheme.testAction?.customLLDBInitFile) == "/test/.lldbinit" try expect(xcscheme.testAction?.systemAttachmentLifetime).to.beNil() - + + try expect(xcscheme.launchAction?.useCustomWorkingDirectory) == true + try expect(xcscheme.launchAction?.customWorkingDirectory) == "/test" + try expect(xcscheme.testAction?.testables[0].locationScenarioReference?.referenceType) == "0" try expect(xcscheme.testAction?.testables[0].locationScenarioReference?.identifier) == "../test.gpx"