From 22bc45606f600154ae7bd84d294f94c685352357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berthold=20H=C3=B6llmann?= Date: Sun, 22 Sep 2024 20:51:45 +0200 Subject: [PATCH 1/6] Improved Sming installation - Support for linux platforms not providing apt or dnf. Installation script searches for required tools and list missing. - Better support for installing outside "/opt". esp and rp2040 tools are not installed in "/opt" if Sming isn't. --- .gitignore | 6 ++++++ Sming/Arch/Esp32/Tools/install.sh | 23 +++++++++++++++++++++++ Tools/export.sh | 11 ++++++----- Tools/install.sh | 24 ++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 180c1a5cc0..1a46d1347a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,9 @@ GPATH .submodule *.built *.completed + +/esp-idf* +/esp-quick-toolchain/ +/esp32/ +/rp2040/ +/samples/Basic_Serial/files/ diff --git a/Sming/Arch/Esp32/Tools/install.sh b/Sming/Arch/Esp32/Tools/install.sh index 0a872db39d..b563e0ccd3 100755 --- a/Sming/Arch/Esp32/Tools/install.sh +++ b/Sming/Arch/Esp32/Tools/install.sh @@ -31,6 +31,29 @@ case $DIST in darwin) ;; + *) + _OK=1 + _COMMANDS=(dfu-util bison flex gperf) + for _COMMAND in "${_COMMANDS[@]}"; do + if ! [ -x "$(command -v ${_COMMAND})" ]; then + _OK=0 + echo "Install programm ${_COMMAND}" + fi + done + _INCLUDES=("/usr/include/ffi.h" "/usr/include/ssl/ssl.h") + for _INCLUDE in "${_INCLUDES[@]}"; do + if ! [ -f "${_INCLUDE}" ]; then + _OK=0 + echo "Install development package providing ${_INCLUDE}" + fi + done + if [ $_OK != 1 ]; then + echo "ABORTING" + exit 1 + fi + PACKAGES=() + ;; + esac $PKG_INSTALL "${PACKAGES[@]}" diff --git a/Tools/export.sh b/Tools/export.sh index 602bc4423a..f52b5449d7 100755 --- a/Tools/export.sh +++ b/Tools/export.sh @@ -24,7 +24,8 @@ if [ -z "$SMING_HOME" ]; then else _SOURCEDIR=$(dirname "${BASH_SOURCE[0]}") fi - SMING_HOME=$(realpath "$_SOURCEDIR/../Sming") + _SMIG_BASE=$(realpath "$_SOURCEDIR/..") + SMING_HOME=${_SMIG_BASE}"/Sming" export SMING_HOME echo "SMING_HOME: $SMING_HOME" fi @@ -33,14 +34,14 @@ fi export PYTHON=${PYTHON:=$(which python3)} # Esp8266 -export ESP_HOME=${ESP_HOME:=/opt/esp-quick-toolchain} +export ESP_HOME=${ESP_HOME:=${_SMIG_BASE}/esp-quick-toolchain} # Esp32 -export IDF_PATH=${IDF_PATH:=/opt/esp-idf} -export IDF_TOOLS_PATH=${IDF_TOOLS_PATH:=/opt/esp32} +export IDF_PATH=${IDF_PATH:=${_SMIG_BASE}/esp-idf} +export IDF_TOOLS_PATH=${IDF_TOOLS_PATH:=${_SMIG_BASE}/esp32} # Rp2040 -export PICO_TOOLCHAIN_PATH=${PICO_TOOLCHAIN_PATH:=/opt/rp2040} +export PICO_TOOLCHAIN_PATH=${PICO_TOOLCHAIN_PATH:=${_SMIG_BASE}/rp2040} # Provide non-apple CLANG (e.g. for rbpf library) if [ -n "$GITHUB_ACTIONS" ] && [ "$(uname)" = "Darwin" ]; then diff --git a/Tools/install.sh b/Tools/install.sh index 4b85fd5dd1..b52b618e7c 100755 --- a/Tools/install.sh +++ b/Tools/install.sh @@ -99,12 +99,34 @@ elif [ -n "$(command -v dnf)" ]; then DIST=fedora PKG_INSTALL="sudo dnf install -y" else + _OK=1 echo "Unsupported distribution" + _REQUIRED_TOOLS=( + ccache \ + cmake \ + curl \ + git \ + make \ + ninja \ + unzip \ + g++ \ + python3 \ + pip3 \ + wget \ + ) + for _TOOL in "${_REQUIRED_TOOLS[@]}"; do + if ! [ -x "$(command -v $_TOOL)" ]; then + _OK=0 + echo "Install required tool ${_TOOL}" + fi + done + if [ $_OK != 1 ]; then if [ $sourced = 1 ]; then return 1 else exit 1 fi + fi fi # Common install @@ -183,9 +205,11 @@ case $DIST in esac +if [ $(/usr/bin/python -c "import sys;print(sys.version_info[0])") != 3 ]; then if [ "$DIST" != "darwin" ]; then sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 100 fi +fi set -e From 39bf1c7843db73a4537e90f894cc831161069f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berthold=20H=C3=B6llmann?= Date: Sun, 22 Sep 2024 21:26:14 +0200 Subject: [PATCH 2/6] Fixing Codacy Static Code Analysis --- Sming/Arch/Esp32/Tools/install.sh | 2 +- Tools/install.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sming/Arch/Esp32/Tools/install.sh b/Sming/Arch/Esp32/Tools/install.sh index b563e0ccd3..850d989cec 100755 --- a/Sming/Arch/Esp32/Tools/install.sh +++ b/Sming/Arch/Esp32/Tools/install.sh @@ -35,7 +35,7 @@ case $DIST in _OK=1 _COMMANDS=(dfu-util bison flex gperf) for _COMMAND in "${_COMMANDS[@]}"; do - if ! [ -x "$(command -v ${_COMMAND})" ]; then + if ! [ -x "$(command -v \"${_COMMAND}\")" ]; then _OK=0 echo "Install programm ${_COMMAND}" fi diff --git a/Tools/install.sh b/Tools/install.sh index b52b618e7c..b2657ff4d4 100755 --- a/Tools/install.sh +++ b/Tools/install.sh @@ -115,7 +115,7 @@ else wget \ ) for _TOOL in "${_REQUIRED_TOOLS[@]}"; do - if ! [ -x "$(command -v $_TOOL)" ]; then + if ! [ -x "$(command -v \"${_TOOL}\")" ]; then _OK=0 echo "Install required tool ${_TOOL}" fi From 32cdb63ddd334efbe1da470aed9562eae8506306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berthold=20H=C3=B6llmann?= Date: Sun, 22 Sep 2024 21:30:00 +0200 Subject: [PATCH 3/6] Fixing Codacy Static Code Analysis again --- Sming/Arch/Esp32/Tools/install.sh | 2 +- Tools/install.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sming/Arch/Esp32/Tools/install.sh b/Sming/Arch/Esp32/Tools/install.sh index 850d989cec..571a71bde6 100755 --- a/Sming/Arch/Esp32/Tools/install.sh +++ b/Sming/Arch/Esp32/Tools/install.sh @@ -35,7 +35,7 @@ case $DIST in _OK=1 _COMMANDS=(dfu-util bison flex gperf) for _COMMAND in "${_COMMANDS[@]}"; do - if ! [ -x "$(command -v \"${_COMMAND}\")" ]; then + if ! [ -x $(command -v "${_COMMAND}") ]; then _OK=0 echo "Install programm ${_COMMAND}" fi diff --git a/Tools/install.sh b/Tools/install.sh index b2657ff4d4..7dd3a00cec 100755 --- a/Tools/install.sh +++ b/Tools/install.sh @@ -115,7 +115,7 @@ else wget \ ) for _TOOL in "${_REQUIRED_TOOLS[@]}"; do - if ! [ -x "$(command -v \"${_TOOL}\")" ]; then + if ! [ -x $(command -v "${_TOOL}") ]; then _OK=0 echo "Install required tool ${_TOOL}" fi From 772f25a86a6405003a4dc4ea5486365a9ce14b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berthold=20H=C3=B6llmann?= Date: Mon, 23 Sep 2024 14:07:39 +0200 Subject: [PATCH 4/6] Reverted changes regarding tool installation paths Implemented comments regarding shell variable names I will handle tool installatin paths via direnv. My .envrc is simple: layout Sming With Sming extracte in my home directory my `~/.config/direnv/direnvrc` then contains: layout_Sming() { _SMIG_BASE=${HOME}/Sming _SMIG_TOOLS=${_SMIG_BASE}/.tools export ESP_HOME=${_SMIG_TOOLS}/esp-quick-toolchain export IDF_PATH=${_SMIG_TOOLS}/esp-idf export IDF_TOOLS_PATH=${_SMIG_TOOLS}/esp32 export PICO_TOOLCHAIN_PATH=${_SMIG_TOOLS}/rp2040 . ${_SMIG_BASE}/Tools/export.sh } --- .gitignore | 6 ----- Sming/Arch/Esp32/Tools/install.sh | 40 +++++++++++++++---------------- Tools/export.sh | 11 ++++----- Tools/install.sh | 14 +++++------ samples/Basic_Serial/.gitignore | 1 + 5 files changed, 33 insertions(+), 39 deletions(-) create mode 100644 samples/Basic_Serial/.gitignore diff --git a/.gitignore b/.gitignore index 1a46d1347a..180c1a5cc0 100644 --- a/.gitignore +++ b/.gitignore @@ -30,9 +30,3 @@ GPATH .submodule *.built *.completed - -/esp-idf* -/esp-quick-toolchain/ -/esp32/ -/rp2040/ -/samples/Basic_Serial/files/ diff --git a/Sming/Arch/Esp32/Tools/install.sh b/Sming/Arch/Esp32/Tools/install.sh index 571a71bde6..7e252ae1d5 100755 --- a/Sming/Arch/Esp32/Tools/install.sh +++ b/Sming/Arch/Esp32/Tools/install.sh @@ -32,26 +32,26 @@ case $DIST in ;; *) - _OK=1 - _COMMANDS=(dfu-util bison flex gperf) - for _COMMAND in "${_COMMANDS[@]}"; do - if ! [ -x $(command -v "${_COMMAND}") ]; then - _OK=0 - echo "Install programm ${_COMMAND}" - fi - done - _INCLUDES=("/usr/include/ffi.h" "/usr/include/ssl/ssl.h") - for _INCLUDE in "${_INCLUDES[@]}"; do - if ! [ -f "${_INCLUDE}" ]; then - _OK=0 - echo "Install development package providing ${_INCLUDE}" - fi - done - if [ $_OK != 1 ]; then - echo "ABORTING" - exit 1 - fi - PACKAGES=() + TOOLS_MISSING=0 + COMMANDS=(dfu-util bison flex gperf) + for COMMAND in "${COMMANDS[@]}"; do + if ! [ -x $(command -v "${COMMAND}") ]; then + TOOLS_MISSING=1 + echo "Install programm ${COMMAND}" + fi + done + INCLUDES=("/usr/include/ffi.h" "/usr/include/ssl/ssl.h") + for INCLUDE in "${INCLUDES[@]}"; do + if ! [ -f "${INCLUDE}" ]; then + TOOLS_MISSING=1 + echo "Install development package providing ${INCLUDE}" + fi + done + if [ $TOOLS_MISSING != 0 ]; then + echo "ABORTING" + exit 1 + fi + PACKAGES=() ;; esac diff --git a/Tools/export.sh b/Tools/export.sh index f52b5449d7..602bc4423a 100755 --- a/Tools/export.sh +++ b/Tools/export.sh @@ -24,8 +24,7 @@ if [ -z "$SMING_HOME" ]; then else _SOURCEDIR=$(dirname "${BASH_SOURCE[0]}") fi - _SMIG_BASE=$(realpath "$_SOURCEDIR/..") - SMING_HOME=${_SMIG_BASE}"/Sming" + SMING_HOME=$(realpath "$_SOURCEDIR/../Sming") export SMING_HOME echo "SMING_HOME: $SMING_HOME" fi @@ -34,14 +33,14 @@ fi export PYTHON=${PYTHON:=$(which python3)} # Esp8266 -export ESP_HOME=${ESP_HOME:=${_SMIG_BASE}/esp-quick-toolchain} +export ESP_HOME=${ESP_HOME:=/opt/esp-quick-toolchain} # Esp32 -export IDF_PATH=${IDF_PATH:=${_SMIG_BASE}/esp-idf} -export IDF_TOOLS_PATH=${IDF_TOOLS_PATH:=${_SMIG_BASE}/esp32} +export IDF_PATH=${IDF_PATH:=/opt/esp-idf} +export IDF_TOOLS_PATH=${IDF_TOOLS_PATH:=/opt/esp32} # Rp2040 -export PICO_TOOLCHAIN_PATH=${PICO_TOOLCHAIN_PATH:=${_SMIG_BASE}/rp2040} +export PICO_TOOLCHAIN_PATH=${PICO_TOOLCHAIN_PATH:=/opt/rp2040} # Provide non-apple CLANG (e.g. for rbpf library) if [ -n "$GITHUB_ACTIONS" ] && [ "$(uname)" = "Darwin" ]; then diff --git a/Tools/install.sh b/Tools/install.sh index 7dd3a00cec..ec22c8f3da 100755 --- a/Tools/install.sh +++ b/Tools/install.sh @@ -99,9 +99,9 @@ elif [ -n "$(command -v dnf)" ]; then DIST=fedora PKG_INSTALL="sudo dnf install -y" else - _OK=1 + TOOLS_MISSING=0 echo "Unsupported distribution" - _REQUIRED_TOOLS=( + REQUIRED_TOOLS=( ccache \ cmake \ curl \ @@ -114,13 +114,13 @@ else pip3 \ wget \ ) - for _TOOL in "${_REQUIRED_TOOLS[@]}"; do - if ! [ -x $(command -v "${_TOOL}") ]; then - _OK=0 - echo "Install required tool ${_TOOL}" + for TOOL in "${REQUIRED_TOOLS[@]}"; do + if ! [ -x $(command -v "${TOOL}") ]; then + TOOLS_MISSING=1 + echo "Install required tool ${TOOL}" fi done - if [ $_OK != 1 ]; then + if [ $TOOLS_MISSING != 0 ]; then if [ $sourced = 1 ]; then return 1 else diff --git a/samples/Basic_Serial/.gitignore b/samples/Basic_Serial/.gitignore new file mode 100644 index 0000000000..bb97907eef --- /dev/null +++ b/samples/Basic_Serial/.gitignore @@ -0,0 +1 @@ +/files/ From d3d24901ad55e7976c890a43c4afa8208f81ebb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berthold=20H=C3=B6llmann?= Date: Mon, 23 Sep 2024 14:56:05 +0200 Subject: [PATCH 5/6] Add shell functions to check for installed tools The new shell function `check_for_installed_tools` can be used to check for installed tools. the function takes a list of required executables for argument. Shell process is aborted if any of the tools is missing. All tools missing in the list are reported. Similar the the shell function `check_for_installed_files` checks for installed files, here used to make sure header files are installed. --- Sming/Arch/Esp32/Tools/install.sh | 22 ++---------- Tools/install.sh | 58 ++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/Sming/Arch/Esp32/Tools/install.sh b/Sming/Arch/Esp32/Tools/install.sh index 7e252ae1d5..f16026df59 100755 --- a/Sming/Arch/Esp32/Tools/install.sh +++ b/Sming/Arch/Esp32/Tools/install.sh @@ -32,25 +32,9 @@ case $DIST in ;; *) - TOOLS_MISSING=0 - COMMANDS=(dfu-util bison flex gperf) - for COMMAND in "${COMMANDS[@]}"; do - if ! [ -x $(command -v "${COMMAND}") ]; then - TOOLS_MISSING=1 - echo "Install programm ${COMMAND}" - fi - done - INCLUDES=("/usr/include/ffi.h" "/usr/include/ssl/ssl.h") - for INCLUDE in "${INCLUDES[@]}"; do - if ! [ -f "${INCLUDE}" ]; then - TOOLS_MISSING=1 - echo "Install development package providing ${INCLUDE}" - fi - done - if [ $TOOLS_MISSING != 0 ]; then - echo "ABORTING" - exit 1 - fi + check_for_installed_tools dfu-util bison flex gperf + + check_for_installed_files "/usr/include/ffi.h" "/usr/include/ssl/ssl.h" PACKAGES=() ;; diff --git a/Tools/install.sh b/Tools/install.sh index ec22c8f3da..2131453916 100755 --- a/Tools/install.sh +++ b/Tools/install.sh @@ -22,6 +22,46 @@ FONT_PACKAGES=(\ fonts-droid-fallback \ ) +check_for_installed_tools () { + REQUIRED_TOOLS="${@}" + echo -e "Checking for installed tools.\nrequirded tools: ${REQUIRED_TOOLS}" + TOOLS_MISSING=0 + for TOOL in ${REQUIRED_TOOLS}; do + if ! command -v "${TOOL}" > /dev/null ; then + TOOLS_MISSING=1 + echo "Install required tool ${TOOL}" + fi + done + if [ $TOOLS_MISSING != 0 ]; then + echo "ABORTING" + if [ $sourced = 1 ]; then + return 1 + else + exit 1 + fi + fi +} + +check_for_installed_files () { + REQUIRED_FILES="${@}" + echo -e "Checking for installed files.\nrequirded files: ${REQUIRED_FILES}" + FILES_MISSING=0 + for FILE in ${REQUIRED_FILES}; do + if ! [ -f "${FILE}" ]; then + FILES_MISSING=1 + echo "Install required FILE ${FILE}" + fi + done + if [ $FILES_MISSING != 0 ]; then + echo "ABORTING" + if [ $sourced = 1 ]; then + return 1 + else + exit 1 + fi + fi +} + EXTRA_PACKAGES=() OPTIONAL_PACKAGES=() @@ -101,7 +141,7 @@ elif [ -n "$(command -v dnf)" ]; then else TOOLS_MISSING=0 echo "Unsupported distribution" - REQUIRED_TOOLS=( + check_for_installed_tools \ ccache \ cmake \ curl \ @@ -112,21 +152,7 @@ else g++ \ python3 \ pip3 \ - wget \ - ) - for TOOL in "${REQUIRED_TOOLS[@]}"; do - if ! [ -x $(command -v "${TOOL}") ]; then - TOOLS_MISSING=1 - echo "Install required tool ${TOOL}" - fi - done - if [ $TOOLS_MISSING != 0 ]; then - if [ $sourced = 1 ]; then - return 1 - else - exit 1 - fi - fi + wget fi # Common install From b9b44264985a26f53ceb413d6542a5b8b662ee92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berthold=20H=C3=B6llmann?= Date: Tue, 24 Sep 2024 12:19:16 +0200 Subject: [PATCH 6/6] Applied latest code review comments --- Sming/Arch/Esp32/Tools/install.sh | 1 - Tools/install.sh | 84 +++++++++++++++---------------- 2 files changed, 42 insertions(+), 43 deletions(-) diff --git a/Sming/Arch/Esp32/Tools/install.sh b/Sming/Arch/Esp32/Tools/install.sh index f16026df59..3ead67befc 100755 --- a/Sming/Arch/Esp32/Tools/install.sh +++ b/Sming/Arch/Esp32/Tools/install.sh @@ -33,7 +33,6 @@ case $DIST in *) check_for_installed_tools dfu-util bison flex gperf - check_for_installed_files "/usr/include/ffi.h" "/usr/include/ssl/ssl.h" PACKAGES=() ;; diff --git a/Tools/install.sh b/Tools/install.sh index 2131453916..f43d0cd56b 100755 --- a/Tools/install.sh +++ b/Tools/install.sh @@ -22,46 +22,6 @@ FONT_PACKAGES=(\ fonts-droid-fallback \ ) -check_for_installed_tools () { - REQUIRED_TOOLS="${@}" - echo -e "Checking for installed tools.\nrequirded tools: ${REQUIRED_TOOLS}" - TOOLS_MISSING=0 - for TOOL in ${REQUIRED_TOOLS}; do - if ! command -v "${TOOL}" > /dev/null ; then - TOOLS_MISSING=1 - echo "Install required tool ${TOOL}" - fi - done - if [ $TOOLS_MISSING != 0 ]; then - echo "ABORTING" - if [ $sourced = 1 ]; then - return 1 - else - exit 1 - fi - fi -} - -check_for_installed_files () { - REQUIRED_FILES="${@}" - echo -e "Checking for installed files.\nrequirded files: ${REQUIRED_FILES}" - FILES_MISSING=0 - for FILE in ${REQUIRED_FILES}; do - if ! [ -f "${FILE}" ]; then - FILES_MISSING=1 - echo "Install required FILE ${FILE}" - fi - done - if [ $FILES_MISSING != 0 ]; then - echo "ABORTING" - if [ $sourced = 1 ]; then - return 1 - else - exit 1 - fi - fi -} - EXTRA_PACKAGES=() OPTIONAL_PACKAGES=() @@ -124,6 +84,47 @@ source "$(dirname "${BASH_SOURCE[0]}")/export.sh" export WGET="wget --no-verbose" +# Scripts for checking for required resources + +abort () { + echo "ABORTING" + if [ $sourced = 1 ]; then + return 1 + else + exit 1 + fi +} + +check_for_installed_tools() { + REQUIRED_TOOLS=( "$@" ) + echo -e "Checking for installed tools.\nRequired tools: ${REQUIRED_TOOLS[*]}" + TOOLS_MISSING=0 + for TOOL in "${REQUIRED_TOOLS[@]}"; do + if ! command -v "$TOOL" > /dev/null ; then + TOOLS_MISSING=1 + echo "Install required tool $TOOL" + fi + done + if [ $TOOLS_MISSING != 0 ]; then + abort + fi +} + +check_for_installed_files() { + REQUIRED_FILES=( "$@" ) + echo -e "Checking for installed files.\nRequired files: ${REQUIRED_FILES[*]}" + FILES_MISSING=0 + for FILE in "${REQUIRED_FILES[@]}"; do + if ! [ -f "$FILE" ]; then + FILES_MISSING=1 + echo "Install required FILE $FILE" + fi + done + if [ $FILES_MISSING != 0 ]; then + abort + fi +} + # Installers put downloaded archives here DOWNLOADS="downloads" mkdir -p $DOWNLOADS @@ -139,7 +140,6 @@ elif [ -n "$(command -v dnf)" ]; then DIST=fedora PKG_INSTALL="sudo dnf install -y" else - TOOLS_MISSING=0 echo "Unsupported distribution" check_for_installed_tools \ ccache \ @@ -231,7 +231,7 @@ case $DIST in esac -if [ $(/usr/bin/python -c "import sys;print(sys.version_info[0])") != 3 ]; then +if [ "$(/usr/bin/python -c 'import sys;print(sys.version_info[0])')" != 3 ]; then if [ "$DIST" != "darwin" ]; then sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 100 fi