diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index 83166e9c4..071154125 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -1054,6 +1054,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 e417fcf0f..de8cc5126 100644 --- a/Sources/ProjectSpec/Scheme.swift +++ b/Sources/ProjectSpec/Scheme.swift @@ -153,6 +153,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, @@ -174,7 +175,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 @@ -195,6 +197,7 @@ public struct Scheme: Equatable { self.storeKitConfiguration = storeKitConfiguration self.customLLDBInit = customLLDBInit self.macroExpansion = macroExpansion + self.customWorkingDirectory = customWorkingDirectory } } @@ -523,6 +526,7 @@ extension Scheme.Run: JSONObjectConvertible { } customLLDBInit = jsonDictionary.json(atKeyPath: "customLLDBInit") macroExpansion = jsonDictionary.json(atKeyPath: "macroExpansion") + customWorkingDirectory = jsonDictionary.json(atKeyPath: "customWorkingDirectory") } } @@ -575,6 +579,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 69ad80faf..5779b72c9 100644 --- a/Sources/XcodeGenKit/SchemeGenerator.swift +++ b/Sources/XcodeGenKit/SchemeGenerator.swift @@ -355,6 +355,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 edad2183b..d876b3f8b 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"