Skip to content

Commit b1fbec1

Browse files
authored
Enable embuilder.py targets mixed with predefined aliases (e.g. SYSTEM or MINIMAL) (#19180)
1 parent 9154b00 commit b1fbec1

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

embuilder.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -208,31 +208,43 @@ def main():
208208
if args.force:
209209
do_clear = True
210210

211+
system_libraries, system_tasks = get_system_tasks()
212+
211213
# process tasks
212214
auto_tasks = False
213-
tasks = args.targets
214-
system_libraries, system_tasks = get_system_tasks()
215-
if 'SYSTEM' in tasks:
216-
tasks = system_tasks
217-
auto_tasks = True
218-
elif 'USER' in tasks:
219-
tasks = PORTS
220-
auto_tasks = True
221-
elif 'MINIMAL' in tasks:
222-
tasks = MINIMAL_TASKS
223-
auto_tasks = True
224-
elif 'MINIMAL_PIC' in tasks:
225-
tasks = MINIMAL_PIC_TASKS
226-
auto_tasks = True
227-
elif 'ALL' in tasks:
228-
tasks = system_tasks + PORTS
229-
auto_tasks = True
215+
task_targets = dict.fromkeys(args.targets) # use dict to keep targets order
216+
217+
# subsitute
218+
predefined_tasks = {
219+
'SYSTEM': system_tasks,
220+
'USER': PORTS,
221+
'MINIMAL': MINIMAL_TASKS,
222+
'MINIMAL_PIC': MINIMAL_PIC_TASKS,
223+
'ALL': system_tasks + PORTS,
224+
}
225+
for name, tasks in predefined_tasks.items():
226+
if name in task_targets:
227+
task_targets[name] = tasks
228+
auto_tasks = True
229+
230+
# flatten tasks
231+
tasks = []
232+
for name, targets in task_targets.items():
233+
if targets is None:
234+
# Use target name as task
235+
tasks.append(name)
236+
else:
237+
# There are some ports that we don't want to build as part
238+
# of ALL since the are not well tested or widely used:
239+
if 'cocos2d' in targets:
240+
targets.remove('cocos2d')
241+
242+
# Use targets from predefined_tasks
243+
tasks.extend(targets)
244+
230245
if auto_tasks:
231-
# There are some ports that we don't want to build as part
232-
# of ALL since the are not well tested or widely used:
233-
skip_tasks = ['cocos2d']
234-
tasks = [x for x in tasks if x not in skip_tasks]
235246
print('Building targets: %s' % ' '.join(tasks))
247+
236248
for what in tasks:
237249
for old, new in legacy_prefixes.items():
238250
if what.startswith(old):

test/test_sanity.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,15 @@ def test_embuilder_force_port(self):
707707
# Unless --force is specified
708708
self.assertContained('generating port', self.do([EMBUILDER, 'build', 'zlib', '--force']))
709709

710+
def test_embuilder_auto_tasks(self):
711+
restore_and_set_up()
712+
self.assertContained('Building targets: zlib', self.do([EMBUILDER, 'build', 'zlib', 'MINIMAL']))
713+
# Second time it should not generate anything
714+
self.assertNotContained('generating port', self.do([EMBUILDER, 'build', 'zlib']))
715+
self.assertNotContained('generating system library', self.do([EMBUILDER, 'build', 'libemmalloc']))
716+
# Unless --force is specified
717+
self.assertContained('Building targets: zlib', self.do([EMBUILDER, 'build', 'zlib', 'MINIMAL', '--force']))
718+
710719
def test_embuilder_wasm_backend(self):
711720
restore_and_set_up()
712721
# the --lto flag makes us build wasm-bc

0 commit comments

Comments
 (0)