Skip to content

Commit 2772ecb

Browse files
EvanBaconclaude
andauthored
Add XCSharedData support for breakpoints and workspace settings (#39)
Implements unified access to xcshareddata directories containing: - Breakpoints (Breakpoints_v2.xcbkptlist) - file, symbolic, exception breakpoints - Workspace settings (WorkspaceSettings.xcsettings) - build system, derived data, previews - Integration with existing scheme support New modules: - src/breakpoints/ - XML parser/writer for breakpoint lists - src/settings/ - Plist parser/writer for workspace settings - src/api/XCSharedData.ts - High-level API unifying schemes, breakpoints, settings Adds getSharedData() method to XcodeProject and XCWorkspace for easy access. Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e7d59cd commit 2772ecb

19 files changed

Lines changed: 2117 additions & 6 deletions

README.md

Lines changed: 110 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,111 @@ PRODUCT_BUNDLE_IDENTIFIER = $(BUNDLE_ID_PREFIX).$(PRODUCT_NAME:lower)
355355
OTHER_LDFLAGS = $(inherited) -framework UIKit
356356
```
357357

358+
## XCSharedData Support
359+
360+
Access and manipulate shared data directories (`xcshareddata`) which contain schemes, breakpoints, and workspace settings that are intended for version control.
361+
362+
### High-level API
363+
364+
```ts
365+
import { XcodeProject, XCSharedData } from "@bacons/xcode";
366+
367+
// Get shared data from a project
368+
const project = XcodeProject.open("/path/to/project.pbxproj");
369+
const sharedData = project.getSharedData();
370+
371+
// Access schemes
372+
const schemes = sharedData.getSchemes();
373+
const appScheme = sharedData.getScheme("App");
374+
375+
// Access breakpoints
376+
if (sharedData.breakpoints) {
377+
console.log(sharedData.breakpoints.breakpoints?.length);
378+
}
379+
380+
// Access workspace settings
381+
if (sharedData.workspaceSettings) {
382+
console.log(sharedData.workspaceSettings.PreviewsEnabled);
383+
}
384+
385+
// Modify and save
386+
sharedData.workspaceSettings = {
387+
PreviewsEnabled: true,
388+
IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded: false,
389+
};
390+
sharedData.save();
391+
```
392+
393+
### Breakpoints API
394+
395+
Parse and build Xcode breakpoint files (`Breakpoints_v2.xcbkptlist`):
396+
397+
```ts
398+
import * as breakpoints from "@bacons/xcode/breakpoints";
399+
import fs from "fs";
400+
401+
// Parse breakpoint file
402+
const xml = fs.readFileSync(
403+
"/path/to/xcshareddata/xcdebugger/Breakpoints_v2.xcbkptlist",
404+
"utf-8",
405+
);
406+
const list = breakpoints.parse(xml);
407+
408+
// Access breakpoints
409+
for (const bp of list.breakpoints ?? []) {
410+
console.log(bp.breakpointExtensionID); // "Xcode.Breakpoint.FileBreakpoint"
411+
console.log(bp.breakpointContent?.filePath);
412+
console.log(bp.breakpointContent?.startingLineNumber);
413+
}
414+
415+
// Add a new breakpoint
416+
list.breakpoints?.push({
417+
breakpointExtensionID: "Xcode.Breakpoint.FileBreakpoint",
418+
breakpointContent: {
419+
uuid: "new-uuid",
420+
shouldBeEnabled: true,
421+
filePath: "MyApp/ViewController.swift",
422+
startingLineNumber: "42",
423+
endingLineNumber: "42",
424+
actions: [
425+
{
426+
actionExtensionID: "Xcode.BreakpointAction.DebuggerCommand",
427+
actionContent: { consoleCommand: "po self" },
428+
},
429+
],
430+
},
431+
});
432+
433+
// Serialize back to XML
434+
const outputXml = breakpoints.build(list);
435+
```
436+
437+
### Workspace Settings API
438+
439+
Parse and build workspace settings files (`WorkspaceSettings.xcsettings`):
440+
441+
```ts
442+
import * as settings from "@bacons/xcode/settings";
443+
import fs from "fs";
444+
445+
// Parse settings file
446+
const plist = fs.readFileSync(
447+
"/path/to/xcshareddata/WorkspaceSettings.xcsettings",
448+
"utf-8",
449+
);
450+
const config = settings.parse(plist);
451+
452+
console.log(config.BuildSystemType); // "Original" or "New"
453+
console.log(config.PreviewsEnabled); // true/false
454+
455+
// Modify and save
456+
config.PreviewsEnabled = true;
457+
config.IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded = false;
458+
459+
const outputPlist = settings.build(config);
460+
fs.writeFileSync("/path/to/WorkspaceSettings.xcsettings", outputPlist);
461+
```
462+
358463
## Solution
359464

360465
- Uses a hand-optimized single-pass parser that is 11x faster than the legacy `xcode` package (which uses PEG.js).
@@ -382,15 +487,14 @@ We support the following types: `Object`, `Array`, `Data`, `String`. Notably, we
382487
- [x] xcscheme support.
383488
- [x] Benchmarks (`bun run bench`).
384489
- [x] xcworkspace support.
490+
- [x] **XCConfig** Parsing: `.xcconfig` file parsing with `#include` support and build settings flattening.
491+
- [x] **XCSharedData**: Shared project data directory (schemes, breakpoints, workspace settings).
492+
- [x] **XCSchemeManagement**: Scheme ordering, visibility, and management plist.
493+
- [x] **WorkspaceSettings**: (`xcshareddata/WorkspaceSettings.xcsettings`) Derived data location, build system version, auto-create schemes setting.
494+
- [x] **XCBreakpointList**: (`xcshareddata/xcdebugger/Breakpoints_v2.xcbkptlist`) Shared debugger breakpoints (file, symbolic, exception breakpoints).
385495
- [ ] Create robust xcode projects from scratch.
386496
- [ ] Skills.
387497
- [ ] Import from other tools.
388-
- [x] **XCConfig** Parsing: `.xcconfig` file parsing with `#include` support and build settings flattening.
389-
- [ ] **XCSharedData**: Shared project data directory (schemes, breakpoints, workspace settings).
390-
- [ ] **XCSchemeManagement**: Scheme ordering, visibility, and management plist. Controls which schemes appear and in what order in Xcode.
391-
- [ ] **XCUserData**: User-specific data (breakpoints, UI state). Useful for tooling that manages user preferences.
392-
- [ ] **WorkspaceSettings**: (`xcshareddata/WorkspaceSettings.xcsettings`) Derived data location, build system version, auto-create schemes setting.
393-
- [ ] **XCBreakpointList**: (`xcshareddata/xcdebugger/Breakpoints_v2.xcbkptlist`) Shared debugger breakpoints (file, symbolic, exception breakpoints)
394498
- [ ] **XCUserData**: (`xcuserdata/<user>.xcuserdatad/`) Per-user schemes, breakpoints, UI state.
395499
- [ ] **IDEWorkspaceChecks**: (`xcshareddata/IDEWorkspaceChecks.plist`) "Trust this project" flag that suppresses Xcode warning.
396500

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
"./xcconfig": {
3737
"types": "./build/xcconfig/index.d.ts",
3838
"default": "./build/xcconfig/index.js"
39+
},
40+
"./breakpoints": {
41+
"types": "./build/breakpoints/index.d.ts",
42+
"default": "./build/breakpoints/index.js"
43+
},
44+
"./settings": {
45+
"types": "./build/settings/index.d.ts",
46+
"default": "./build/settings/index.js"
3947
}
4048
},
4149
"files": [

0 commit comments

Comments
 (0)