-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwscript
132 lines (107 loc) · 4.15 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
import os.path
import json
import shutil
from sh import uglifyjs
from sh import jshint
top = '.'
out = 'build'
def options(ctx):
ctx.load('pebble_sdk')
def configure(ctx):
ctx.load('pebble_sdk')
def distclean(ctx):
ctx.load('pebble_sdk')
for p in ['build', 'src/generated', 'src/js/src/generated', 'src/js/app.js']:
try:
if os.path.isfile(p): os.remove(p)
elif os.path.isdir(p): shutil.rmtree(p)
except OSError as e:
pass
def build(ctx):
# Create a group to ensure the generated files are created first
ctx.add_group('pregenerate')
ctx.load('pebble_sdk')
build_worker = os.path.exists('worker_src')
binaries = []
# The following must be generated first
ctx.set_group('pregenerate')
# Run jshint on package.json
ctx(rule=js_jshint, source='package.json')
# Run jshint on all the JavaScript files
ctx(rule=js_jshint, source=ctx.path.ant_glob('src/js/src/**/*.js'))
# Generate appinfo.h
ctx(rule=generate_appinfo_h, source='package.json', target='../src/generated/appinfo.h')
# Generate keys.h
ctx(rule=generate_keys_h, source='src/keys.json', target='../src/generated/keys.h')
# Generate appinfo.js
ctx(rule=generate_appinfo_js, source='package.json', target='../src/js/src/generated/appinfo.js')
# Generate keys.js
ctx(rule=generate_keys_js, source='src/keys.json', target='../src/js/src/generated/keys.js')
# Combine the source JS files into a single JS file.
ctx(rule=concatenate_js, source='src/js/src/main.js src/js/src/appmessagequeue.js ../src/js/src/generated/appinfo.js ../src/js/src/generated/keys.js ', target='src/js/app.js')
# Now the main build process can happen, building multiple platforms
for p in ctx.env.TARGET_PLATFORMS:
ctx.set_env(ctx.all_envs[p])
ctx.set_group(ctx.env.PLATFORM_NAME)
app_elf='{}/pebble-app.elf'.format(ctx.env.BUILD_DIR)
ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'), target=app_elf)
if build_worker:
worker_elf='{}/pebble-worker.elf'.format(ctx.env.BUILD_DIR)
binaries.append({'platform': p, 'app_elf': app_elf, 'worker_elf': worker_elf})
ctx.pbl_worker(source=ctx.path.ant_glob('worker_src/**/*.c'), target=worker_elf)
else:
binaries.append({'platform': p, 'app_elf': app_elf})
# Bundle everything needed into the pbw file
ctx.set_group('bundle')
ctx.pbl_bundle(binaries=binaries, js='src/js/app.js')
def generate_appinfo_h(task):
src = task.inputs[0].abspath()
target = task.outputs[0].abspath()
appinfo = json.load(open(src))
f = open(target, 'w')
f.write('#pragma once\n\n')
# f.write('#define DEBUG {0}\n'.format('true' if appinfo['debug'] else 'false'))
f.write('#define VERSION_LABEL "{0}"\n'.format(appinfo['version']))
f.write('#define SHORT_NAME "{0}"\n'.format(appinfo['name']))
f.write('#define UUID "{0}"\n'.format(appinfo['pebble']['uuid']))
for key in appinfo['pebble']['messageKeys']:
f.write('#define APP_KEY_{0} {1}\n'.format(key.upper(), appinfo['pebble']['messageKeys'][key]))
f.close()
def generate_keys_h(task):
src = task.inputs[0].abspath()
target = task.outputs[0].abspath()
keys = json.load(open(src))
f = open(target, 'w')
f.write('#pragma once\n\n')
for key in keys:
f.write('enum {\n')
for i, key2 in enumerate(keys[key]):
f.write('\tKEY_{0}_{1} = {2},\n'.format(key, key2, i))
f.write('};\n')
f.close()
def generate_appinfo_js(task):
src = task.inputs[0].abspath()
target = task.outputs[0].abspath()
data = open(src).read().strip()
f = open(target, 'w')
f.write('var AppInfo = ')
f.write(data)
f.write(';')
f.close()
def generate_keys_js(task):
src = task.inputs[0].abspath()
target = task.outputs[0].abspath()
keys = json.load(open(src))
f = open(target, 'w')
for key in keys:
f.write('var {0} = {{\n'.format(key))
for i, key2 in enumerate(keys[key]):
f.write('\t{0}: {1},\n'.format(key2, i))
f.write('};\n')
f.close()
def concatenate_js(task):
inputs = (input.abspath() for input in task.inputs)
uglifyjs(*inputs, o=task.outputs[0].abspath(), c=True)
def js_jshint(task):
inputs = (input.abspath() for input in task.inputs)
jshint(*inputs)