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
This commit is contained in:
Dimitri Schoolwerth 2010-09-08 17:11:15 +00:00
parent 5eda55f775
commit 59719014c5
2 changed files with 86 additions and 0 deletions

78
build/osx/fix_xcode_ids.py Executable file
View File

@ -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 = "<group>"; };
# 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()

View File

@ -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)