-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathpavement.py
258 lines (210 loc) · 8.45 KB
/
pavement.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
from paver.easy import *
from paver.easy import path
import re
import itertools
"""
Notes:
Java build tasks require ant to be on your path
C# tasks require Visual Studio and might need to be run using the
vcpaver.cmd script which sets up the VC environment variables. (You may
need to adjust the path to vcvarsall.bat in the vcpaver.cmd script)
ObjC tasks require clang. To build the test application, you also need v8:
To get v8 libraries on OSX:
get brew
sudo brew install v8
For packaging sdks on windows, make sure 7zip is on your path.
Building docs requires markdown and django:
pip install markdown django
"""
PRETTY_PLATFORMS = {
'ios': 'iOS',
'mac': 'Mac',
'android': 'Android',
'win8': 'Windows 8',
'winphone': 'Windows Phone',
}
DEBUG = False
CONFIGURATION = 'Release'
@task
def debug():
global DEBUG, CONFIGURATION
DEBUG = True
CONFIGURATION = 'Debug'
# Java sdk for Android
def _make_java(path):
target = CONFIGURATION.lower()
with pushd(path):
with pushd('Core'):
sh('ant %s' % target)
with pushd('Tapstream'):
sh('ant %s' % target)
with pushd('TapstreamTest'):
sh('ant %s' % target)
def _gen_java_whitelabel():
path('java-whitelabel').rmtree()
path.copytree(path('java'), path('java-whitelabel'))
for d in ('Core', 'Tapstream', 'TapstreamTest'):
path.move(path('java-whitelabel/%s/src/com/tapstream' % d), path('java-whitelabel/%s/src/com/conversiontracker' % d))
path.move(path('java-whitelabel/Tapstream/src/com/conversiontracker/sdk/Tapstream.java'), path('java-whitelabel/Tapstream/src/com/conversiontracker/sdk/ConversionTracker.java'))
package_name = re.compile(r'com\.tapstream\.sdk')
class_name = re.compile(r'([\s("])Tapstream([\s(.])')
for file_path in path('java-whitelabel').walkfiles('*.java'):
with open(file_path, 'rb+') as f:
data = f.read()
data = package_name.sub('com.conversiontracker.sdk', data)
data = class_name.sub(r'\1ConversionTracker\2', data)
f.seek(0)
f.write(data)
f.truncate()
def _package_java():
path('builds/android').rmtree()
path('builds/android').makedirs()
path.copy(path('./java/Tapstream/build/jar/Tapstream.jar'), path('./builds/android/'))
path.copy(path('./java/Tapstream/build/jar/Tapstream.jar'), path('./examples/Android/Example/libs/'))
path('builds/TapstreamSDK-android.zip').remove()
with pushd('builds/android'):
sh('7z a -tzip ../TapstreamSDK-android.zip Tapstream.jar')
def _package_java_whitelabel():
path('builds/android-whitelabel').rmtree()
path('builds/android-whitelabel').makedirs()
path.copy(path('./java-whitelabel/Tapstream/build/jar/Tapstream.jar'), path('./builds/android-whitelabel/ConversionTracker.jar'))
path('builds/TapstreamSDK-android-whitelabel.zip').remove()
with pushd('builds/android-whitelabel'):
sh('7z a -tzip ../TapstreamSDK-android-whitelabel.zip ConversionTracker.jar')
path('java-whitelabel').rmtree()
@task
def make_java():
_make_java('java')
@task
def test_java():
sh('java -jar ./java/TapstreamTest/build/jar/TapstreamTest.jar tests.js')
@task
def package_java():
_make_java('java')
_gen_java_whitelabel()
_make_java('java-whitelabel')
_package_java()
_package_java_whitelabel()
# C# sdk for Windows 8 and Windows Phone
@task
def make_cs():
with pushd('cs'):
sh('msbuild /m Tapstream.sln /t:Build /p:Configuration=%s' % CONFIGURATION)
sh('msbuild /m TapstreamWinPhone.sln /t:Build /p:Configuration=%s' % CONFIGURATION)
sh('msbuild /m TapstreamTest.sln /t:Build /p:Configuration=Debug')
@task
def test_cs():
sh('"cs/TapstreamTest/bin/Debug/TapstreamTest.exe" tests.js')
@task
def package_cs():
make_cs()
path('builds/win8').rmtree()
path('builds/win8').makedirs()
path.copy(path('./cs/Tapstream/bin/%s/TapstreamMetrics.winmd' % CONFIGURATION), path('./builds/win8/'))
path('builds/winphone').rmtree()
path('builds/winphone').makedirs()
path.copy(path('./cs/TapstreamWinPhone/Bin/%s/TapstreamMetrics.dll' % CONFIGURATION), path('./builds/winphone/'))
path('builds/TapstreamSDK-win8.zip').remove()
with pushd('builds/win8'):
sh('7z a -tzip ../TapstreamSDK-win8.zip TapstreamMetrics.winmd')
path('builds/TapstreamSDK-winphone.zip').remove()
with pushd('builds/winphone'):
sh('7z a -tzip ../TapstreamSDK-winphone.zip TapstreamMetrics.dll')
# ObjC sdk for Mac and iOS
def listify(series, prefix=''):
return ' '.join(['%s%s' % (prefix, path(d).normpath().replace('\\', '/')) for d in series])
@task
def make_objc():
with pushd('objc'):
path('Tapstream/bin').mkdir()
path('TapstreamTest/bin').mkdir()
include_dirs = listify(['Core', '/usr/local/include/'], prefix='-I')
core_sources = listify(path('Core').walkfiles('*.m'))
tapstream_sources = ' '.join((
core_sources,
listify(path('Tapstream').walkfiles('*.m'))
))
tapstream_test_sources = ' '.join((
core_sources,
listify(path('TapstreamTest').walkfiles('*.m')),
listify(path('TapstreamTest').walkfiles('*.mm'))
))
# Compile the non-test code as well to catch potential errors (even though this sdk will be distributed as source)
# iOS With and without ARC
clang = sh('echo xcrun -sdk iphoneos clang', capture=True).strip()
sdk_root = sh('echo $(xcodebuild -version -sdk iphoneos Path)', capture=True).strip()
sh('%s -isysroot %s -miphoneos-version-min=4.3 -arch armv7 -fno-objc-arc -shared %s %s -o ./TapstreamTest/bin/Tapstream.so -framework Foundation -framework UIKit' % (
clang, sdk_root, include_dirs, tapstream_sources
))
sh('%s -isysroot %s -miphoneos-version-min=4.3 -arch armv7 -fobjc-arc -shared %s %s -o ./TapstreamTest/bin/Tapstream.so -framework Foundation -framework UIKit' % (
clang, sdk_root, include_dirs, tapstream_sources
))
# Mac With and without ARC
sh('clang -fno-objc-arc -shared %s %s -o ./TapstreamTest/bin/Tapstream.so -framework Foundation -framework AppKit' % (
include_dirs, tapstream_sources
))
sh('clang -fobjc-arc -shared %s %s -o ./TapstreamTest/bin/Tapstream.so -framework Foundation -framework AppKit' % (
include_dirs, tapstream_sources
))
# Compile test application
sh('clang++ -fobjc-arc %s %s -o ./TapstreamTest/bin/TapstreamTest -lv8 -framework Foundation' % (
include_dirs, tapstream_test_sources
))
@task
def test_objc():
sh('./objc/TapstreamTest/bin/TapstreamTest tests.js')
@task
def package_objc():
make_objc()
path('builds').mkdir()
for sdk in ('mac', 'ios'):
path('builds/%s' % sdk).rmtree()
path('builds/%s/Tapstream' % sdk).makedirs()
for file_type in ('.h', '.m'):
sh('cp ./objc/Tapstream/*%s ./builds/%s/Tapstream/' % (file_type, sdk))
sh('cp ./objc/Core/*%s ./builds/%s/Tapstream/' % (file_type, sdk))
path('builds/TapstreamSDK-%s.zip' % sdk).remove()
with pushd('builds/%s' % sdk):
sh('zip -r ../TapstreamSDK-%s.zip Tapstream' % sdk)
# Generate whitelabel
path('builds/%s-whitelabel' % sdk).rmtree()
path('builds/%s-whitelabel' % sdk).mkdir()
sh('cp -r ./builds/%s/Tapstream ./builds/%s-whitelabel/' % (sdk, sdk))
with pushd('./builds/%s-whitelabel' % sdk):
sh('mv Tapstream ConversionTracker')
sh('mv ConversionTracker/TSTapstream.h ConversionTracker/ConversionTracker.h')
sh('mv ConversionTracker/TSTapstream.m ConversionTracker/ConversionTracker.m')
pattern = re.compile(r'(With|[\s\[("])(?:TS)?Tapstream([\s(.*:])')
for file_path in itertools.chain(path('.').walkfiles('*.h'), path('.').walkfiles('*.m')):
with open(file_path, 'rb+') as f:
data = f.read()
data = pattern.sub(r'\1ConversionTracker\2', data)
f.seek(0)
f.write(data)
f.truncate()
path('builds/TapstreamSDK-%s-whitelabel.zip' % sdk).remove()
with pushd('builds/%s-whitelabel' % sdk):
sh('zip -r ../TapstreamSDK-%s-whitelabel.zip ConversionTracker' % sdk)
@task
def docs():
import markdown
from django.template import Context, Template
from django.conf import settings
settings.configure()
path('builds/docs').rmtree()
path('builds/docs').makedirs()
path.copy(path('./docs/bootstrap.min.css'), path('./builds/docs/'))
path.copy(path('./docs/pygments.css'), path('./builds/docs/'))
with open('docs/base.html') as f:
base_template = Template(f.read())
with open('docs/docs.md') as f:
md_template = Template(f.read())
with pushd('builds/docs'):
for platform in ('android', 'ios', 'mac', 'win8', 'winphone'):
md = md_template.render(Context({'platform': platform, 'pretty_platform': PRETTY_PLATFORMS[platform]}))
with open('docs_%s.md' % platform, 'w') as f:
f.write(md)
md = markdown.markdown(md, ['fenced_code', 'codehilite'])
page = base_template.render(Context({'md': md}))
with open('docs_%s.html' % platform, 'w') as f:
f.write(page)