Skip to content

Commit cad15b5

Browse files
Marek Fialaespressif-bot
Marek Fiala
authored andcommitted
feat(tools): Inform user about IDF_PATH set/change in install/export scripts
1 parent ab3d179 commit cad15b5

File tree

12 files changed

+37
-19
lines changed

12 files changed

+37
-19
lines changed

Diff for: docs/en/api-guides/tools/idf-tools.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Since the installed tools are not permanently added to the user or system ``PATH
184184

185185
To modify the shell environment in Bash, ``export.sh`` must be "sourced" by using the ``. ./export.sh`` command. Please ensure to include the leading dot and space.
186186

187-
``export.sh`` may be used with shells other than Bash (such as zsh). However, in this case, it is required to set the ``IDF_PATH`` environment variable before running the script. When used in Bash, the script guesses the ``IDF_PATH`` value from its own location.
187+
``export.sh`` may be used with various shells like Bash, Zsh, sh, dash, etc. When using Bash or Zsh, you can run it from any path (e.g., ``. ./<<some_path>>/export.sh``) as it automatically detects IDF_PATH. For other shells, it must be run from the ESP-IDF directory (``. ./export.sh``) to locate IDF_PATH correctly.
188188

189189
activate.py
190190
~~~~~~~~~~~

Diff for: export.bat

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ if not exist "%IDF_PATH%\tools\activate.py" (
4747
)
4848

4949

50-
for /f "delims=" %%i in ('python "%IDF_PATH%/tools/activate.py" --export') do set activate=%%i
50+
for /f "delims=" %%i in ('python "%IDF_PATH%\tools\activate.py" --export') do set activate=%%i
5151
%activate%
5252

5353
goto :__end
@@ -64,8 +64,8 @@ goto :__end
6464
goto :__end
6565

6666
:__missing_file
67-
echo Could not detect correct IDF_PATH. Please set it before running this script:
68-
echo set IDF_PATH=(add path here)
67+
echo Could not detect IDF_PATH. Please navigate to your ESP-IDF directory and run:
68+
echo export.bat
6969
goto :__end
7070

7171
:__end

Diff for: export.fish

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ set idf_path (dirname (realpath (status -f)))
1717
if not test -f "$idf_path/tools/idf.py"
1818
or not test -f "$idf_path/tools/idf_tools.py"
1919
or not test -f "$idf_path/tools/activate.py"
20-
echo "Could not detect IDF_PATH. Please set it before sourcing this script:"
21-
echo " export IDF_PATH=(add path here)"
20+
echo "Could not detect IDF_PATH. Please navigate to your ESP-IDF directory and run:"
21+
echo ". ./export.fish"
2222
set -e idf_path
2323
exit 1
2424
end

Diff for: export.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ if (-not (Test-Path "$idf_path/tools/idf.py") -or
1313
-not (Test-Path "$idf_path/tools/idf_tools.py") -or
1414
-not (Test-Path "$idf_path/tools/activate.py")) {
1515

16-
Write-Output "Could not detect IDF_PATH. Please set it before running this script:"
17-
Write-Output ' $env:IDF_PATH=(add path here)'
16+
Write-Output "Could not detect IDF_PATH. Please navigate to your ESP-IDF directory and run:"
17+
Write-Output ".\export.ps1"
1818

1919
$env:IDF_PATH = ""
2020

Diff for: export.sh

+4-7
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,14 @@ then
3232
# shellcheck disable=SC2296 # ignore parameter starts with '{' because it's zsh
3333
idf_path=$(dirname "${(%):-%x}")
3434
shell_type="zsh"
35-
elif test -n "${IDF_PATH-}"
36-
then
37-
idf_path=$IDF_PATH
3835
fi
3936

4037
if [ ! -f "${idf_path}/tools/idf.py" ] ||
41-
[ ! -f "${idf_path}/tools/idf_tools.py" ] ||
42-
[ ! -f "${idf_path}/tools/activate.py" ]
38+
[ ! -f "${idf_path}/tools/idf_tools.py" ] ||
39+
[ ! -f "${idf_path}/tools/activate.py" ]
4340
then
44-
echo "Could not detect IDF_PATH. Please set it before sourcing this script:"
45-
echo " export IDF_PATH=(add path here)"
41+
echo "Could not detect IDF_PATH. Please navigate to your ESP-IDF directory and run:"
42+
echo ". ./export.sh"
4643
unset idf_path
4744
return 1
4845
fi

Diff for: install.bat

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ if defined MSYSTEM (
33
echo This .bat file is for Windows CMD.EXE shell only.
44
goto :__end
55
)
6+
:: Set local ensures that variables like IDF_PATH are not changed/propagated out of the script
7+
setlocal
68

79
set SCRIPT_EXIT_CODE=0
810

@@ -30,6 +32,8 @@ if /I "%1" == "/?" goto :__help
3032
if /I "%1" == "-h" goto :__help
3133
if /I "%1" == "--help" goto :__help
3234

35+
echo INFO: Using IDF_PATH '%IDF_PATH%' for installation.
36+
3337
for /f "delims=" %%i in ('python.exe "%IDF_PATH%\tools\install_util.py" extract targets "%*"') do set TARGETS=%%i
3438

3539
echo Installing ESP-IDF tools

Diff for: install.fish

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ set basedir (realpath (dirname (status -f)))
44

55
set -x IDF_PATH $basedir
66

7+
echo "INFO: Using IDF_PATH '$IDF_PATH' for installation."
8+
79
echo "Detecting the Python interpreter"
810
source "$IDF_PATH"/tools/detect_python.fish
911

@@ -27,7 +29,7 @@ or exit 1
2729
set FEATURES ("$ESP_PYTHON" "$IDF_PATH"/tools/install_util.py extract features $argv) || exit 1
2830

2931
echo "Installing Python environment and packages"
30-
"$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py install-python-env --features=$FEATURES
32+
"$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py install-python-env --features=$FEATURES || exit 1
3133

3234
echo "All done! You can now run:"
3335
echo ""

Diff for: install.ps1

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@ python "$IDF_PATH/tools/install_util.py" print_help ps1
1111
Exit
1212
}
1313

