Repository navigation
Preserve Xcode per-file flags and Run Scripts, drop dead template src refs - #712
Merged
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
1. Fix
src/*template file referencesThe
osx/ios/tvOS/macostemplates ship hardcodedPBXFileReferenceentries forsrc/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
mainkeeps 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)generateUUIDreturns a new random UUID per call, so every regen creates freshPBXBuildFileentries with nosettings. Any-fno-objc-arcthe user set on an.mmfile (orPublic/Privateon 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 everyPBXShellScriptBuildPhasenowrestoreShellScriptPhases— 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
ofLogWarningnaming it, not silently.GUI:
0.123.0 -> 0.124.0CLI:
0.128.0 -> 0.129.0