mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-17 19:00:58 +00:00
build(core): optimize qstr and module collection
Run the preprocessor on each file separately. This allows parallelization and doesn't need to re-run for all files if just a small number is changed. Replace simple extractors with one-liners which are generally going to be faster.
This commit is contained in:
parent
1d6fafa0ff
commit
7958061705
@ -489,8 +489,10 @@ qstr_protobuf = env.Command(
|
||||
|
||||
qstr_micropython = 'vendor/micropython/py/qstrdefs.h'
|
||||
|
||||
micropy_defines = env.MicroPyDefines(source=SOURCE_QSTR)
|
||||
|
||||
qstr_collected = env.CollectQstr(
|
||||
target='genhdr/qstrdefs.collected.h', source=SOURCE_QSTR)
|
||||
target='genhdr/qstrdefs.collected.h', source=micropy_defines)
|
||||
|
||||
qstr_preprocessed = env.PreprocessQstr(
|
||||
target='genhdr/qstrdefs.preprocessed.h',
|
||||
@ -506,16 +508,16 @@ env.Ignore(qstr_collected, qstr_generated)
|
||||
#
|
||||
|
||||
moduledefs_collected = env.CollectModules(
|
||||
target='genhdr/moduledefs.collected.h', source=SOURCE_QSTR)
|
||||
target='genhdr/moduledefs.collected.h', source=micropy_defines)
|
||||
|
||||
hdr_moduledefs = env.Command(
|
||||
target='genhdr/moduledefs.h',
|
||||
source=moduledefs_collected,
|
||||
action='$MAKEMODULEDEFS $SOURCE > $TARGET', )
|
||||
|
||||
env.Ignore(moduledefs_collected, moduledefs_collected)
|
||||
env.Ignore(moduledefs_collected, qstr_generated)
|
||||
env.Ignore(moduledefs_collected, hdr_moduledefs)
|
||||
env.Ignore(micropy_defines, micropy_defines)
|
||||
env.Ignore(micropy_defines, qstr_generated)
|
||||
env.Ignore(micropy_defines, hdr_moduledefs)
|
||||
|
||||
#
|
||||
# Micropython version
|
||||
|
@ -564,8 +564,10 @@ qstr_protobuf = env.Command(
|
||||
|
||||
qstr_micropython = 'vendor/micropython/py/qstrdefs.h'
|
||||
|
||||
micropy_defines = env.MicroPyDefines(source=SOURCE_QSTR)
|
||||
|
||||
qstr_collected = env.CollectQstr(
|
||||
target='genhdr/qstrdefs.collected.h', source=SOURCE_QSTR)
|
||||
target='genhdr/qstrdefs.collected.h', source=micropy_defines)
|
||||
|
||||
qstr_preprocessed = env.PreprocessQstr(
|
||||
target='genhdr/qstrdefs.preprocessed.h',
|
||||
@ -581,7 +583,7 @@ env.Ignore(qstr_collected, qstr_generated)
|
||||
#
|
||||
|
||||
moduledefs_collected = env.CollectModules(
|
||||
target='genhdr/moduledefs.collected.h', source=SOURCE_QSTR)
|
||||
target='genhdr/moduledefs.collected.h', source=micropy_defines)
|
||||
|
||||
|
||||
hdr_moduledefs = env.Command(
|
||||
@ -602,10 +604,10 @@ hdr_version = env.Command(
|
||||
source='',
|
||||
action='$MAKEVERSIONHDR $TARGET', )
|
||||
|
||||
env.Ignore(hdr_moduledefs, hdr_moduledefs)
|
||||
env.Ignore(hdr_moduledefs, qstr_collected)
|
||||
env.Ignore(hdr_moduledefs, qstr_preprocessed)
|
||||
env.Ignore(hdr_moduledefs, qstr_generated)
|
||||
env.Ignore(micropy_defines, hdr_moduledefs)
|
||||
env.Ignore(micropy_defines, qstr_collected)
|
||||
env.Ignore(micropy_defines, qstr_preprocessed)
|
||||
env.Ignore(micropy_defines, qstr_generated)
|
||||
|
||||
#
|
||||
# Frozen modules
|
||||
|
@ -8,9 +8,14 @@ def generate(env):
|
||||
MODULECOL="site_scons/site_tools/micropython/moduledefs.py",
|
||||
)
|
||||
|
||||
env["BUILDERS"]["MicroPyDefines"] = SCons.Builder.Builder(
|
||||
action="$CC -E $CCFLAGS_QSTR $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCE > $TARGET",
|
||||
suffix=".upydef",
|
||||
single_source=True,
|
||||
)
|
||||
|
||||
env["BUILDERS"]["CollectQstr"] = SCons.Builder.Builder(
|
||||
action="$CC -E $CCFLAGS_QSTR $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES"
|
||||
" | $PYTHON $QSTRCOL > $TARGET"
|
||||
action="cat $SOURCES | perl -nle 'print \"Q($1)\" while /MP_QSTR_(\\w+)/g' > $TARGET"
|
||||
)
|
||||
|
||||
env["BUILDERS"]["PreprocessQstr"] = SCons.Builder.Builder(
|
||||
@ -25,8 +30,9 @@ def generate(env):
|
||||
)
|
||||
|
||||
env["BUILDERS"]["CollectModules"] = SCons.Builder.Builder(
|
||||
action="$CC -E $CCFLAGS_QSTR $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES"
|
||||
" | $PYTHON $MODULECOL > $TARGET"
|
||||
action="grep ^MP_REGISTER_MODULE $SOURCES > $TARGET"
|
||||
# action="$CC -E $CCFLAGS_QSTR $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES"
|
||||
# " | $PYTHON $MODULECOL > $TARGET"
|
||||
)
|
||||
|
||||
def generate_frozen_module(source, target, env, for_signature):
|
||||
|
@ -1,13 +0,0 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def process(source, target):
|
||||
re_module = re.compile(r"MP_REGISTER_MODULE\(.*?,\s*.*?\);")
|
||||
for line in source:
|
||||
for match in re_module.findall(line):
|
||||
target.write(f"{match}\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
process(sys.stdin, sys.stdout)
|
@ -1,14 +0,0 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def process(source, target):
|
||||
re_qstr = re.compile(r"MP_QSTR_[_a-zA-Z0-9]+")
|
||||
for line in source:
|
||||
for match in re_qstr.findall(line):
|
||||
name = match.replace("MP_QSTR_", "")
|
||||
target.write(f"Q({name})\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
process(sys.stdin, sys.stdout)
|
Loading…
Reference in New Issue
Block a user