forked from appcelerator-archive/tijscore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixup.py
executable file
·156 lines (136 loc) · 3.81 KB
/
fixup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python
#
#
# This is a script that will attempt to fix up filenames
# and symbols inside files to match the Titanium namespace,
# naming conventions, etc so as not to conflict with an
# existing install of KJS
#
import os, shutil, sys, re, datetime
if len(sys.argv) > 1:
root_dir = sys.argv[1]
else:
root_dir = "TiCore"
tokens = [
['JSString','TiString'],
['JavaScriptCore', 'TiCore'],
['JavaScript','Ti'],
['JSRetain','TiRetain'],
['JSRelease','TiRelease'],
['JSObject','TiObject'],
['JSLock','TiLock'],
['JSUnlock','TiUnlock'],
['JSCell','TiCell'],
['JSClass','TiClass'],
['JSStatic','TiStatic'],
['JSContext','TiContext'],
['JSGlobal','TiGlobal'],
['JSValue','TiValue'],
['JSArray','TiArray'],
['JSByte','TiArray'],
['JSFunction','TiFunction'],
['JSProperty','TiProperty'],
['ExecState','TiExcState'],
['JSGlobalData','TiGlobalData'],
['kJS','kTI'],
['JSEvaluate','TiEval'],
['JSCheck','TiCheck'],
['JSGarbage','TiGarbage'],
['JSType','TiType'],
['JSAPI','TiAPI'],
['JSCallback','TiCallback'],
['JSProfile','TiProfile'],
['JSBase','TiBase'],
['JSChar','TiChar'],
['WTFMain','WTIMain'],
]
extensions = (
'.c',
'.cpp',
'.mm',
'.h',
'.pbxproj',
'.exp',
'.xcconfig',
'.sh',
'.make',
'.y',
'.lut.h',
'.py'
)
copyright_ext = (
'.h',
'.cpp',
'.c',
'.mm'
)
#['jsAPIValueWrapper','TiAPIValueWrapper'],
COPYRIGHT_NOW = datetime.date.today().strftime('%Y')
COPYRIGHT = """/**
* Appcelerator Titanium License
* This source code and all modifications done by Appcelerator
* are licensed under the Apache Public License (version 2) and
* are Copyright (c) 2009-%s by Appcelerator, Inc.
*/
""" % COPYRIGHT_NOW
def fix_copyright(ext,content):
if ext in copyright_ext:
if content.find('Appcelerator Titanium License')==-1:
content = COPYRIGHT + content
else:
# update the copyright information if necessary
content = re.sub('Copyright \(c\) 2009\S*', 'Copyright (c) 2009-%s' % COPYRIGHT_NOW, content)
return content
def fix_content(fn):
content = open(fn,'r').read()
if os.path.basename(fn)=='project.pbxproj':
content = content.replace('build/Release/DerivedSources/JavaScriptCore,','"$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/DerivedSources/JavaScriptCore",')
for token in tokens:
content = content.replace(token[0],token[1])
content = content.replace('namespace JSC','namespace TI')
content = content.replace('namespace WTF','namespace WTI')
content = content.replace('using WTF::','using WTI::')
content = content.replace('using JSC::','using TI::')
content = content.replace('using WTFNoncopyable::','using WTINoncopyable::')
content = content.replace('JSC::','TI::')
content = content.replace('WTF::','WTI::')
return content
def fix_filename(fn):
dirname = os.path.dirname(fn)
path = os.path.basename(fn)
ext = os.path.splitext(path)[1]
if ext in extensions or path == 'create_hash_table':
found = False
content = fix_content(fn)
content = fix_copyright(ext,content)
for token in tokens:
if token[0] in path:
newfn = os.path.join(dirname,path.replace(token[0],token[1]))
found = True
newf = open(newfn,'w')
newf.write(content)
newf.close()
print "Renamed: %s" % newfn
os.remove(fn)
break
if not found:
newf = open(fn,'w')
newf.write(content)
newf.close()
print "Fixed: %s" % fn
return True
return False
for root, dirs, files in os.walk(os.path.abspath(root_dir)):
for file in files:
from_ = os.path.join(root, file)
#print from_
fix_filename(from_)
xcode = os.path.join(root_dir,'JavaScriptCore.xcodeproj')
if os.path.exists(xcode):
newxcode = os.path.join(root_dir,'TiCore.xcodeproj')
os.rename(xcode,newxcode)
jsc = os.path.join(root_dir,'DerivedSources','JavaScriptCore')
if os.path.exists(jsc):
newjsc = os.path.join(root_dir,'DerivedSources','TiCore')
os.rename(jsc,newjsc)
sys.exit(0)