Skip to content

Commit 3251691

Browse files
Feature: Custom Working Directory (#1543)
* Added `customWorkingDirectory` and `useCustomWorkingDirectory` properties to `Scheme.Run` * Use new `customWorkingDirectory` and `useCustomWorkingDirectory` when generating `XCScheme.LaunchAction` * Updated ProjectSpec.md to document new `customWorkingDirectory` and `useCustomWorkingDirectory` properties * Fix for not setting customWorkingDirectory in the toJSONValue function * Added test to make sure usCustomWorkingDirectory value is true when the customWorkingDirectory is set to non nil * Change to infer the value of SchemaGenerator.LaunchAction.useCustomWorkingDirectory based on the value of Schema.Run.customWorkingDirectory * Removed useCustomWorkingDirectory from the project spec now that it is no longer user defined.
1 parent a1c7544 commit 3251691

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

Docs/ProjectSpec.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ A multiline script can be written using the various YAML multiline methods, for
10591059
### Run Action
10601060
- [ ] **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
10611061
- [ ] **customLLDBInit**: **String** - the absolute path to the custom `.lldbinit` file
1062+
- [ ] **customWorkingDirectory**: **String** - a path to use as the working directory when launching the executable.
10621063

10631064
### Test Action
10641065

Sources/ProjectSpec/Scheme.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public struct Scheme: Equatable {
161161
public var storeKitConfiguration: String?
162162
public var customLLDBInit: String?
163163
public var macroExpansion: String?
164+
public var customWorkingDirectory: String?
164165

165166
public init(
166167
config: String? = nil,
@@ -186,7 +187,8 @@ public struct Scheme: Equatable {
186187
simulateLocation: SimulateLocation? = nil,
187188
storeKitConfiguration: String? = nil,
188189
customLLDBInit: String? = nil,
189-
macroExpansion: String? = nil
190+
macroExpansion: String? = nil,
191+
customWorkingDirectory: String? = nil
190192
) {
191193
self.config = config
192194
self.commandLineArguments = commandLineArguments
@@ -211,6 +213,7 @@ public struct Scheme: Equatable {
211213
self.storeKitConfiguration = storeKitConfiguration
212214
self.customLLDBInit = customLLDBInit
213215
self.macroExpansion = macroExpansion
216+
self.customWorkingDirectory = customWorkingDirectory
214217
}
215218
}
216219

@@ -559,6 +562,7 @@ extension Scheme.Run: JSONObjectConvertible {
559562
}
560563
customLLDBInit = jsonDictionary.json(atKeyPath: "customLLDBInit")
561564
macroExpansion = jsonDictionary.json(atKeyPath: "macroExpansion")
565+
customWorkingDirectory = jsonDictionary.json(atKeyPath: "customWorkingDirectory")
562566
}
563567
}
564568

@@ -627,6 +631,9 @@ extension Scheme.Run: JSONEncodable {
627631
if let customLLDBInit = customLLDBInit {
628632
dict["customLLDBInit"] = customLLDBInit
629633
}
634+
if let customWorkingDirectory = customWorkingDirectory {
635+
dict["customWorkingDirectory"] = customWorkingDirectory
636+
}
630637
return dict
631638
}
632639
}

Sources/XcodeGenKit/SchemeGenerator.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ public class SchemeGenerator {
359359
selectedDebuggerIdentifier: selectedDebuggerIdentifier(for: schemeTarget, run: scheme.run),
360360
selectedLauncherIdentifier: selectedLauncherIdentifier(for: schemeTarget, run: scheme.run),
361361
askForAppToLaunch: scheme.run?.askForAppToLaunch,
362+
customWorkingDirectory: scheme.run?.customWorkingDirectory,
363+
useCustomWorkingDirectory: scheme.run?.customWorkingDirectory != nil,
362364
allowLocationSimulation: allowLocationSimulation,
363365
locationScenarioReference: locationScenarioReference,
364366
enableGPUFrameCaptureMode: scheme.run?.enableGPUFrameCaptureMode ?? XCScheme.LaunchAction.defaultGPUFrameCaptureMode,

Tests/XcodeGenKitTests/SchemeGeneratorTests.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class SchemeGeneratorTests: XCTestCase {
5353
let scheme = try Scheme(
5454
name: "MyScheme",
5555
build: Scheme.Build(targets: [buildTarget], preActions: [preAction]),
56-
run: Scheme.Run(config: "Debug", enableGPUFrameCaptureMode: .metal, askForAppToLaunch: true, launchAutomaticallySubstyle: "2", simulateLocation: simulateLocation, storeKitConfiguration: storeKitConfiguration, customLLDBInit: "/sample/.lldbinit"),
56+
run: Scheme.Run(config: "Debug", enableGPUFrameCaptureMode: .metal, askForAppToLaunch: true, launchAutomaticallySubstyle: "2", simulateLocation: simulateLocation, storeKitConfiguration: storeKitConfiguration, customLLDBInit: "/sample/.lldbinit", customWorkingDirectory: "/test"),
5757
test: Scheme.Test(config: "Debug", targets: [
5858
Scheme.Test.TestTarget(targetReference: TestableTargetReference(framework.name), location: "test.gpx"),
5959
Scheme.Test.TestTarget(targetReference: TestableTargetReference(framework.name), location: "New York, NY, USA")
@@ -114,7 +114,10 @@ class SchemeGeneratorTests: XCTestCase {
114114
try expect(xcscheme.launchAction?.enableGPUFrameCaptureMode) == .metal
115115
try expect(xcscheme.testAction?.customLLDBInitFile) == "/test/.lldbinit"
116116
try expect(xcscheme.testAction?.systemAttachmentLifetime).to.beNil()
117-
117+
118+
try expect(xcscheme.launchAction?.useCustomWorkingDirectory) == true
119+
try expect(xcscheme.launchAction?.customWorkingDirectory) == "/test"
120+
118121
try expect(xcscheme.testAction?.testables[0].locationScenarioReference?.referenceType) == "0"
119122
try expect(xcscheme.testAction?.testables[0].locationScenarioReference?.identifier) == "../test.gpx"
120123

0 commit comments

Comments
 (0)