]> granicus.if.org Git - esp-idf/commitdiff
tools: {install,export}.{bat,sh} tools
authorIvan Grokhotkov <ivan@espressif.com>
Mon, 29 Apr 2019 02:37:02 +0000 (10:37 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Mon, 1 Jul 2019 12:51:44 +0000 (14:51 +0200)
add_path.sh
export.bat [new file with mode: 0644]
export.sh [new file with mode: 0644]
install.bat [new file with mode: 0644]
install.sh [new file with mode: 0755]
tools/ci/executable-list.txt

index bfc27bb49fa1541222183183a5f64cb17bbd66c3..f48c9b0c2c4e7ad880fdea1aa201ede0820e4db9 100644 (file)
@@ -9,8 +9,7 @@
 if [ -z ${IDF_PATH} ]; then
        echo "IDF_PATH must be set before including this script."
 else
-       IDF_ADD_PATHS_EXTRAS=
-       IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/esptool_py/esptool"
+       IDF_ADD_PATHS_EXTRAS="${IDF_PATH}/components/esptool_py/esptool"
        IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/espcoredump"
        IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/partition_table/"
        IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/tools/"
diff --git a/export.bat b/export.bat
new file mode 100644 (file)
index 0000000..51a3965
--- /dev/null
@@ -0,0 +1,70 @@
+@echo off
+if defined MSYSTEM (
+    echo This .bat file is for Windows CMD.EXE shell only. When using MSYS, run:
+    echo   . ./export.sh.
+    goto :eof
+)
+
+:: Infer IDF_PATH from script location
+set IDF_PATH=%~dp0
+set IDF_PATH=%IDF_PATH:~0,-1%
+
+set IDF_TOOLS_PY_PATH=%IDF_PATH%\tools\idf_tools.py
+set IDF_TOOLS_JSON_PATH=%IDF_PATH%\tools\tools.json
+set IDF_TOOLS_EXPORT_CMD=%IDF_PATH%\export.bat
+set IDF_TOOLS_INSTALL_CMD=%IDF_PATH%\install.bat
+echo Setting IDF_PATH: %IDF_PATH%
+echo.
+
+set "OLD_PATH=%PATH%"
+echo Adding ESP-IDF tools to PATH...
+:: Export tool paths and environment variables.
+:: It is possible to do this without a temporary file (running idf_tools.py from for /r command),
+:: but that way it is impossible to get the exit code of idf_tools.py.
+set "IDF_TOOLS_EXPORTS_FILE=%TEMP%\idf_export_vars.tmp"
+python.exe %IDF_PATH%\tools\idf_tools.py export --format key-value >"%IDF_TOOLS_EXPORTS_FILE%"
+if %errorlevel% neq 0 goto :end
+
+for /f "usebackq tokens=1,2 eol=# delims==" %%a in ("%IDF_TOOLS_EXPORTS_FILE%") do (
+      call set "%%a=%%b"
+    )
+
+:: This removes OLD_PATH substring from PATH, leaving only the paths which have been added,
+:: and prints semicolon-delimited components of the path on separate lines
+call set PATH_ADDITIONS=%%PATH:%OLD_PATH%=%%
+if "%PATH_ADDITIONS%"=="" call :print_nothing_added
+if not "%PATH_ADDITIONS%"=="" echo     %PATH_ADDITIONS:;=&echo.    %
+
+echo Checking if Python packages are up to date...
+python.exe %IDF_PATH%\tools\check_python_dependencies.py
+if %errorlevel% neq 0 goto :end
+
+echo.
+echo Done! You can now compile ESP-IDF projects.
+echo Go to the project directory and run:
+echo.
+echo   idf.py build
+echo.
+
+goto :end
+
+:print_nothing_added
+    echo No directories added to PATH:
+    echo.
+    echo %PATH%
+    echo.
+    goto :eof
+
+:end
+
+:: Clean up
+if not "%IDF_TOOLS_EXPORTS_FILE%"=="" (
+    del "%IDF_TOOLS_EXPORTS_FILE%" 1>nul 2>nul
+)
+set IDF_TOOLS_EXPORTS_FILE=
+set IDF_TOOLS_EXPORT_CMD=
+set IDF_TOOLS_INSTALL_CMD=
+set IDF_TOOLS_PY_PATH=
+set IDF_TOOLS_JSON_PATH=
+set OLD_PATH=
+set PATH_ADDITIONS=
diff --git a/export.sh b/export.sh
new file mode 100644 (file)
index 0000000..a136ab2
--- /dev/null
+++ b/export.sh
@@ -0,0 +1,82 @@
+# This script should be sourced, not executed.
+
+function idf_export_main() {
+    # The file doesn't have executable permissions, so this shouldn't really happen.
+    # Doing this in case someone tries to chmod +x it and execute...
+    if [[ -n "${BASH_SOURCE}" && ( "${BASH_SOURCE[0]}" == "${0}" ) ]]; then
+        echo "This script should be sourced, not executed:"
+        echo ". ${BASH_SOURCE[0]}"
+        return 1
+    fi
+
+    if [[ -z "${IDF_PATH}" ]]
+    then
+        # If using bash, try to guess IDF_PATH from script location
+        if [[ -n "${BASH_SOURCE}" ]]
+        then
+            script_name="$(readlink -f $BASH_SOURCE)"
+            export IDF_PATH="$(dirname ${script_name})"
+        else
+            echo "IDF_PATH must be set before sourcing this script"
+            return 1
+        fi
+    fi
+
+    old_path=$PATH
+
+    echo "Adding ESP-IDF tools to PATH..."
+    # Call idf_tools.py to export tool paths
+    export IDF_TOOLS_EXPORT_CMD=${IDF_PATH}/export.sh
+    export IDF_TOOLS_INSTALL_CMD=${IDF_PATH}/install.sh
+    idf_exports=$(${IDF_PATH}/tools/idf_tools.py export) || return 1
+    eval "${idf_exports}"
+
+    echo "Checking if Python packages are up to date..."
+    python ${IDF_PATH}/tools/check_python_dependencies.py || return 1
+
+
+    # Allow calling some IDF python tools without specifying the full path
+    # ${IDF_PATH}/tools is already added by 'idf_tools.py export'
+    IDF_ADD_PATHS_EXTRAS="${IDF_PATH}/components/esptool_py/esptool"
+    IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/espcoredump"
+    IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/partition_table/"
+    export PATH="${IDF_ADD_PATHS_EXTRAS}:${PATH}"
+
+    if [[ -n "$BASH" ]]
+    then
+        path_prefix=${PATH%%${old_path}}
+        paths="${path_prefix//:/ }"
+        if [ -n "${paths}" ]; then
+            echo "Added the following directories to PATH:"
+        else
+            echo "All paths are already set."
+        fi
+        for path_entry in ${paths}
+        do
+            echo "  ${path_entry}"
+        done
+    else
+        echo "Updated PATH variable:"
+        echo "  ${PATH}"
+    fi
+
+    # Clean up
+    unset old_path
+    unset paths
+    unset path_prefix
+    unset path_entry
+    unset IDF_ADD_PATHS_EXTRAS
+    unset idf_exports
+    # Not unsetting IDF_PYTHON_ENV_PATH, it can be used by IDF build system
+    # to check whether we are using a private Python environment
+
+    echo "Done! You can now compile ESP-IDF projects."
+    echo "Go to the project directory and run:"
+    echo ""
+    echo "  idf.py build"
+    echo ""
+}
+
+idf_export_main
+
+unset idf_export_main
diff --git a/install.bat b/install.bat
new file mode 100644 (file)
index 0000000..fdb9771
--- /dev/null
@@ -0,0 +1,19 @@
+@echo off
+if defined MSYSTEM (
+       echo This .bat file is for Windows CMD.EXE shell only. When using MSYS, run:
+       echo   ./install.sh.
+       goto end
+)
+:: Infer IDF_PATH from script location
+set IDF_PATH=%~dp0
+set IDF_PATH=%IDF_PATH:~0,-1%
+
+echo Installing ESP-IDF tools
+python.exe %IDF_PATH%\tools\idf_tools.py install
+
+echo Setting up Python environment
+python.exe %IDF_PATH%\tools\idf_tools.py install-python-env
+
+echo All done! You can now run:
+echo    export.bat
+:: Clean up
diff --git a/install.sh b/install.sh
new file mode 100755 (executable)
index 0000000..d026e3c
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+
+set -e
+set -u
+
+export IDF_PATH=$(cd $(dirname $0); pwd)
+
+echo "Installing ESP-IDF tools"
+${IDF_PATH}/tools/idf_tools.py install
+
+echo "Installing Python environment and packages"
+${IDF_PATH}/tools/idf_tools.py install-python-env
+
+basedir="$(dirname $0)"
+echo "All done! You can now run:"
+echo ""
+echo "  . ${basedir}/export.sh"
+echo ""
index fa86287ccafa374db2387f6b28b757e6433a4d27..a3b2845577b056b64cf430e56b77de224f5a837d 100644 (file)
@@ -26,6 +26,7 @@ examples/storage/parttool/parttool_example.sh
 examples/system/ota/otatool/get_running_partition.py
 examples/system/ota/otatool/otatool_example.py
 examples/system/ota/otatool/otatool_example.sh
+install.sh
 tools/check_kconfigs.py
 tools/check_python_dependencies.py
 tools/ci/apply_bot_filter.py