-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwscript
More file actions
121 lines (89 loc) · 3.34 KB
/
wscript
File metadata and controls
121 lines (89 loc) · 3.34 KB
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
import json
import os
import re
from waflib.Configure import conf
top = '.'
out = 'build'
def options(ctx):
ctx.load('pebble_sdk')
def configure(ctx):
ctx.load('pebble_sdk')
if ctx.env.TARGET_PLATFORMS:
for platform in ctx.env.TARGET_PLATFORMS:
ctx.configure_platform(platform)
else:
ctx.configure_platform()
def build(ctx):
ctx.load('pebble_sdk')
binaries = []
js_target = ctx.concat_javascript(js_path='src/pkjs')
if ctx.env.TARGET_PLATFORMS:
for platform in ctx.env.TARGET_PLATFORMS:
ctx.build_platform(platform, binaries=binaries)
ctx.pbl_bundle(binaries=binaries,
js=js_target)
else:
ctx.env.BUILD_DIR = 'aplite'
ctx.build_platform(binaries=binaries)
elfs = binaries[0]
ctx.pbl_bundle(elf=elfs['app_elf'],
js=js_target)
@conf
def configure_platform(ctx, platform=None):
if platform is not None:
ctx.setenv(platform, ctx.all_envs[platform])
@conf
def build_platform(ctx, platform=None, binaries=None):
if platform is not None:
ctx.set_env(ctx.all_envs[platform])
app_elf = '{}/pebble-app.elf'.format(ctx.env.BUILD_DIR)
ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'),
target=app_elf)
binaries.append({'platform': platform, 'app_elf': app_elf})
@conf
def concat_javascript(ctx, js_path=None):
js_nodes = (ctx.path.ant_glob(js_path + '/**/*.js') +
ctx.path.ant_glob(js_path + '/**/*.json'))
if not js_nodes:
return []
def concat_javascript_task(task):
LOADER_PATH = "loader.js"
LOADER_TEMPLATE = ("__loader.define({relpath}, {lineno}, " +
"function(exports, module, require) {{\n{body}\n}});")
JSON_TEMPLATE = "module.exports = {body};"
def loader_translate(source, lineno):
return LOADER_TEMPLATE.format(
relpath=json.dumps(source['relpath']),
lineno=lineno,
body=source['body'])
sources = []
for node in task.inputs:
relpath = os.path.relpath(node.abspath(), js_path)
with open(node.abspath(), 'r') as f:
body = f.read()
if relpath.endswith('.json'):
body = JSON_TEMPLATE.format(body=body)
if relpath == LOADER_PATH:
sources.insert(0, body)
else:
sources.append({'relpath': relpath, 'body': body})
# Add package.json as a module
PACKAGE_PATH = "package.json"
with open(PACKAGE_PATH, 'r') as f:
body = JSON_TEMPLATE.format(body=f.read())
sources.append({'relpath': PACKAGE_PATH, 'body': body})
sources.append('__loader.require("app.js");')
with open(task.outputs[0].abspath(), 'w') as f:
lineno = 1
for source in sources:
if type(source) is dict:
body = loader_translate(source, lineno)
else:
body = source
f.write(body + '\n')
lineno += body.count('\n') + 1
js_target = ctx.path.make_node('build/src/pkjs/pebble-js-app.js')
ctx(rule=concat_javascript_task,
source=js_nodes,
target=js_target)
return js_target