-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmake.py
294 lines (230 loc) · 7.07 KB
/
make.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#!/usr/bin/env python3
# Copyright (c) 2024 - 2025 Kevin G. Schlosser
import os
import sys
import builder
import shutil
from argparse import ArgumentParser
if sys.platform.startswith('win'):
raise RuntimeError('compiling on windows is not supported at this time')
SCRIPT_DIR = os.path.abspath(os.path.dirname(sys.argv[0]))
MPY_DIR = os.path.join(SCRIPT_DIR, 'micropython')
argParser = ArgumentParser(prefix_chars='-')
argParser.add_argument(
'--custom-board-path',
dest='custom_board_path',
default=None,
action='store'
)
args, extra_args = argParser.parse_known_args(sys.argv[1:])
custom_board_path = args.custom_board_path
if custom_board_path is not None:
if not os.path.exists(custom_board_path):
raise RuntimeError(
'Supplied custom board path does not exist.'
)
for file in os.listdir(custom_board_path):
if file.endswith('.toml'):
extra_args.insert(0, f'--toml={os.path.join(custom_board_path, file)}')
break
argParser = ArgumentParser(prefix_chars='-')
argParser.add_argument(
'--toml',
dest='toml',
help='use a toml file to setup the build.',
action='store',
default=None
)
args, extra_args = argParser.parse_known_args(extra_args)
if args.toml is not None:
toml_path = args.toml
build_path = os.path.join(SCRIPT_DIR, 'build')
if not os.path.exists(build_path):
os.mkdir(build_path)
driver_out_path = os.path.join(build_path, 'display.py')
from builder import toml_reader
build_command = toml_reader.run(toml_path, driver_out_path)
build_command = set(build_command)
extra_args = set(extra_args)
extra_args = list(extra_args.union(build_command))
argParser = ArgumentParser(prefix_chars='-')
argParser.add_argument(
'target',
help='build target',
choices=[
'esp32', 'windows', 'stm32', 'unix', 'rp2',
'renesas-ra', 'nrf', 'mimxrt', 'samd', 'macOS', 'raspberry_pi'
],
action='store',
nargs=1
)
args1, extra_args = argParser.parse_known_args(extra_args)
target = args1.target[0]
argParser = ArgumentParser(prefix_chars='-mscLBFDIVE')
argParser.add_argument(
'clean',
dest='clean',
help='clean the build',
action='store_true'
)
argParser.add_argument(
'LV_CFLAGS',
dest='lv_cflags',
help='additional flags that gets passed to the compiler for LVGL',
action='store',
default=None
)
if target in ('windows', 'unix', 'macOS', 'raspberry_pi'):
argParser.add_argument(
'VARIANT',
dest='board',
help='optional, board to compile for.',
action='store',
default=None
)
else:
argParser.add_argument(
'BOARD',
dest='board',
help='optional, board to compile for.',
action='store',
default=None
)
argParser.add_argument(
'FROZEN_MANIFEST',
dest='frozen_manifest',
help='path to manifest file',
action='store',
default=None
)
argParser.add_argument(
'DISPLAY',
dest='displays',
help=(
'display name or path (absolute) to display driver. '
'Display name is the name of the directory under '
'api_drivers/common_api_drivers/display'
),
action='append',
default=[]
)
argParser.add_argument(
'INDEV',
dest='indevs',
help=(
'indev ic model or path (absolue) to indev driver. '
'Indev name is the name of the source file under '
'api_drivers/common_api_drivers/indev (without the ".py")'
),
action='append',
default=[]
)
argParser.add_argument(
'EXPANDER',
dest='expanders',
help=(
'io expander ic model or path (absolue) to an io expander driver. '
'the model is the name of the source file under '
'api_drivers/common_api_drivers/io_expander (without the ".py")'
),
action='append',
default=[]
)
argParser.add_argument(
'--no-scrub',
dest='no_scrub',
default=False,
action='store_true'
)
args2, extra_args = argParser.parse_known_args(extra_args)
lv_cflags = args2.lv_cflags
clean = args2.clean
board = args2.board
frozen_manifest = args2.frozen_manifest
displays = args2.displays
indevs = args2.indevs
expanders = args2.expanders
builder.DO_NOT_SCRUB_BUILD_FOLDER = args2.no_scrub
if custom_board_path is not None:
board_name = os.path.split(custom_board_path)[-1]
dst_path = f'lib/micropython/ports/{target}/boards/{board_name}'
shutil.copytree(custom_board_path, dst_path)
if board is None or board != board_name:
board = board_name
if lv_cflags is None:
lv_cflags = ''
extra_args.append(f'FROZEN_MANIFEST="{SCRIPT_DIR}/build/manifest.py"')
extra_args.append(f'GEN_SCRIPT=python')
if lv_cflags is not None:
lv_cflags = lv_cflags.replace('"', '')
def get_submodules():
if not os.path.exists(
os.path.join(SCRIPT_DIR, 'lib/micropython/mpy-cross')
):
builder.get_micropython()
if not os.path.exists(
os.path.join(SCRIPT_DIR, 'lib/lvgl/lvgl.h')
):
builder.get_lvgl()
if not os.path.exists(os.path.join(
SCRIPT_DIR, 'lib/pycparser/pycparser')
):
builder.get_pycparser()
def create_lvgl_header():
header_path = f'{SCRIPT_DIR}/build/lvgl_header.h'
with open(header_path, 'w') as f:
f.write(
f'#include "{SCRIPT_DIR}/lib/lvgl/lvgl.h"\n'
)
f.write(
f'#include "{SCRIPT_DIR}/lib/lvgl/src/lvgl_private.h"\n'
)
if __name__ == '__main__':
from builder import set_mp_version
if sys.platform.startswith('win'):
from builder import setup_windows_build
setup_windows_build()
if target.lower() == 'esp32':
from builder import esp32 as mod
elif target.lower() == 'unix':
from builder import unix as mod
elif target.lower() == 'rp2':
from builder import rp2 as mod
elif target.lower() == 'stm32':
from builder import stm32 as mod
elif target.lower() == 'nrf':
from builder import nrf as mod
elif target.lower() == 'renesas-ra':
from builder import renesas as mod
elif target.lower() == 'macos':
from builder import macOS as mod
target = 'unix'
elif target.lower() == 'raspberry_pi':
from builder import raspberry_pi as mod
target = 'unix'
elif target.lower() == 'windows':
from builder import windows as mod
else:
import builder as mod
get_submodules()
extra_args, lv_cflags, board = mod.parse_args(extra_args, lv_cflags, board)
extra_args = mod.build_commands(
target, extra_args, SCRIPT_DIR, lv_cflags, board)
if clean:
print('Cleaning build....')
mod.force_clean(True)
else:
mod.clean()
if not os.path.exists('lib/micropython/mpy_cross/build/mpy-cross'):
print('Compiling mpy-cross....')
mod.mpy_cross()
mod.submodules()
print('Generating build files....')
set_mp_version(target.lower())
mod.build_manifest(
target, SCRIPT_DIR, False, displays,
indevs, expanders, frozen_manifest
)
create_lvgl_header()
print('Compiling....')
mod.compile(*extra_args)