-
Notifications
You must be signed in to change notification settings - Fork 1
/
monkey.bzl
111 lines (105 loc) · 3.89 KB
/
monkey.bzl
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
monkeydo_script_tmpl = """\
#!/bin/bash
DST=/tmp/GARMIN/APPS
STATE=/tmp/com.garmin.connectiq
[ -d $STATE ] && rm -rf $STATE
mkdir -p $DST
echo `pwd`
cd {prg}
(cd /tmp; "connectiq") & # > /dev/null 2>&1) &
while [ ! -d $DST ]; do echo waiting for $DST; sleep 1; done
sleep 5
cp -f {prg_device}.prg $DST/{prg}.prg
cp -f {prg_device}.prg.debug.xml $DST/{prg}.prg.debug.xml
# cp -f {prg_device}-settings.json $DST/{prg}-settings.json
"monkeydo" {prg_device}.prg {device} {test_flag}
killall simulator
"""
OPT = {
'dbg': '1',
'fastbuild': '2',
'opt': '3pz',
}
def _monkeyc_binary_impl(ctx):
developer_key = '/Users/robertbuessow/StudioProjects/developer_key'
device = ctx.var['TARGET_CPU']
prg = ctx.files.jungles[0].dirname
prg_device = '%s_%s' % (ctx.attr.name, device)
prg_file = ctx.actions.declare_file(prg_device + ".prg")
outputs = [
prg_file,
ctx.actions.declare_file(prg_device + ".prg.debug.xml"),
# ctx.actions.declare_file(prg_device + "-settings.json"),
]
profile = ctx.var['COMPILATION_MODE'] == 'dbg'
ctx.actions.run_shell(
inputs = ctx.files.jungles + ctx.files.srcs + ctx.files.resources + ctx.files.manifest,
outputs = outputs,
progress_message = 'Building %s.prg' % ctx.attr.name,
execution_requirements = { 'no-sandbox': 'True' },
use_default_shell_env = True,
command = ' '.join([
# 'date \'+<strings><string id="BuildTime">%Y-%m-%dT%H:%M%z</string></strings>\' > "resources/strings/version.xml";',
'monkeyc',
'--jungles %s' % '\\;'.join([f.path for f in ctx.files.jungles]),
'--output %s' % prg_file.path,
'--private-key $(printenv DEVELOPER_KEY)',
'--device %s' % device,
'--warn',
'--optimization %s' % OPT[ctx.var['COMPILATION_MODE']],
'--profile' if profile else '',
'--unit-test' if ctx.attr.test else ''
])
)
monkeydo_script = ctx.actions.declare_file('%s-do.sh' % ctx.attr.name)
monkeydo_script_content = monkeydo_script_tmpl.format(
prg=prg,
prg_device=prg_device,
device=device,
test_flag=' -t' if ctx.attr.test else '')
ctx.actions.write(monkeydo_script, monkeydo_script_content, is_executable=True)
return [DefaultInfo(runfiles=ctx.runfiles(files=outputs), executable=monkeydo_script)]
def _monkeyc_package_impl(ctx):
developer_key = '/Users/robertbuessow/StudioProjects/developer_key'
prg = ctx.files.jungles[0].dirname
prg_file = ctx.actions.declare_file(prg + ".iq")
outputs = [prg_file]
ctx.actions.run_shell(
inputs = ctx.files.jungles + ctx.files.srcs + ctx.files.resources + ctx.files.manifest,
outputs = outputs,
progress_message = 'Building %s.iq' % ctx.attr.name,
execution_requirements = { 'no-sandbox': 'True' },
use_default_shell_env = True,
command = ' '.join([
'monkeyc',
'--jungles %s' % '\\;'.join([f.path for f in ctx.files.jungles]),
'--output %s' % prg_file.path,
'--private-key $(printenv DEVELOPER_KEY)',
'--warn',
'--optimization %s' % OPT[ctx.var['COMPILATION_MODE']],
'--package-app',
'--release',
])
)
return [DefaultInfo(runfiles=ctx.runfiles(files=outputs))]
monkeyc_binary = rule(
implementation = _monkeyc_binary_impl,
attrs = {
'srcs': attr.label_list(mandatory=True, allow_files=['.mc']),
'resources': attr.label_list(default=[], allow_files=True),
'jungles': attr.label(mandatory=True, allow_single_file=True),
'manifest': attr.label(mandatory=True, allow_single_file=True),
'test': attr.bool(default=False),
},
executable = True,
)
monkeyc_package = rule(
implementation = _monkeyc_package_impl,
attrs = {
'srcs': attr.label_list(mandatory=True, allow_files=['.mc']),
'resources': attr.label_list(default=[], allow_files=True),
'jungles': attr.label(mandatory=True, allow_single_file=True),
'manifest': attr.label(mandatory=True, allow_single_file=True),
},
executable = False,
)