]> git.saurik.com Git - wxWidgets.git/blob - build/osx/fix_xcode_ids.py
23dbe250dd0315b8dcab0e9428de7ae67d8596fa
[wxWidgets.git] / build / osx / fix_xcode_ids.py
1 #!/usr/bin/python
2
3 ###############################################################################
4 # Name: build/osx/fix_xcode_ids.py
5 # Author: Dimitri Schoolwerth
6 # Created: 2010-09-08
7 # RCS-Id: $Id$
8 # Copyright: (c) 2010 wxWidgets team
9 # Licence: wxWindows licence
10 ###############################################################################
11
12 import sys
13 import re
14
15 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"
16 Usage: fix_xcode_ids xcode_proj_dir"""
17
18 if len(sys.argv) < 2:
19 print USAGE
20 sys.exit(1)
21
22 projectFile = sys.argv[1] + "/project.pbxproj"
23
24 fin = open(projectFile, "r")
25 strIn = fin.read()
26 fin.close()
27
28
29 # Xcode identifiers (IDs) consist of 24 hexadecimal digits
30 idMask = "[A-Fa-f0-9]{24}"
31
32 # key = original ID found in project
33 # value = ID it will be replaced by
34 idDict = {}
35
36 # some of the strings to match to find definitions of Xcode IDs:
37
38 # from PBXBuildFile section:
39 # 0123456789ABCDEF01234567 /* filename.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEDCBA9876543210FEDCBA98 /* filename.cpp */; };
40
41 # from PBXFileReference section:
42 # FEDCBA9876543210FEDCBA98 /* filename.cpp */ = {isa = PBXFileReference; lastKnownFileType = file; name = any.cpp; path = ../../src/common/filename.cpp; sourceTree = "<group>"; };
43
44 # from remaining sections:
45 # 890123456789ABCDEF012345 /* Name */ = {
46
47 # Capture the first comment between /* and */ (file/section name) as a group
48 rc = re.compile("\s+(" + idMask + ") /\* (.+) \*/ = {.*$", re.MULTILINE)
49 dict = rc.findall(strIn)
50
51 # convert a name to an identifier for Xcode
52 def toUuid(name):
53 from uuid import uuid3, UUID
54 return uuid3(UUID("349f853c-91f8-4eba-b9b9-5e9f882e693c"), name).hex[:24].upper()
55
56 for s in dict:
57 # s[0] is the original ID, s[1] is the name
58 newId = toUuid(s[1])
59 # Some names can appear twice or even more (depending on number of
60 # targets), make them unique
61 while newId in idDict.values() :
62 # [2:-1] to skip prepended 0x and trailing L
63 newId = hex(int(newId, 16) + 1)[2:-1].upper()
64
65 assert(not s[0] in idDict)
66 idDict[s[0]] = newId
67
68
69 # replace all found identifiers with the new ones
70 def repl(match):
71 return idDict[match.group(0)]
72
73 strOut = re.sub(idMask, repl, strIn)
74
75 fout = open(projectFile, "w")
76 fout.write(strOut)
77 fout.close()