Skip to content

Fix file elements being added to more than one group - #1652

Open
Ckitakishi wants to merge 3 commits into
yonaskolb:masterfrom
Ckitakishi:fix-multiple-parent-groups
Open

Ckitakishi wants to merge 3 commits into
yonaskolb:masterfrom
Ckitakishi:fix-multiple-parent-groups

Conversation

@Ckitakishi

Copy link
Copy Markdown
Contributor

Summary

XcodeGen could add the same file element to both the main group and another group, producing a malformed project that Xcode 27.2 refuses to open.

getGroup now removes an element from rootGroups before attaching it to another group. A top-level group's path is relative to the project, so it is also rewritten relative to its new parent.

This also resolves the malformed structure reported in #405.

Behavior change

Previously, specs whose source directory is the spec directory itself (sources: [../Module]) showed their subdirectory groups at the project root. They now appear under the module group, one level deeper, which is the structure the spec describes. File references and build files are unchanged.

The TestProject fixture changes for the same reason: Folder (type: folder, group: CustomGroup) was a member of both CustomGroup and the main group, and now only lives in CustomGroup.

Testing

Two regression cases in SourceGeneratorTests fail on master:

  • a source pointing at the spec directory
  • a directory reached first through a file source, then through a directory source

A third case ensures that a skipped subdirectory populated by a later source remains reachable.

expectSingleParents also runs while generating the fixture projects, so the invariant is checked across all fixtures. swift test passes.

Fixes #1651.

Ckitakishi and others added 2 commits September 18, 2026 00:48
The first two tests reproduce multiple parents: a source pointing at the
spec directory, and a directory reached first through a file source. The
third preserves a skipped subdirectory at the project root when a later
source populates it. `expectSingleParents` lives in TestSupport so the
fixtures are covered too.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`getGroup` infers "top level" from the shape of the path, which stops
holding once the same directory is also reached as a child. Drop anything
that gets attached to a group from `rootGroups`, and rewrite its path,
project relative until now, to be relative to the new parent.

The TestProject fixture loses the duplicate `Folder` entry in the main group.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Ckitakishi added a commit to Ckitakishi/XcodeGen that referenced this pull request Sep 17, 2026
@Ckitakishi
Ckitakishi force-pushed the fix-multiple-parent-groups branch from 65dbfb7 to e2025b1 Compare September 18, 2026 00:33
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.

Subdirectory PBXGroup is also added to the main group, so Xcode 27.2 cannot open the project

1 participant