Skip to content

Preserve Xcode per-file flags and Run Scripts, drop dead template src refs - #712

Merged
danoli3 merged 1 commit into
masterfrom
fix/xcode-preserve-user-customizations
Nov 18, 2026
Merged

danoli3 merged 1 commit into
masterfrom
fix/xcode-preserve-user-customizations

Conversation

@danoli3

@danoli3 danoli3 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

1. Fix src/* template file references

The osx / ios / tvOS / macos templates ship hardcoded PBXFileReference entries for src/main.{cpp,mm}, src/ofApp.{cpp,mm,h}

Conservative at depth 1 (src/<basename>):
the template placeholder is only removed when a file with the same basename exists elsewhere under src/.

So a project that genuinely has no main keeps the placeholder as a visible signal rather than silently losing its entry point.

2. Fixes Per-file COMPILER_FLAGS / ATTRIBUTES (e.g. -fno-objc-arc)

generateUUID returns a new random UUID per call, so every regen creates fresh PBXBuildFile entries with no settings. Any -fno-objc-arc the user set on an .mm file (or Public/Private on a header, or any other per-file compiler flag) disappears.

3. Custom Run Script build phases

Scripts added via Editor / Add Build Phase / New Run Script Phase are wiped on every regen.

  • snapshotShellScriptPhases — records every PBXShellScriptBuildPhase now

  • restoreShellScriptPhases — re-attaches each snapshot phase to the fresh project's target matched by name, skipping any whose signature is already present so addon-added scripts (addAfterRule) and template duplicates don't double up. Handles multi-target templates (macos has <projectName> + <projectName>macOS).
    -If a target was renamed between runs the phase is dropped with a ofLogWarning naming it, not silently.

  • GUI: 0.123.0 -> 0.124.0

  • CLI: 0.128.0 -> 0.129.0

… refs

Three regressions users hit when re-running the project generator on an
existing Apple project — all stem from createProjectFile overwriting the
.pbxproj with a fresh template copy.

- Dead template src/* references: the osx / ios / tvOS / macos templates
  ship hardcoded PBXFileReference entries for src/main.{cpp,mm},
  src/ofApp.{cpp,mm,h}. When a project (e.g. ofxMultiplatform) keeps
  those files in a subfolder like src/Apps/ or src/iOS/, the real files
  are added correctly via addSrc but the template entries remain as red
  dead links. removeDeadSrcReferences runs right after the pbxproj is
  parsed in saveProjectFile and drops any PBXFileReference under src/
  whose file is missing on disk, along with its PBXBuildFile and every
  reference in PBXGroup.children / *BuildPhase.files. Scoped to depth 1
  under src/: a top-level placeholder (src/<basename>) is only removed
  when a same-named file exists elsewhere under src/ — so a project
  with no main at all keeps its placeholder as a visible signal rather
  than silently losing the entry point. Deeper dead refs are prior
  regen leftovers from deleted files, removed unconditionally.

- Per-file COMPILER_FLAGS and ATTRIBUTES (e.g. -fno-objc-arc on .mm
  files, Public/Private header visibility): generateUUID returns a
  fresh UUID per call, so every regen creates new PBXBuildFile entries
  with no settings. snapshotFileSettings walks appleProject (the
  pre-regen pbxproj that readAppleSettings already loads) and records
  each PBXBuildFile.settings keyed by the resolved file path.
  restoreFileSettings re-applies them on the fresh PBXBuildFile
  entries by resolving the new fileRef's path and merging the snapshot
  onto whatever the generator set (user flags win; generator-set
  ATTRIBUTES like CodeSignOnCopy are kept).

- Custom Run Script build phases added via Editor → Add Build Phase →
  New Run Script Phase: snapshotShellScriptPhases records every
  PBXShellScriptBuildPhase from appleProject whose (name, shellScript)
  signature doesn't match one shipped by the template, tagging it with
  its target name. restoreShellScriptPhases re-attaches each to the
  target matched by name in the fresh project, skipping any whose
  signature is already present (addon-added scripts re-added by
  addAfterRule, or template duplicates). Works for single-target
  templates (osx, ios, tvOS) and the multi-target macos template; a
  target renamed between runs drops its scripts with ofLogWarning
  naming each, rather than silently losing them.

Shared helpers parentGroupMap and resolveRefPath (anon namespace) walk
<group>-relative PBXFileReference paths back to a SOURCE_ROOT-rooted
path, so both the osx/ios pattern (path = src/main.mm, sourceTree =
SOURCE_ROOT) and the tvOS pattern (path = main.mm inside a src group)
resolve consistently.
@danoli3
danoli3 merged commit eb5b179 into master Nov 18, 2026
11 checks passed
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.

1 participant