Skip to content

Keep shared file elements under their first parent group - #1672

Merged
yonaskolb merged 4 commits into
yonaskolb:masterfrom
blastmann:fix/1663-first-parent-group
Nov 19, 2026
Merged

yonaskolb merged 4 commits into
yonaskolb:masterfrom
blastmann:fix/1663-first-parent-group

Conversation

@blastmann

Copy link
Copy Markdown
Contributor

Summary

When targets reference the same synced folder or file under different custom groups, the generated project can attach the same file element to multiple parents, which Xcode rejects. Keep each element under its first navigator parent while preserving target membership.

Add regression coverage for a shared synced folder and a shared ordinary file with different custom groups.

Fixes #1663

Validation

  • swift test --filter SourceGeneratorTests and swift test, including the TestProject fixture.
  • Generated the issue's original YAML before and after the change: before, Xcode 27.2 rejected the project because Sources/Shared belonged to both groups; after, only GroupA contains the shared root group and both targets reference the same object. xcodebuild -list succeeds.
  • Built an iOS Simulator app based on the repro after adding an app entry point, and built both targets in a separate shared ordinary-file repro.
  • The reporter also opened their local project using the fix and confirmed it opened without errors.
  • Cherry-picked the two commits onto upstream master d212e4de without conflicts and ran the full swift test suite there.

Tested with Xcode 27.2 / Swift 6.4.2 on Apple Silicon. Xcode 26 was not tested.

@yonaskolb yonaskolb left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, and for the thorough validation. The approach looks good and fixes the #1663 repro (also checked nested custom groups and type: group sources).

One behaviour change to address before merging: with createIntermediateGroups: true, a type: group source with a custom group: now ends up only under the intermediate group, so the group: is ignored, even with a single target:

options:
  createIntermediateGroups: true
targets:
  App:
    type: application
    platform: iOS
    sources:
      - path: Sources/Shared
        group: GroupA

getGroupSources creates intermediate groups for the base group before createParentGroups runs, so the intermediate Sources group becomes the first parent. Skipping intermediate groups for the base group when it has a custom parent (around if createIntermediateGroups { createIntermediaGroups(for: group, at: path) }) should keep it under GroupA. A test for this would be great.

Optional, if you're up for it: when one target puts a synced folder under group: GroupA and another target lists the same folder with no group:, it still ends up in both the main group and GroupA, because the top-level rootGroups.insert paths bypass getGroup. Happy to take that as a follow-up instead.


Generated by Claude Code

…yonaskolb#1663)

With createIntermediateGroups, a group source with a custom `group:` was
first attached to its intermediate parent groups, so first-parent-wins
dropped the custom group. Skip intermediate groups for sources under a
custom parent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01237XKrCX47eL6yP9FR5D1m
@yonaskolb
yonaskolb merged commit 76ad6da into yonaskolb:master Nov 19, 2026
8 checks passed
yonaskolb pushed a commit that referenced this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PBXFileSystemSynchronizedRootGroup is added to multiple parent groups when a synced folder is shared by several targets with different custom groups

3 participants