14+
Write-Output "INFO: Using IDF_PATH '$IDF_PATH' for installation."
15+
1416
$TARGETS = (python "$IDF_PATH/tools/install_util.py" extract targets "$args")
1517

1618
Write-Output "Installing ESP-IDF tools"
17-
$proces_tools = Start-Process -Wait -PassThru -NoNewWindow -FilePath "python" -Args "`"$IDF_PATH/tools/idf_tools.py`" install --targets=${TARGETS}"
19+
# PowerShell does not propagate variables to new process (spawned python), so we pass detected IDF_PATH as argument
20+
# to avoid using any previously set IDF_PATH values in the terminal environment.
21+
$proces_tools = Start-Process -Wait -PassThru -NoNewWindow -FilePath "python" -Args "`"$IDF_PATH/tools/idf_tools.py`" --idf-path ${IDF_PATH} install --targets=${TARGETS}"
1822
$exit_code_tools = $proces_tools.ExitCode
1923
if ($exit_code_tools -ne 0) { exit $exit_code_tools } # if error
2024

2125
$FEATURES = (python "$IDF_PATH/tools/install_util.py" extract features "$args")
2226

2327
Write-Output "Setting up Python environment"
24-
$proces_py_env = Start-Process -Wait -PassThru -NoNewWindow -FilePath "python" -Args "`"$IDF_PATH/tools/idf_tools.py`" install-python-env --features=${FEATURES}"
28+
# PowerShell does not propagate variables to new process (spawned python), so we pass detected IDF_PATH as argument
29+
# to avoid using any previously set IDF_PATH values in the terminal environment.
30+
$proces_py_env = Start-Process -Wait -PassThru -NoNewWindow -FilePath "python" -Args "`"$IDF_PATH/tools/idf_tools.py`" --idf-path ${IDF_PATH} install-python-env --features=${FEATURES}"
2531
$exit_code_py_env = $proces_py_env.ExitCode
2632
if ($exit_code_py_env -ne 0) { exit $exit_code_py_env } # if error
2733

Diff for: install.sh

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ basedir=$(dirname "$0")
77
IDF_PATH=$(cd "${basedir}"; pwd -P)
88
export IDF_PATH
99

10+
echo "INFO: Using IDF_PATH '${IDF_PATH}' for installation."
11+
1012
echo "Detecting the Python interpreter"
1113
. "${IDF_PATH}/tools/detect_python.sh"
1214

Diff for: tools/activate.py

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def die(msg: str) -> None:
3333
idf_tools.g.idf_tools_path = os.environ.get('IDF_TOOLS_PATH') or os.path.expanduser(idf_tools.IDF_TOOLS_PATH_DEFAULT)
3434
idf_python_env_path, idf_python_export_path, virtualenv_python, idf_version = idf_tools.get_python_env_path()
3535

36+
os.environ['IDF_PATH_OLD'] = os.environ.get('IDF_PATH', '')
3637
os.environ['IDF_PATH'] = idf_path
3738
os.environ['IDF_PYTHON_ENV_PATH'] = idf_python_env_path
3839
os.environ['ESP_IDF_VERSION'] = idf_version

Diff for: tools/export_utils/activate_venv.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from console_output import eprint
1414
from console_output import oprint
1515
from console_output import status_message
16+
from console_output import warn
1617
from shell_types import SHELL_CLASSES
1718
from shell_types import SUPPORTED_SHELLS
1819
from utils import conf
@@ -161,7 +162,11 @@ def main() -> None:
161162
sys.exit()
162163

163164
eprint(f'[dark_orange]Activating ESP-IDF {conf.IDF_VERSION}')
164-
debug(f'IDF_PATH {conf.IDF_PATH}')
165+
if conf.IDF_PATH_OLD and conf.IDF_PATH != conf.IDF_PATH_OLD:
166+
warn(f"IDF_PATH is changed from '{conf.IDF_PATH_OLD}' to '{conf.IDF_PATH}'.")
167+
else:
168+
eprint(f"Setting IDF_PATH to '{conf.IDF_PATH}'.")
169+
165170
debug(f'IDF_PYTHON_ENV_PATH {conf.IDF_PYTHON_ENV_PATH}')
166171

167172
check_python_version()

Diff for: tools/export_utils/utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Config:
1717
"""
1818
def __init__(self) -> None:
1919
self.IDF_PATH = os.environ['IDF_PATH']
20+
self.IDF_PATH_OLD = os.environ['IDF_PATH_OLD']
2021
self.IDF_VERSION = os.environ['ESP_IDF_VERSION']
2122
self.IDF_PYTHON_ENV_PATH = os.environ['IDF_PYTHON_ENV_PATH']
2223
self.IDF_TOOLS_PY = os.path.join(self.IDF_PATH, 'tools', 'idf_tools.py')

0 commit comments

Comments
 (0)