From 59719014c53a3c0b5609165cedf35e711151dc8f Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Wed, 8 Sep 2010 17:11:15 +0000 Subject: [PATCH] Make Xcode identifiers in generated project files be the same after each run. From the AppleScript that composes the Xcode projects call a Python script that bases the identifiers on an associated name instead of being random each run like Xcode does. After the Python script reopen the project again in Xcode to have the identifiers sorted (Xcode wants them to be), resulting in the project.pbxproj file being completely different inside but in the IDE the order of files still will be the same. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65478 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- build/osx/fix_xcode_ids.py | 78 ++++++++++++++++++++++++++++++ build/osx/makeprojects.applescript | 8 +++ 2 files changed, 86 insertions(+) create mode 100755 build/osx/fix_xcode_ids.py diff --git a/build/osx/fix_xcode_ids.py b/build/osx/fix_xcode_ids.py new file mode 100755 index 0000000000..0bbfad9ba4 --- /dev/null +++ b/build/osx/fix_xcode_ids.py @@ -0,0 +1,78 @@ +#!/usr/bin/python + +############################################################################### +# Name: build/osx/fix_xcode_ids.py +# Author: Dimitri Schoolwerth +# Created: 2010-09-08 +# RCS-Id: $Id$ +# Copyright: (c) 2010 wxWidgets team +# Licence: wxWindows licence +############################################################################### + +import sys +import re +import uuid + +USAGE = """fix_xcode_ids - Modifies an Xcode project in-place to use the same identifiers (based on name) instead of being different on each regeneration" +Usage: fix_xcode_ids xcode_proj_dir""" + +if len(sys.argv) < 2: + print USAGE + sys.exit(1) + +projectFile = sys.argv[1] + "/project.pbxproj" + +fin = open(projectFile, "r") +strIn = fin.read() +fin.close() + + +# Xcode identifiers (IDs) consist of 24 hexadecimal digits +idMask = "[A-Fa-f0-9]{24}" + +# key = original ID found in project +# value = ID it will be replaced by +idDict = {} + +# some of the strings to match to find definitions of Xcode IDs: + +# from PBXBuildFile section: +# 0123456789ABCDEF01234567 /* filename.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEDCBA9876543210FEDCBA98 /* filename.cpp */; }; + +# from PBXFileReference section: +# FEDCBA9876543210FEDCBA98 /* filename.cpp */ = {isa = PBXFileReference; lastKnownFileType = file; name = any.cpp; path = ../../src/common/filename.cpp; sourceTree = ""; }; + +# from remaining sections: +# 890123456789ABCDEF012345 /* Name */ = { + +# Capture the first comment between /* and */ (file/section name) as a group +rc = re.compile("\s+(" + idMask + ") /\* (.+) \*/ = {.*$", re.MULTILINE) +dict = rc.findall(strIn) + +# convert a name to an identifier for Xcode +def toUuid(name): + return uuid.uuid3(uuid.NAMESPACE_DNS, name).hex[:24].upper() + +for s in dict: + # s[0] is the original ID, s[1] is the name + newId = toUuid(s[1]) + num = 0 + # Some names can appear twice or even more (depending on number of + # targets), make them unique + while newId in idDict.values() : + num = num + 1 + newId = toUuid(s[1] + str(num)) + + assert(not s[0] in idDict) + idDict[s[0]] = newId + + +# replace all found identifiers with the new ones +def repl(match): + return idDict[match.group(0)] + +strOut = re.sub(idMask, repl, strIn) + +fout = open(projectFile, "w") +fout.write(strOut) +fout.close() diff --git a/build/osx/makeprojects.applescript b/build/osx/makeprojects.applescript index 98162bafa1..fc1c2972ea 100644 --- a/build/osx/makeprojects.applescript +++ b/build/osx/makeprojects.applescript @@ -184,6 +184,14 @@ on populateProject(theProject) tell application "Xcode" quit end tell + do shell script (osxBuildFolder as text) & "fix_xcode_ids.py \"" & (POSIX path of projectFile as Unicode text) & "\"" + -- reopen again to let Xcode sort identifiers + tell application "Xcode" + open projectFile + end tell + tell application "Xcode" + quit + end tell end populateProject on makeProject(theProject) -- 2.47.2