3 ###############################################################################
4 # Name: build/osx/fix_xcode_ids.py
5 # Author: Dimitri Schoolwerth
8 # Copyright: (c) 2010 wxWidgets team
9 # Licence: wxWindows licence
10 ###############################################################################
16 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"
17 Usage: fix_xcode_ids xcode_proj_dir"""
23 projectFile
= sys
.argv
[1] + "/project.pbxproj"
25 fin
= open(projectFile
, "r")
30 # Xcode identifiers (IDs) consist of 24 hexadecimal digits
31 idMask
= "[A-Fa-f0-9]{24}"
33 # key = original ID found in project
34 # value = ID it will be replaced by
37 # some of the strings to match to find definitions of Xcode IDs:
39 # from PBXBuildFile section:
40 # 0123456789ABCDEF01234567 /* filename.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEDCBA9876543210FEDCBA98 /* filename.cpp */; };
42 # from PBXFileReference section:
43 # FEDCBA9876543210FEDCBA98 /* filename.cpp */ = {isa = PBXFileReference; lastKnownFileType = file; name = any.cpp; path = ../../src/common/filename.cpp; sourceTree = "<group>"; };
45 # from remaining sections:
46 # 890123456789ABCDEF012345 /* Name */ = {
48 # Capture the first comment between /* and */ (file/section name) as a group
49 rc
= re
.compile("\s+(" + idMask
+ ") /\* (.+) \*/ = {.*$", re
.MULTILINE
)
50 dict = rc
.findall(strIn
)
52 # convert a name to an identifier for Xcode
54 return uuid
.uuid3(uuid
.NAMESPACE_DNS
, name
).hex[:24].upper()
57 # s[0] is the original ID, s[1] is the name
60 # Some names can appear twice or even more (depending on number of
61 # targets), make them unique
62 while newId
in idDict
.values() :
64 newId
= toUuid(s
[1] + str(num
))
66 assert(not s
[0] in idDict
)
70 # replace all found identifiers with the new ones
72 return idDict
[match
.group(0)]
74 strOut
= re
.sub(idMask
, repl
, strIn
)
76 fout
= open(projectFile
, "w")