mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 04:18:10 +00:00
build(core): improve model detection
instead of MODEL_IS_T2B1, we now catch INTERNAL_MODEL == Txyz this is still not perfect because it can't detect 'in'/'not in', which sucks but what can we do
This commit is contained in:
parent
87619c19ee
commit
44a6696f24
@ -42,29 +42,41 @@ def generate(env):
|
||||
# replace "utils.BITCOIN_ONLY" with literal constant (True/False)
|
||||
# so the compiler can optimize out the things we don't want
|
||||
btc_only = env["bitcoin_only"] == "1"
|
||||
is_t2b1 = env["TREZOR_MODEL"] == "R"
|
||||
backlight = env["backlight"]
|
||||
optiga = env["optiga"]
|
||||
layout_tt = env["ui_layout"] == "UI_LAYOUT_TT"
|
||||
layout_tr = env["ui_layout"] == "UI_LAYOUT_TR"
|
||||
thp = env["thp"]
|
||||
interim = f"{target[:-4]}.i" # replace .mpy with .i
|
||||
sed_scripts = " ".join(
|
||||
[
|
||||
rf"-e 's/utils\.MODEL_IS_T2B1/{is_t2b1}/g'",
|
||||
rf"-e 's/utils\.BITCOIN_ONLY/{btc_only}/g'",
|
||||
rf"-e 's/utils\.USE_BACKLIGHT/{backlight}/g'",
|
||||
rf"-e 's/utils\.USE_OPTIGA/{optiga}/g'",
|
||||
rf"-e 's/utils\.UI_LAYOUT == \"TT\"/{layout_tt}/g'",
|
||||
rf"-e 's/utils\.UI_LAYOUT == \"TR\"/{layout_tr}/g'",
|
||||
rf"-e 's/utils\.USE_THP/{thp}/g'",
|
||||
r"-e 's/if TYPE_CHECKING/if False/'",
|
||||
r"-e 's/import typing/# \0/'",
|
||||
r"-e '/from typing import (/,/^\s*)/ {s/^/# /; }'",
|
||||
r"-e 's/from typing import/# \0/'",
|
||||
]
|
||||
)
|
||||
return f"$SED {sed_scripts} {source} > {interim} && $MPY_CROSS -o {target} -s {source_name} {interim}"
|
||||
sed_scripts = [
|
||||
rf"-e 's/utils\.BITCOIN_ONLY/{btc_only}/g'",
|
||||
rf"-e 's/utils\.USE_BACKLIGHT/{backlight}/g'",
|
||||
rf"-e 's/utils\.USE_OPTIGA/{optiga}/g'",
|
||||
rf"-e 's/utils\.UI_LAYOUT == \"TT\"/{layout_tt}/g'",
|
||||
rf"-e 's/utils\.UI_LAYOUT == \"TR\"/{layout_tr}/g'",
|
||||
rf"-e 's/utils\.USE_THP/{thp}/g'",
|
||||
r"-e 's/if TYPE_CHECKING/if False/'",
|
||||
r"-e 's/import typing/# \0/'",
|
||||
r"-e '/from typing import (/,/^\s*)/ {s/^/# /; }'",
|
||||
r"-e 's/from typing import/# \0/'",
|
||||
]
|
||||
|
||||
MODEL_SYMS = {
|
||||
"T": "T2T1",
|
||||
"R": "T2B1",
|
||||
"T3T1": "T3T1",
|
||||
}
|
||||
|
||||
for model_sym, internal_model in MODEL_SYMS.items():
|
||||
model_matches = env["TREZOR_MODEL"] == model_sym
|
||||
sed_scripts.extend(
|
||||
(
|
||||
rf"-e 's/utils\.INTERNAL_MODEL == \"{internal_model}\"/{model_matches}/g'",
|
||||
rf"-e 's/utils\.INTERNAL_MODEL != \"{internal_model}\"/{not model_matches}/g'",
|
||||
)
|
||||
)
|
||||
|
||||
return f"$SED {' '.join(sed_scripts)} {source} > {interim} && $MPY_CROSS -o {target} -s {source_name} {interim}"
|
||||
|
||||
env["BUILDERS"]["FrozenModule"] = SCons.Builder.Builder(
|
||||
generator=generate_frozen_module,
|
||||
|
@ -126,8 +126,8 @@ def get_features() -> Features:
|
||||
Capability.Translations,
|
||||
]
|
||||
|
||||
# We do not support some currencies on T2B1
|
||||
if not utils.MODEL_IS_T2B1:
|
||||
# We don't support some currencies on later models (see #2793)
|
||||
if utils.INTERNAL_MODEL == "T2T1":
|
||||
f.capabilities.extend(
|
||||
[
|
||||
Capability.NEM,
|
||||
|
@ -30,10 +30,6 @@ from trezorutils import ( # noqa: F401
|
||||
)
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
# Will get replaced by "True" / "False" in the build process
|
||||
# However, needs to stay as an exported symbol for the unit tests
|
||||
MODEL_IS_T2B1: bool = INTERNAL_MODEL == "T2B1"
|
||||
|
||||
DISABLE_ANIMATION = 0
|
||||
|
||||
if __debug__:
|
||||
|
@ -1,6 +1,6 @@
|
||||
from common import * # isort:skip
|
||||
|
||||
if not utils.MODEL_IS_T2B1:
|
||||
if utils.INTERNAL_MODEL not in ("T2B1", "T3T1"):
|
||||
from trezor.crypto import bip39
|
||||
from trezor.enums import AmountUnit, OutputScriptType
|
||||
from trezor.enums.RequestType import TXFINISHED, TXINPUT, TXMETA, TXOUTPUT
|
||||
@ -405,5 +405,5 @@ class TestSignTxDecred(unittest.TestCase):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not utils.MODEL_IS_T2B1:
|
||||
if utils.INTERNAL_MODEL not in ("T2B1", "T3T1"):
|
||||
unittest.main()
|
||||
|
@ -22,7 +22,7 @@ class TestCoins(unittest.TestCase):
|
||||
("ZEC", "Zcash", 7352),
|
||||
("TAZ", "Zcash Testnet", 7461),
|
||||
]
|
||||
if not utils.MODEL_IS_T2B1:
|
||||
if utils.INTERNAL_MODEL not in ("T2B1", "T3T1"):
|
||||
ref.extend(
|
||||
[
|
||||
("NMC", "Namecoin", 52),
|
||||
|
Loading…
Reference in New Issue
Block a user