From d393fc6e85b873fc9f025ac699a5987852010b35 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Wed, 25 Sep 2019 12:01:11 +0200 Subject: [PATCH] Revert "core: replace BITCOIN_ONLY with a constant only in src/trezor/utils.py" This reverts commit b9e7e93bcf4ac40fb494fe1e8c0d2438fd1c99df. Unfortunately this does not work, compiler cannot see it is a literal constant, so it won't get optimized out, even when we use const(0). Also const(False) is not supported at all. --- core/site_scons/site_tools/micropython/__init__.py | 12 +++++------- core/src/trezor/utils.py | 3 --- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/core/site_scons/site_tools/micropython/__init__.py b/core/site_scons/site_tools/micropython/__init__.py index 16306c02a..35c803425 100644 --- a/core/site_scons/site_tools/micropython/__init__.py +++ b/core/site_scons/site_tools/micropython/__init__.py @@ -23,13 +23,11 @@ def generate(env): target = str(target[0]) source = str(source[0]) source_name = source.replace(env['source_dir'], '') - # set utils.BITCOIN_ONLY to constant in src/trezor/utils.py - if source == "src/trezor/utils.py": - btc_only = 'True' if env['bitcoin_only'] == '1' else 'False' - interim = "%s.i" % target[:-4] # replace .mpy with .i - return '$SED "s:^BITCOIN_ONLY = BITCOIN_ONLY$:BITCOIN_ONLY = %s:g" %s > %s && $MPY_CROSS -o %s -s %s %s' % (btc_only, source, interim, target, source_name, interim) - else: - return '$MPY_CROSS -o %s -s %s %s' % (target, source_name, source) + # replace "utils.BITCOIN_ONLY" with literal constant (True/False) + # so the compiler can optimize out the things we don't want + btc_only = 'True' if env['bitcoin_only'] == '1' else 'False' + interim = "%s.i" % target[:-4] # replace .mpy with .i + return '$SED "s:utils\.BITCOIN_ONLY:%s:g" %s > %s && $MPY_CROSS -o %s -s %s %s' % (btc_only, source, interim, target, source_name, interim) env['BUILDERS']['FrozenModule'] = SCons.Builder.Builder( generator=generate_frozen_module, diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py index fbb2a40a5..f38792359 100644 --- a/core/src/trezor/utils.py +++ b/core/src/trezor/utils.py @@ -14,9 +14,6 @@ from trezorutils import ( # noqa: F401 set_mode_unprivileged, ) -# Don't remove! This line will be modified when freezing the module -BITCOIN_ONLY = BITCOIN_ONLY - if __debug__: if EMULATOR: import uos