This repository has been archived by the owner on Nov 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathwscript
200 lines (174 loc) · 6.62 KB
/
wscript
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
# WARNING: This wscript does not follow good practices and should not be copied
# or reproduced in your own projects.
#
# Multi Timer v3.4
# http://matthewtole.com/pebble/multi-timer/
#
# ----------------------
#
# The MIT License (MIT)
#
# Copyright © 2013 - 2015 Matthew Tole
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# --------------------
#
# wscript
#
import json
import datetime
import os
from sh import karma
from sh import uglifyjs
from sh import jshint
from sh import make
top = '.'
out = 'build'
def options(ctx):
ctx.load('pebble_sdk')
def configure(ctx):
ctx.load('pebble_sdk')
def distclean(ctx):
ctx.load('pebble_sdk')
try:
os.remove('./src/js/pebble-js-app.js')
except OSError as e:
pass
try:
os.remove('./src/js/src/generated/appinfo.js')
except OSError as e:
pass
try:
os.remove('./src/generated/appinfo.h')
except OSError as e:
pass
def build(ctx):
ctx.load('pebble_sdk')
js_libs = [
'../src/js/src/libs/pebble-ga.js'
]
js_sources = [
'../src/js/src/generated/appinfo.js',
'../src/js/src/main.js',
]
built_js = '../src/js/pebble-js-app.js'
c_sources = ctx.path.ant_glob('src/**/*.c')
# Generate appinfo.js
ctx(rule=generate_appinfo_js, source='../appinfo.json', target='../src/js/src/generated/appinfo.js')
# Generate appinfo.h
ctx(rule=generate_appinfo_h, source='../appinfo.json', target='../src/generated/appinfo.h')
# Run the C tests.
# ctx(rule=make_test);
# Run jshint on all the JavaScript files
ctx(rule=js_jshint, source=js_sources)
# Run the suite of JS tests.
# ctx(rule=js_karma)
# Combine the source JS files into a single JS file.
ctx(rule=concatenate_js, source=' '.join(js_libs + js_sources), target=built_js)
# Build and bundle the Pebble app.
ctx.pbl_program(source=c_sources,
includes=lib_folders(ctx),
target='pebble-app.elf')
ctx.pbl_bundle(elf='pebble-app.elf', js=built_js)
# Return a list of all of the subfolders within the "src/libs/" folder
def lib_folders(ctx):
folders = []
libs = ctx.path.find_node('./src/libs')
for folder in libs.listdir():
folders.append(libs.find_node(folder).abspath())
return folders
def generate_appinfo_h(task):
ext_out = '.c'
src = task.inputs[0].abspath()
target = task.outputs[0].abspath()
appinfo = json.load(open(src))
f = open(target, 'w')
write_comment_header(f, 'src/generated/appinfo.h', appinfo)
f.write('#pragma once\n\n')
f.write('#define VERSION_LABEL "{0}"\n'.format(appinfo["versionLabel"]))
f.write('#define UUID "{0}"\n'.format(appinfo["uuid"]))
f.write('#define DEBUG_MODE {0}\n'.format('true' if appinfo["debug"] else 'false'))
f.write('#define DELIMITER_INNER \'{0}\'\n'.format(appinfo['delimiters']['inner']))
f.write('#define DELIMITER_OUTER \'{0}\'\n'.format(appinfo['delimiters']['outer']))
for key in appinfo['appKeys']:
f.write('#define APP_KEY_{0} {1}\n'.format(key.upper(), appinfo['appKeys'][key]))
f.close()
def generate_appinfo_js(task):
src = task.inputs[0].abspath()
target = task.outputs[0].abspath()
data = open(src).read().strip()
appinfo = json.load(open(src))
f = open(target, 'w')
write_comment_header(f, 'src/js/src/generated/appinfo.js', appinfo)
f.write('/* exported AppInfo */\n\n')
f.write('var AppInfo = ')
f.write(data)
f.write(';')
f.close()
# Function to write the comment header for both the C and JS generated files.
# Thank goodness that they have the same comment syntax!
def write_comment_header(f, filename, appinfo):
f.write('/*\n')
f.write('\n')
f.write('Multi Timer v{0}\n'.format(appinfo['versionLabel']))
f.write('http://matthewtole.com/pebble/multi-timer/\n')
f.write('\n')
f.write('----------------------\n')
f.write('\n')
f.write('The MIT License (MIT)\n')
f.write('\n')
f.write('Copyright © 2013 - {0} Matthew Tole\n'.format(datetime.datetime.now().year))
f.write('\n')
f.write('Permission is hereby granted, free of charge, to any person obtaining a copy\n')
f.write('of this software and associated documentation files (the "Software"), to deal\n')
f.write('in the Software without restriction, including without limitation the rights\n')
f.write('to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n')
f.write('copies of the Software, and to permit persons to whom the Software is\n')
f.write('furnished to do so, subject to the following conditions:\n')
f.write('\n')
f.write('The above copyright notice and this permission notice shall be included in\n')
f.write('all copies or substantial portions of the Software.\n')
f.write('\n')
f.write('THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n')
f.write('IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n')
f.write('FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n')
f.write('AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n')
f.write('LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n')
f.write('OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n')
f.write('THE SOFTWARE.\n')
f.write('\n')
f.write('--------------------\n')
f.write('\n')
f.write('{0}\n'.format(filename))
f.write('\n')
f.write('*/\n')
f.write('\n')
def concatenate_js(task):
inputs = (input.abspath() for input in task.inputs)
uglifyjs(*inputs, o=task.outputs[0].abspath(), b=True, indent_level=2)
def make_test(task):
ext_out = '.c'
make()
def js_jshint(task):
inputs = (input.abspath() for input in task.inputs)
jshint(*inputs, config=".jshintrc")
def js_karma(task):
ext_out = '.js'
karma("start", single_run=True, reporters="dots")