From 85f2e18828c104864a18a673a0be3470b034f757 Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 16 Jan 2020 14:35:27 +0100 Subject: [PATCH] core: convert emu.sh to a simple dependency-less compat wrapper --- core/emu.sh | 41 +++++------------------- core/trezor_cmd.sh | 78 ---------------------------------------------- 2 files changed, 8 insertions(+), 111 deletions(-) delete mode 100644 core/trezor_cmd.sh diff --git a/core/emu.sh b/core/emu.sh index 4481de249..970d689a1 100755 --- a/core/emu.sh +++ b/core/emu.sh @@ -1,35 +1,10 @@ -#!/usr/bin/env bash +#!/bin/sh +PYOPT="${PYOPT:-1}" -MICROPYTHON="${MICROPYTHON:-${PWD}/build/unix/micropython}" -TREZOR_SRC=$(cd "${PWD}/src/"; pwd) -BROWSER="${BROWSER:-chromium}" +if [ -n "$1" ]; then + echo "This is just a compatibility wrapper. Use emu.py if you want features." + exit 1 +fi -source ./trezor_cmd.sh - -cd "${TREZOR_SRC}" - -case "$1" in - "-d") - shift - OPERATING_SYSTEM=$(uname) - if [ "$OPERATING_SYSTEM" = "Darwin" ]; then - PATH=/usr/bin /usr/bin/lldb -f $MICROPYTHON -- $ARGS $* $MAIN - else - gdb --args $MICROPYTHON $ARGS $* $MAIN - fi - ;; - "-r") - shift - while true; do - $MICROPYTHON $ARGS $* $MAIN & - UPY_PID=$! - find -name '*.py' | inotifywait -q -e close_write --fromfile - - echo Restarting ... - kill $UPY_PID - done - ;; - *) - echo "Starting emulator: $MICROPYTHON $ARGS $* $MAIN" - $MICROPYTHON $ARGS $* $MAIN 2>&1 | tee "${TREZOR_LOGFILE}" - exit ${PIPESTATUS[0]} -esac +cd src +../build/unix/micropython -O$PYOPT -X heapsize=20M -m main diff --git a/core/trezor_cmd.sh b/core/trezor_cmd.sh deleted file mode 100644 index cb96072f1..000000000 --- a/core/trezor_cmd.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env bash - -# expected inputs: -# TREZOR_SRC -- directory containing python code for uMP - -if [[ ! "${TREZOR_SRC}" ]]; then echo "expecting TREZOR_SRC"; exit 0; fi - -# optional inputs: -# TREZOR_PROFILE -- profile name (directory) in ~/.trezoremu or full path -# TREZOR_PROFILING -- wrap the uMP/python in the profiler script - -# outputs: -## uMP -# PYOPT -# HEAPSIZE -# ARGS -- uMP arguments -# MAIN -- uMP file to execute -## Trezor core -# TREZOR_PROFILE_DIR -# TREZOR_PROFILE_NAME -# TREZOR_UDP_PORT -## this script -# TREZOR_SRC -# TREZOR_LOGFILE -## python-trezor -# TREZOR_PATH -- connect string - - -# defaults -PYOPT="${PYOPT:-1}" -HEAPSIZE="${HEAPSIZE:-20M}" - -TREZOR_PROFILE="${TREZOR_PROFILE:-/var/tmp}" -TREZOR_PROFILE_DIR="${TREZOR_PROFILE}" -TREZOR_PROFILE_NAME="${TREZOR_PROFILE}" - -# for profile names create profile directory if not existent -if ! [[ "$TREZOR_PROFILE" == "/"* ]]; then - TREZOR_PROFILE_DIR="${HOME}/.trezoremu/${TREZOR_PROFILE}" - if ! [[ -d "${TREZOR_PROFILE_DIR}" ]]; then - mkdir -p "${TREZOR_PROFILE_DIR}" - PORT=$(( ( RANDOM % 1000 ) + 1 + 21324 )) - echo "# autogenerated config" > "${TREZOR_PROFILE_DIR}/emu.config" - echo "TREZOR_UDP_PORT=\"\${TREZOR_UDP_PORT:-${PORT}}\"" >> "${TREZOR_PROFILE_DIR}/emu.config" - fi -fi - -# load profile config -if [[ -f "${TREZOR_PROFILE_DIR}/emu.config" ]]; then - source "${TREZOR_PROFILE_DIR}/emu.config" -fi - -# for profiling wrap -if [[ "$TREZOR_PROFILING" -gt 0 ]]; then - MAIN="${TREZOR_SRC}/../prof/prof.py" -else - MAIN="${TREZOR_SRC}/main.py" -fi - -TREZOR_LOGFILE="${TREZOR_PROFILE_DIR}/trezor.log" -TREZOR_UDP_PORT="${TREZOR_UDP_PORT:-21324}" -TREZOR_PATH="${TREZOR_PATH:-udp:127.0.0.1:${TREZOR_UDP_PORT}}" - -echo "Trezor^emu profile name: ${TREZOR_PROFILE_NAME}" -echo "Trezor^emu profile directory: ${TREZOR_PROFILE_DIR}" -echo "Trezor^emu log file: ${TREZOR_LOGFILE}" -echo "Trezor^emu UDP port: ${TREZOR_UDP_PORT}" -echo "Trezor^emu path: ${TREZOR_PATH}" -echo "Trezor^emu src: ${TREZOR_SRC}" - -export TREZOR_PROFILE_NAME="${TREZOR_PROFILE_NAME}" -export TREZOR_PROFILE_DIR="${TREZOR_PROFILE_DIR}" -export TREZOR_LOGFILE="${TREZOR_LOGFILE}" -export TREZOR_UDP_PORT="${TREZOR_UDP_PORT}" -export TREZOR_PATH="${TREZOR_PATH}" -export TREZOR_SRC="${TREZOR_SRC}" - -ARGS="-O${PYOPT} -X heapsize=${HEAPSIZE}"