forked from appcelerator-archive/tijscore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixup.py
executable file
·124 lines (108 loc) · 3.39 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
#!/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
root_dir = "TiCore"
tokens = [
['JSString','TiString'],
['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'],
]
#['jsAPIValueWrapper','TiAPIValueWrapper'],
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 by Appcelerator, Inc.
*/
"""
def fix_copyright(ext,content):
if ext in ('.h','.cpp','.c','.mm'):
if content.find('Appcelerator Titanium License')==-1:
content = COPYRIGHT + 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 ('.c','.cpp','.mm','.h','.pbxproj','.exp','.xcconfig','.sh','.make','.y','.lut.h') 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)