From b8d6985dcad8706bf7b7b4cfa0f455212fdb7ccc Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 9 Oct 2020 18:39:21 +0200 Subject: [PATCH 1/6] tools: idf_exe: quote idf.py path --- tools/ci/check_copyright_ignore.txt | 1 - tools/windows/idf_exe/CMakeLists.txt | 2 +- tools/windows/idf_exe/idf_main.c | 24 ++++++++---------------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 0f467a11ec..f499de4cc4 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -4193,4 +4193,3 @@ tools/unit-test-app/tools/CreateSectionTable.py tools/unit-test-app/tools/UnitTestParser.py tools/unit-test-app/unit_test.py tools/windows/eclipse_make.py -tools/windows/idf_exe/idf_main.c diff --git a/tools/windows/idf_exe/CMakeLists.txt b/tools/windows/idf_exe/CMakeLists.txt index 7693412e91..95fda81c60 100644 --- a/tools/windows/idf_exe/CMakeLists.txt +++ b/tools/windows/idf_exe/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.5) project(idfexe) -set(VERSION 1.0.1) +set(VERSION 1.0.2) set(ARCHIVE_NAME idf-exe-v${VERSION}.zip) add_executable(idf idf_main.c) diff --git a/tools/windows/idf_exe/idf_main.c b/tools/windows/idf_exe/idf_main.c index cbfcf7990f..59f0350031 100644 --- a/tools/windows/idf_exe/idf_main.c +++ b/tools/windows/idf_exe/idf_main.c @@ -1,16 +1,8 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at", -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License +/* + * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include @@ -76,13 +68,13 @@ int main(int argc, LPTSTR argv[]) } } - /* Prepare the command line: python.exe %IDF_PATH%\\tools\idf.py */ + /* Prepare the command line: python.exe "%IDF_PATH%\\tools\idf.py" */ TCHAR cmdline[LINESIZE] = {}; - StringCchCat(cmdline, sizeof(cmdline), TEXT("python.exe ")); + StringCchCat(cmdline, sizeof(cmdline), TEXT("python.exe \"")); StringCchCat(cmdline, sizeof(cmdline), idf_path); StringCchCat(cmdline, sizeof(cmdline), TEXT("\\tools\\")); StringCchCat(cmdline, sizeof(cmdline), idfpy_script_name); - StringCchCat(cmdline, sizeof(cmdline), TEXT(" ")); + StringCchCat(cmdline, sizeof(cmdline), TEXT("\" ")); for (int i = 1; i < argc; ++i) { StringCchCat(cmdline, sizeof(cmdline), argv[i]); StringCchCat(cmdline, sizeof(cmdline), TEXT(" ")); From ffb708d403a97be2acf00226b5efb79ef1be38f5 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 29 Sep 2021 19:43:50 +0200 Subject: [PATCH 2/6] tools: idf_exe: compatibility with MSVC --- tools/windows/idf_exe/CMakeLists.txt | 2 +- tools/windows/idf_exe/idf_main.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/windows/idf_exe/CMakeLists.txt b/tools/windows/idf_exe/CMakeLists.txt index 95fda81c60..f0b5dd915a 100644 --- a/tools/windows/idf_exe/CMakeLists.txt +++ b/tools/windows/idf_exe/CMakeLists.txt @@ -7,7 +7,7 @@ set(ARCHIVE_NAME idf-exe-v${VERSION}.zip) add_executable(idf idf_main.c) target_compile_definitions(idf PRIVATE -DVERSION=\"${VERSION}\") set_target_properties(idf PROPERTIES C_STANDARD 99) -target_link_libraries(idf "-lshlwapi") +target_link_libraries(idf "shlwapi") if(CMAKE_BUILD_TYPE STREQUAL Release) add_custom_command(TARGET idf diff --git a/tools/windows/idf_exe/idf_main.c b/tools/windows/idf_exe/idf_main.c index 59f0350031..b40465b2bd 100644 --- a/tools/windows/idf_exe/idf_main.c +++ b/tools/windows/idf_exe/idf_main.c @@ -11,7 +11,11 @@ #define LINESIZE 1024 +#ifdef __GNUC__ static void fail(LPCSTR message, ...) __attribute__((noreturn)); +#else +__declspec(noreturn) static void fail(LPCSTR message, ...); +#endif static void fail(LPCSTR message, ...) { @@ -58,7 +62,7 @@ int main(int argc, LPTSTR argv[]) LPCTSTR idfpy_script_name = TEXT("idf.py"); /* Get IDF_PATH */ - TCHAR idf_path[LINESIZE] = {}; + TCHAR idf_path[LINESIZE] = { 0 }; if (GetEnvironmentVariable(TEXT("IDF_PATH"), idf_path, sizeof(idf_path)) == 0) { DWORD err = GetLastError(); if (err == ERROR_ENVVAR_NOT_FOUND) { @@ -69,7 +73,7 @@ int main(int argc, LPTSTR argv[]) } /* Prepare the command line: python.exe "%IDF_PATH%\\tools\idf.py" */ - TCHAR cmdline[LINESIZE] = {}; + TCHAR cmdline[LINESIZE] = { 0 }; StringCchCat(cmdline, sizeof(cmdline), TEXT("python.exe \"")); StringCchCat(cmdline, sizeof(cmdline), idf_path); StringCchCat(cmdline, sizeof(cmdline), TEXT("\\tools\\")); From 79f2e68bc0fd500411d89a61ee403fe100768675 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 9 Oct 2020 18:39:40 +0200 Subject: [PATCH 3/6] tools: update idf_exe to 1.0.2 to fix path quoting issue --- tools/tools.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/tools.json b/tools/tools.json index ebae20362c..8ec0c2d620 100644 --- a/tools/tools.json +++ b/tools/tools.json @@ -625,17 +625,17 @@ "version_regex": "([0-9.]+)", "versions": [ { - "name": "1.0.1", + "name": "1.0.2", "status": "recommended", "win32": { - "sha256": "53eb6aaaf034cc7ed1a97d5c577afa0f99815b7793905e9408e74012d357d04a", - "size": 11297, - "url": "https://dl.espressif.com/dl/idf-exe-v1.0.1.zip" + "sha256": "93d45466cd2c86231f0693a60f68833db7bc63da17e876b2a64298a8869b916f", + "size": 7223, + "url": "https://dl.espressif.com/dl/idf-exe-v1.0.2.zip" }, "win64": { - "sha256": "53eb6aaaf034cc7ed1a97d5c577afa0f99815b7793905e9408e74012d357d04a", - "size": 11297, - "url": "https://dl.espressif.com/dl/idf-exe-v1.0.1.zip" + "sha256": "93d45466cd2c86231f0693a60f68833db7bc63da17e876b2a64298a8869b916f", + "size": 7223, + "url": "https://dl.espressif.com/dl/idf-exe-v1.0.2.zip" } } ] From a038fb24bd3c0021c4f8579d6cca8846e9a8cc0b Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 9 Oct 2020 17:40:57 +0200 Subject: [PATCH 4/6] tools: {export,install}.sh: fix quoting issues --- export.sh | 9 ++++++--- install.sh | 11 ++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/export.sh b/export.sh index da23d1f248..d97dffb1ab 100644 --- a/export.sh +++ b/export.sh @@ -111,16 +111,19 @@ __main() { then path_prefix=${PATH%%${old_path}} # shellcheck disable=SC2169,SC2039 # unreachable with 'dash' - paths="${path_prefix//:/ }" - if [ -n "${paths}" ]; then + if [ -n "${path_prefix}" ]; then __verbose "Added the following directories to PATH:" else __verbose "All paths are already set." fi - for path_entry in ${paths} + old_ifs="$IFS" + IFS=":" + for path_entry in ${path_prefix} do __verbose " ${path_entry}" done + IFS="$old_ifs" + unset old_ifs else __verbose "Updated PATH variable:" __verbose " ${PATH}" diff --git a/install.sh b/install.sh index ab37e78db7..b45ade95af 100755 --- a/install.sh +++ b/install.sh @@ -3,10 +3,12 @@ set -e set -u -export IDF_PATH=$(cd $(dirname $0); pwd) +basedir=$(dirname "$0") +IDF_PATH=$(cd "${basedir}"; pwd) +export IDF_PATH echo "Detecting the Python interpreter" -. ${IDF_PATH}/tools/detect_python.sh +. "${IDF_PATH}/tools/detect_python.sh" if [ "$#" -eq 0 ]; then TARGETS="all" @@ -14,12 +16,11 @@ else TARGETS=$1 fi echo "Installing ESP-IDF tools" -${ESP_PYTHON} ${IDF_PATH}/tools/idf_tools.py install --targets=${TARGETS} +"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" install --targets=${TARGETS} echo "Installing Python environment and packages" -${ESP_PYTHON} ${IDF_PATH}/tools/idf_tools.py install-python-env +"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" install-python-env -basedir="$(dirname $0)" echo "All done! You can now run:" echo "" echo " . ${basedir}/export.sh" From 94f4cfe99bdba53e9f63dce3be9321d1c42ce5cf Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 6 Oct 2021 11:06:22 +0200 Subject: [PATCH 5/6] tools: {install, export}.bat: fix path quoting Also includes fix for DOSKEY definitions. Closes https://github.com/espressif/esp-idf/issues/7605 --- export.bat | 25 ++++++++++++------------- install.bat | 4 ++-- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/export.bat b/export.bat index ce3473cce3..1cfedfc39b 100644 --- a/export.bat +++ b/export.bat @@ -14,21 +14,14 @@ if %errorlevel% neq 0 set "MISSING_REQUIREMENTS=%MISSING_REQUIREMENTS% git" if not "%MISSING_REQUIREMENTS%" == "" goto :__error_missing_requirements -set PREFIX=python.exe %IDF_PATH% -DOSKEY idf.py=%PREFIX%\tools\idf.py $* -DOSKEY esptool.py=%PREFIX%\components\esptool_py\esptool\esptool.py $* -DOSKEY espefuse.py=%PREFIX%\components\esptool_py\esptool\espefuse.py $* -DOSKEY otatool.py=%PREFIX%\components\app_update\otatool.py $* -DOSKEY parttool.py=%PREFIX%\components\partition_table\parttool.py $* - :: 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 +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. @@ -38,7 +31,7 @@ echo Adding ESP-IDF tools to PATH... :: 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%" +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 ( @@ -51,8 +44,14 @@ call set PATH_ADDITIONS=%%PATH:%OLD_PATH%=%% if "%PATH_ADDITIONS%"=="" call :__print_nothing_added if not "%PATH_ADDITIONS%"=="" echo %PATH_ADDITIONS:;=&echo. % +DOSKEY idf.py=python.exe "%IDF_PATH%\tools\idf.py" $* +DOSKEY esptool.py=python.exe "%IDF_PATH%\components\esptool_py\esptool\esptool.py" $* +DOSKEY espefuse.py=python.exe "%IDF_PATH%\components\esptool_py\esptool\espefuse.py" $* +DOSKEY otatool.py=python.exe "%IDF_PATH%\components\app_update\otatool.py" $* +DOSKEY parttool.py=python.exe "%IDF_PATH%\components\partition_table\parttool.py" $* + echo Checking if Python packages are up to date... -python.exe %IDF_PATH%\tools\check_python_dependencies.py +python.exe "%IDF_PATH%\tools\check_python_dependencies.py" if %errorlevel% neq 0 goto :__end echo. diff --git a/install.bat b/install.bat index 8ca5ae0d16..df058f1ef1 100644 --- a/install.bat +++ b/install.bat @@ -22,11 +22,11 @@ set TARGETS="all" if NOT "%1"=="" set TARGETS=%* echo Installing ESP-IDF tools -python.exe %IDF_PATH%\tools\idf_tools.py install --targets=%TARGETS% +python.exe "%IDF_PATH%\tools\idf_tools.py" install --targets=%TARGETS% if %errorlevel% neq 0 goto :end echo Setting up Python environment -python.exe %IDF_PATH%\tools\idf_tools.py install-python-env +python.exe "%IDF_PATH%\tools\idf_tools.py" install-python-env if %errorlevel% neq 0 goto :end echo All done! You can now run: From 2c375458abd421a6d985506a286fdbc2fd9cbfbd Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 14 Oct 2021 09:44:16 +0200 Subject: [PATCH 6/6] export.sh: fix undefined reference to realpath after renaming --- export.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/export.sh b/export.sh index d97dffb1ab..c09f8592bd 100644 --- a/export.sh +++ b/export.sh @@ -52,7 +52,7 @@ __main() { # shellcheck disable=SC2169,SC2169,SC2039 # unreachable with 'dash' if [[ "$OSTYPE" == "darwin"* ]]; then # convert possibly relative path to absolute - script_dir="$(realpath_int "${self_path}")" + script_dir="$(__realpath "${self_path}")" # resolve any ../ references to make the path shorter script_dir="$(cd "${script_dir}" || exit 1; pwd)" else