From b9e7e93bcf4ac40fb494fe1e8c0d2438fd1c99df Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sun, 22 Sep 2019 15:07:04 +0200 Subject: [PATCH] core: replace BITCOIN_ONLY with a constant only in src/trezor/utils.py --- core/site_scons/site_tools/micropython/__init__.py | 13 ++++++++----- core/src/trezor/utils.py | 3 +++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/site_scons/site_tools/micropython/__init__.py b/core/site_scons/site_tools/micropython/__init__.py index fa60d1ac8..16306c02a 100644 --- a/core/site_scons/site_tools/micropython/__init__.py +++ b/core/site_scons/site_tools/micropython/__init__.py @@ -23,10 +23,13 @@ def generate(env): target = str(target[0]) source = str(source[0]) source_name = source.replace(env['source_dir'], '') - # unroll the utils.BITCOIN_ONLY constant - 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) + # 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) env['BUILDERS']['FrozenModule'] = SCons.Builder.Builder( generator=generate_frozen_module, @@ -38,4 +41,4 @@ def generate(env): def exists(env): - return True \ No newline at end of file + return True diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py index f38792359..fbb2a40a5 100644 --- a/core/src/trezor/utils.py +++ b/core/src/trezor/utils.py @@ -14,6 +14,9 @@ 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