mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
feat(tools): Add backup option to use legacy export script
This feature serves as an immediate fix in case the new export approach causes issues. The user can simply set the environment variable `ESP_IDF_LEGACY_EXPORT`, and the old export script will be used.
This commit is contained in:
parent
88527faff8
commit
7b417fc3f2
@ -6,6 +6,14 @@ if defined MSYSTEM (
|
||||
|
||||
set SCRIPT_EXIT_CODE=0
|
||||
|
||||
:: Emergency backup option to use previous export.bat (export_legacy.bat) if the new export approach fails.
|
||||
:: To use it, set environmental variable like: set ESP_IDF_LEGACY_EXPORT=1
|
||||
if not "%ESP_IDF_LEGACY_EXPORT%"=="" (
|
||||
tools\legacy_exports\export_legacy.bat
|
||||
set SCRIPT_EXIT_CODE=%errorlevel%
|
||||
goto :eof
|
||||
)
|
||||
|
||||
:: Missing requirements check
|
||||
set MISSING_REQUIREMENTS=
|
||||
python.exe --version >NUL 2>NUL
|
||||
|
@ -5,6 +5,13 @@ function unset
|
||||
set --erase $argv
|
||||
end
|
||||
|
||||
# Emergency backup option to use previous export.fish (export_legacy.fish) if the new export approach fails.
|
||||
# To use it, set environmental variable like: export ESP_IDF_LEGACY_EXPORT=1
|
||||
if test -n "$ESP_IDF_LEGACY_EXPORT"
|
||||
source tools/legacy_exports/export_legacy.fish
|
||||
exit $status
|
||||
end
|
||||
|
||||
set idf_path (dirname (realpath (status -f)))
|
||||
|
||||
if not test -f "$idf_path/tools/idf.py"
|
||||
|
@ -1,5 +1,12 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
# Emergency backup option to use previous export.ps1 (export_legacy.ps1) if the new export approach fails.
|
||||
# To use it, set environmental variable like: $Env:ESP_IDF_LEGACY_EXPORT=1
|
||||
if ($env:ESP_IDF_LEGACY_EXPORT) {
|
||||
. ./tools/legacy_exports/export_legacy.ps1
|
||||
exit $LASTEXITCODE
|
||||
}
|
||||
|
||||
$idf_path = "$PSScriptRoot"
|
||||
|
||||
if (-not (Test-Path "$idf_path/tools/idf.py") -or
|
||||
|
@ -1,5 +1,12 @@
|
||||
# This script should be sourced, not executed.
|
||||
|
||||
# Emergency backup option to use previous export.sh (export_legacy.sh) if the new export approach fails.
|
||||
# To use it, set environmental variable like: export ESP_IDF_LEGACY_EXPORT=1
|
||||
if [ -n "${ESP_IDF_LEGACY_EXPORT-}" ]; then
|
||||
. ./tools/legacy_exports/export_legacy.sh
|
||||
return $?
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2128,SC2169,SC2039,SC3054 # ignore array expansion warning
|
||||
if [ -n "${BASH_SOURCE-}" ] && [ "${BASH_SOURCE[0]}" = "${0}" ]
|
||||
then
|
||||
|
@ -51,3 +51,7 @@ tools/esp_prov/**/*
|
||||
tools/ci/sort_yaml.py
|
||||
tools/ci/sg_rules/*
|
||||
tools/ci/previous_stage_job_status.py
|
||||
tools/legacy_exports/export_legacy.fish
|
||||
tools/legacy_exports/export_legacy.sh
|
||||
tools/legacy_exports/export_legacy.ps1
|
||||
tools/legacy_exports/export_legacy.bat
|
||||
|
129
tools/legacy_exports/export_legacy.bat
Normal file
129
tools/legacy_exports/export_legacy.bat
Normal file
@ -0,0 +1,129 @@
|
||||
@echo off
|
||||
if defined MSYSTEM (
|
||||
echo This .bat file is for Windows CMD.EXE shell only.
|
||||
goto :eof
|
||||
)
|
||||
|
||||
set SCRIPT_EXIT_CODE=0
|
||||
|
||||
:: Missing requirements check
|
||||
set MISSING_REQUIREMENTS=
|
||||
python.exe --version >NUL 2>NUL
|
||||
if %errorlevel% neq 0 (
|
||||
set SCRIPT_EXIT_CODE=%errorlevel%
|
||||
set "MISSING_REQUIREMENTS= python &echo\"
|
||||
)
|
||||
git.exe --version >NUL 2>NUL
|
||||
if %errorlevel% neq 0 (
|
||||
set SCRIPT_EXIT_CODE=%errorlevel%
|
||||
set "MISSING_REQUIREMENTS=%MISSING_REQUIREMENTS% git"
|
||||
)
|
||||
|
||||
if not "%MISSING_REQUIREMENTS%" == "" goto :__error_missing_requirements
|
||||
|
||||
:: Infer IDF_PATH from script location
|
||||
set IDF_PATH=%~dp0
|
||||
set IDF_PATH=%IDF_PATH:~0,-1%
|
||||
:: As export_legacy got moved, remove the trailing 'tools\legacy_exports' to detect IDF_PATH
|
||||
set "IDF_PATH=%IDF_PATH:\tools\legacy_exports=%"
|
||||
|
||||
echo Checking Python compatibility
|
||||
python.exe "%IDF_PATH%\tools\python_version_checker.py"
|
||||
|
||||
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 (
|
||||
set SCRIPT_EXIT_CODE=%errorlevel%
|
||||
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. %
|
||||
|
||||
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 espsecure.py=python.exe "%IDF_PATH%\components\esptool_py\esptool\espsecure.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\idf_tools.py" check-python-dependencies
|
||||
if %errorlevel% neq 0 (
|
||||
set SCRIPT_EXIT_CODE=%errorlevel%
|
||||
goto :__end
|
||||
)
|
||||
|
||||
python.exe "%IDF_PATH%\tools\idf_tools.py" uninstall --dry-run > UNINSTALL_OUTPUT
|
||||
SET /p UNINSTALL=<UNINSTALL_OUTPUT
|
||||
DEL UNINSTALL_OUTPUT
|
||||
if NOT "%UNINSTALL%"=="" call :__uninstall_message
|
||||
|
||||
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
|
||||
|
||||
:__error_missing_requirements
|
||||
echo.
|
||||
echo Error^: The following tools are not installed in your environment.
|
||||
echo.
|
||||
echo %MISSING_REQUIREMENTS%
|
||||
echo.
|
||||
echo Please use the Windows Tool installer for setting up your environment.
|
||||
echo Download link: https://dl.espressif.com/dl/esp-idf/
|
||||
echo For more details please visit our website: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/windows-setup.html
|
||||
goto :__end
|
||||
|
||||
:__uninstall_message
|
||||
echo.
|
||||
echo Detected installed tools that are not currently used by active ESP-IDF version.
|
||||
echo %UNINSTALL%
|
||||
echo For free up even more space, remove installation packages of those tools. Use option 'python.exe %IDF_PATH%\tools\idf_tools.py uninstall --remove-archives'.
|
||||
echo.
|
||||
|
||||
:__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=
|
||||
set MISSING_REQUIREMENTS=
|
||||
set UNINSTALL=
|
||||
exit /b %SCRIPT_EXIT_CODE%
|
111
tools/legacy_exports/export_legacy.fish
Normal file
111
tools/legacy_exports/export_legacy.fish
Normal file
@ -0,0 +1,111 @@
|
||||
# This script should be sourced, not executed.
|
||||
|
||||
# `idf_tools.py export --deactivate` create statement, with keyword unset, but fish shell support only `set --erase variable`
|
||||
function unset
|
||||
set --erase $argv
|
||||
end
|
||||
|
||||
function __main
|
||||
set script_dir (dirname (realpath (status -f)))
|
||||
# As export_legacy got moved, remove the trailing 'tools\legacy_exports' to detect IDF_PATH
|
||||
set script_dir (string replace -r '/tools/legacy_exports$' '' $script_dir)
|
||||
if not set -q IDF_PATH
|
||||
set -gx IDF_PATH $script_dir
|
||||
echo "Setting IDF_PATH to '$IDF_PATH'"
|
||||
end
|
||||
|
||||
if test "$IDF_PATH" != "$script_dir"
|
||||
# Change IDF_PATH is important when there are 2 ESP-IDF versions in different directories.
|
||||
# Sourcing this script without change, would cause sourcing wrong export script.
|
||||
echo "Resetting IDF_PATH from '$IDF_PATH' to '$script_dir'"
|
||||
set IDF_PATH "$script_dir"
|
||||
end
|
||||
|
||||
set oldpath = $PATH
|
||||
|
||||
echo "Detecting the Python interpreter"
|
||||
source "$IDF_PATH"/tools/detect_python.fish
|
||||
|
||||
echo "Checking Python compatibility"
|
||||
"$ESP_PYTHON" "$IDF_PATH"/tools/python_version_checker.py
|
||||
|
||||
echo "Checking other ESP-IDF version."
|
||||
set idf_deactivate ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py export --deactivate) || return 1
|
||||
eval "$idf_deactivate"
|
||||
|
||||
echo "Adding ESP-IDF tools to PATH..."
|
||||
# Call idf_tools.py to export tool paths
|
||||
set -gx IDF_TOOLS_EXPORT_CMD "$IDF_PATH"/export.fish
|
||||
set -gx IDF_TOOLS_INSTALL_CMD "$IDF_PATH"/install.fish
|
||||
# Allow calling some IDF python tools without specifying the full path
|
||||
# "$IDF_PATH"/tools is already added by 'idf_tools.py export'
|
||||
set IDF_ADD_PATHS_EXTRAS "$IDF_PATH"/components/espcoredump
|
||||
set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/partition_table
|
||||
set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/app_update
|
||||
|
||||
set idf_exports ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py export --add_paths_extras="$IDF_ADD_PATHS_EXTRAS") || return 1
|
||||
eval "$idf_exports"
|
||||
set -x PATH "$IDF_ADD_PATHS_EXTRAS":"$PATH"
|
||||
|
||||
echo "Checking if Python packages are up to date..."
|
||||
"$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py check-python-dependencies || return 1
|
||||
|
||||
set added_path_variables
|
||||
for entry in $PATH;
|
||||
if not contains $entry $oldpath
|
||||
set -a added_path_variables $entry
|
||||
end
|
||||
end
|
||||
if set -q added_path_variables[1]
|
||||
echo "Added the following directories to PATH:"
|
||||
for entry in $added_path_variables;
|
||||
echo $entry
|
||||
end
|
||||
else
|
||||
echo "All paths are already set."
|
||||
end
|
||||
|
||||
set uninstall ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py uninstall --dry-run) || return 1
|
||||
if test -n "$uninstall"
|
||||
echo ""
|
||||
echo "Detected installed tools that are not currently used by active ESP-IDF version."
|
||||
echo "$uninstall"
|
||||
echo "For free up even more space, remove installation packages of those tools. Use option '$ESP_PYTHON $IDF_PATH/tools/idf_tools.py uninstall --remove-archives'."
|
||||
echo ""
|
||||
end
|
||||
|
||||
# Clean up
|
||||
set -e added_path_variables
|
||||
set -e cmd
|
||||
set -e old_path
|
||||
set -e paths
|
||||
set -e path_prefix
|
||||
set -e path_entry
|
||||
set -e IDF_ADD_PATHS_EXTRAS
|
||||
set -e idf_exports
|
||||
set -e ESP_PYTHON
|
||||
set -e uninstall
|
||||
set -e script_dir
|
||||
set -e idf_deactivate
|
||||
|
||||
|
||||
# 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 ""
|
||||
end
|
||||
|
||||
__main
|
||||
|
||||
set click_version (python -c 'import click; print(click.__version__.split(".")[0])')
|
||||
if test $click_version -lt 8
|
||||
eval (env _IDF.PY_COMPLETE=source_fish idf.py)
|
||||
else
|
||||
eval (env _IDF.PY_COMPLETE=fish_source idf.py)
|
||||
end
|
||||
|
||||
functions -e __main
|
94
tools/legacy_exports/export_legacy.ps1
Normal file
94
tools/legacy_exports/export_legacy.ps1
Normal file
@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$S = [IO.Path]::PathSeparator # path separator. WIN:';', UNIX:":"
|
||||
|
||||
$IDF_PATH = "$PSScriptRoot"
|
||||
# As export_legacy got moved, remove the trailing 'tools\legacy_exports' to detect IDF_PATH
|
||||
$IDF_PATH = $IDF_PATH -replace "\\tools\\legacy_exports$", ""
|
||||
|
||||
Write-Output "Setting IDF_PATH: $IDF_PATH"
|
||||
$env:IDF_PATH = "$IDF_PATH"
|
||||
|
||||
Write-Output "Checking Python compatibility"
|
||||
python "$IDF_PATH/tools/python_version_checker.py"
|
||||
|
||||
Write-Output "Adding ESP-IDF tools to PATH..."
|
||||
$OLD_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicates
|
||||
# using idf_tools.py to get $envars_array to set
|
||||
$envars_raw = python "$IDF_PATH/tools/idf_tools.py" export --format key-value
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
|
||||
|
||||
$envars_array = @() # will be filled like:
|
||||
# [
|
||||
# [vname1, vval1], [vname2, vval2], ...
|
||||
# ]
|
||||
foreach ($line in $envars_raw) {
|
||||
$pair = $line.split("=") # split in name, val
|
||||
$var_name = $pair[0].Trim() # trim spaces on the ends of the name
|
||||
$var_val = $pair[1].Trim() # trim spaces on the ends of the val
|
||||
$envars_array += (, ($var_name, $var_val))
|
||||
}
|
||||
|
||||
if ($null -eq $IsWindows) {
|
||||
# $IsWindows was added in PowerShell Core 6 and PowerShell 7 together with multi-platform support. # I.E. if this
|
||||
# internal variable is not set then PowerShell 5 is used and # the platform cannot be # anything else than Windows.
|
||||
$Windows = $true
|
||||
}
|
||||
|
||||
foreach ($pair in $envars_array) {
|
||||
# setting the values
|
||||
$var_name = $pair[0].Trim() # trim spaces on the ends of the name
|
||||
$var_val = $pair[1].Trim() # trim spaces on the ends of the val
|
||||
if ($var_name -eq "PATH") {
|
||||
# trim "%PATH%" or "`$PATH"
|
||||
if ($IsWindows -or $Windows) {
|
||||
$var_val = $var_val.Trim($S + "%PATH%")
|
||||
} else {
|
||||
$var_val = $var_val.Trim($S + "`$PATH")
|
||||
}
|
||||
# apply
|
||||
$env:PATH = $var_val + $S + $env:PATH
|
||||
} else {
|
||||
New-Item -Path "env:$var_name" -Value "$var_val" -Force
|
||||
}
|
||||
}
|
||||
|
||||
# Allow calling some IDF python tools without specifying the full path
|
||||
function idf.py { &python "$IDF_PATH\tools\idf.py" $args }
|
||||
function espefuse.py { &python "$IDF_PATH\components\esptool_py\esptool\espefuse.py" $args }
|
||||
function espsecure.py { &python "$IDF_PATH\components\esptool_py\esptool\espsecure.py" $args }
|
||||
function otatool.py { &python "$IDF_PATH\components\app_update\otatool.py" $args }
|
||||
function parttool.py { &python "$IDF_PATH\components\partition_table\parttool.py" $args }
|
||||
|
||||
#Compare Path's OLD vs. NEW
|
||||
$NEW_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicates
|
||||
$dif_Path = Compare-Object -ReferenceObject $OLD_PATH -DifferenceObject $NEW_PATH -PassThru
|
||||
if ($null -ne $dif_Path) {
|
||||
Write-Output "`nAdded to PATH`n-------------"
|
||||
Write-Output $dif_Path
|
||||
} else {
|
||||
Write-Output "No directories added to PATH:"
|
||||
Write-Output $OLD_PATH
|
||||
}
|
||||
|
||||
|
||||
Write-Output "Checking if Python packages are up to date..."
|
||||
|
||||
Start-Process -Wait -NoNewWindow -FilePath "python" -Args "`"$IDF_PATH/tools/idf_tools.py`" check-python-dependencies"
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
|
||||
|
||||
$uninstall = python "$IDF_PATH/tools/idf_tools.py" uninstall --dry-run
|
||||
|
||||
if (![string]::IsNullOrEmpty($uninstall)){
|
||||
Write-Output ""
|
||||
Write-Output "Detected installed tools that are not currently used by active ESP-IDF version."
|
||||
Write-Output "$uninstall"
|
||||
Write-Output "For free up even more space, remove installation packages of those tools. Use option 'python.exe $IDF_PATH\tools\idf_tools.py uninstall --remove-archives'."
|
||||
Write-Output ""
|
||||
}
|
||||
|
||||
Write-Output "
|
||||
Done! You can now compile ESP-IDF projects.
|
||||
Go to the project directory and run:
|
||||
idf.py build
|
||||
|
||||
"
|
235
tools/legacy_exports/export_legacy.sh
Normal file
235
tools/legacy_exports/export_legacy.sh
Normal file
@ -0,0 +1,235 @@
|
||||
# This script should be sourced, not executed.
|
||||
|
||||
__realpath() {
|
||||
wdir="$PWD"; [ "$PWD" = "/" ] && wdir=""
|
||||
arg=$1
|
||||
case "$arg" in
|
||||
/*) scriptdir="${arg}";;
|
||||
*) scriptdir="$wdir/${arg#./}";;
|
||||
esac
|
||||
scriptdir="${scriptdir%/*}"
|
||||
echo "$scriptdir"
|
||||
}
|
||||
|
||||
|
||||
__verbose() {
|
||||
[ -n "${IDF_EXPORT_QUIET-}" ] && return
|
||||
echo "$@"
|
||||
}
|
||||
|
||||
__script_dir(){
|
||||
# shellcheck disable=SC2169,SC2169,SC2039,SC3010,SC3028 # unreachable with 'dash'
|
||||
if [ "$(uname -s)" = "Darwin" ]; then
|
||||
# convert possibly relative path to absolute
|
||||
script_dir="$(__realpath "${self_path}")"
|
||||
# resolve any ../ references to make the path shorter
|
||||
script_dir="$(cd "${script_dir}" || exit 1; pwd)"
|
||||
else
|
||||
# convert to full path and get the directory name of that
|
||||
script_name="$(readlink -f "${self_path}")"
|
||||
script_dir="$(dirname "${script_name}")"
|
||||
fi
|
||||
if [ "$script_dir" = '.' ]
|
||||
then
|
||||
script_dir="$(pwd)"
|
||||
fi
|
||||
echo "$script_dir"
|
||||
}
|
||||
|
||||
__is_dir_esp_idf(){
|
||||
if [ ! -f "$1/tools/idf.py" ] || [ ! -f "$1/tools/idf_tools.py" ]
|
||||
then
|
||||
# Echo command here is not used for printing to the terminal, but as non-empty return value from function.
|
||||
echo "THIS DIRECTORY IS NOT ESP-IDF"
|
||||
fi
|
||||
}
|
||||
|
||||
__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...
|
||||
|
||||
# shellcheck disable=SC2128,SC2169,SC2039,SC3054 # ignore array expansion warning
|
||||
if [ -n "${BASH_SOURCE-}" ] && [ "${BASH_SOURCE[0]}" = "${0}" ]
|
||||
then
|
||||
echo "This script should be sourced, not executed:"
|
||||
# shellcheck disable=SC2039,SC3054 # reachable only with bash
|
||||
echo ". ${BASH_SOURCE[0]}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# If using bash or zsh, try to guess IDF_PATH from script location.
|
||||
self_path=""
|
||||
# shellcheck disable=SC2128 # ignore array expansion warning
|
||||
if [ -n "${BASH_SOURCE-}" ]
|
||||
then
|
||||
self_path="${BASH_SOURCE}"
|
||||
elif [ -n "${ZSH_VERSION-}" ]
|
||||
then
|
||||
# shellcheck disable=SC2296 # ignore parameter starts with '{' because it's zsh
|
||||
self_path="${(%):-%x}"
|
||||
fi
|
||||
|
||||
script_dir="$(__script_dir)"
|
||||
# As export_legacy got moved, remove the trailing 'tools\legacy_exports' to detect IDF_PATH
|
||||
script_dir="${script_dir%/tools/legacy_exports}"
|
||||
# Since sh or dash shells can't detect script_dir correctly, check if script_dir looks like an IDF directory
|
||||
is_script_dir_esp_idf=$(__is_dir_esp_idf "${script_dir}")
|
||||
|
||||
if [ -z "${IDF_PATH-}" ]
|
||||
then
|
||||
# IDF_PATH not set in the environment.
|
||||
|
||||
if [ -n "${is_script_dir_esp_idf}" ]
|
||||
then
|
||||
echo "Could not detect IDF_PATH. Please set it before sourcing this script:"
|
||||
echo " export IDF_PATH=(add path here)"
|
||||
return 1
|
||||
fi
|
||||
export IDF_PATH="${script_dir}"
|
||||
echo "Setting IDF_PATH to '${IDF_PATH}'"
|
||||
else
|
||||
# IDF_PATH came from the environment, check if the path is valid
|
||||
# Set IDF_PATH to script_dir, if script_dir looks like an IDF directory
|
||||
if [ ! "${IDF_PATH}" = "${script_dir}" ] && [ -z "${is_script_dir_esp_idf}" ]
|
||||
then
|
||||
# Change IDF_PATH is important when there are 2 ESP-IDF versions in different directories.
|
||||
# Sourcing this script without change, would cause sourcing wrong export script.
|
||||
echo "Resetting IDF_PATH from '${IDF_PATH}' to '${script_dir}' "
|
||||
export IDF_PATH="${script_dir}"
|
||||
fi
|
||||
# Check if this path looks like an IDF directory
|
||||
is_idf_path_esp_idf=$(__is_dir_esp_idf "${IDF_PATH}")
|
||||
if [ -n "${is_idf_path_esp_idf}" ]
|
||||
then
|
||||
echo "IDF_PATH is set to '${IDF_PATH}', but it doesn't look like an ESP-IDF directory."
|
||||
echo "If you have set IDF_PATH manually, check if the path is correct."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# The variable might have been set (rather than exported), re-export it to be sure
|
||||
export IDF_PATH="${IDF_PATH}"
|
||||
fi
|
||||
|
||||
old_path="$PATH"
|
||||
|
||||
echo "Detecting the Python interpreter"
|
||||
. "${IDF_PATH}/tools/detect_python.sh"
|
||||
|
||||
echo "Checking Python compatibility"
|
||||
"$ESP_PYTHON" "${IDF_PATH}/tools/python_version_checker.py"
|
||||
|
||||
__verbose "Checking other ESP-IDF version."
|
||||
idf_deactivate=$("$ESP_PYTHON" "${IDF_PATH}/tools/idf_tools.py" export --deactivate) || return 1
|
||||
eval "${idf_deactivate}"
|
||||
|
||||
__verbose "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
|
||||
# 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/espcoredump"
|
||||
IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/partition_table"
|
||||
IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/app_update"
|
||||
|
||||
idf_exports=$("$ESP_PYTHON" "${IDF_PATH}/tools/idf_tools.py" export "--add_paths_extras=${IDF_ADD_PATHS_EXTRAS}") || return 1
|
||||
eval "${idf_exports}"
|
||||
export PATH="${IDF_ADD_PATHS_EXTRAS}:${PATH}"
|
||||
|
||||
__verbose "Checking if Python packages are up to date..."
|
||||
"$ESP_PYTHON" "${IDF_PATH}/tools/idf_tools.py" check-python-dependencies || return 1
|
||||
|
||||
if [ -n "$BASH" ]
|
||||
then
|
||||
path_prefix="${PATH%%"${old_path}"}"
|
||||
# shellcheck disable=SC2169,SC2039 # unreachable with 'dash'
|
||||
if [ -n "${path_prefix}" ]; then
|
||||
__verbose "Added the following directories to PATH:"
|
||||
else
|
||||
__verbose "All paths are already set."
|
||||
fi
|
||||
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}"
|
||||
fi
|
||||
|
||||
uninstall=$("$ESP_PYTHON" "${IDF_PATH}/tools/idf_tools.py" uninstall --dry-run) || return 1
|
||||
if [ -n "$uninstall" ]
|
||||
then
|
||||
__verbose ""
|
||||
__verbose "Detected installed tools that are not currently used by active ESP-IDF version."
|
||||
__verbose "${uninstall}"
|
||||
__verbose "To free up even more space, remove installation packages of those tools. Use option '${ESP_PYTHON} ${IDF_PATH}/tools/idf_tools.py uninstall --remove-archives'."
|
||||
__verbose ""
|
||||
fi
|
||||
|
||||
__verbose "Done! You can now compile ESP-IDF projects."
|
||||
__verbose "Go to the project directory and run:"
|
||||
__verbose ""
|
||||
__verbose " idf.py build"
|
||||
__verbose ""
|
||||
}
|
||||
|
||||
__cleanup() {
|
||||
unset old_path
|
||||
unset paths
|
||||
unset path_prefix
|
||||
unset path_entry
|
||||
unset IDF_ADD_PATHS_EXTRAS
|
||||
unset idf_exports
|
||||
unset idf_deactivate
|
||||
unset ESP_PYTHON
|
||||
unset SOURCE_ZSH
|
||||
unset SOURCE_BASH
|
||||
unset WARNING_MSG
|
||||
unset uninstall
|
||||
unset is_idf_path_esp_idf
|
||||
unset is_script_dir_esp_idf
|
||||
|
||||
unset __realpath
|
||||
unset __main
|
||||
unset __verbose
|
||||
unset __enable_autocomplete
|
||||
unset __cleanup
|
||||
unset __is_dir_esp_idf
|
||||
|
||||
# Not unsetting IDF_PYTHON_ENV_PATH, it can be used by IDF build system
|
||||
# to check whether we are using a private Python environment
|
||||
|
||||
return "$1"
|
||||
}
|
||||
|
||||
|
||||
__enable_autocomplete() {
|
||||
click_version="$(python -c 'import click; print(click.__version__.split(".")[0])')"
|
||||
if [ "${click_version}" -lt 8 ]
|
||||
then
|
||||
SOURCE_ZSH=source_zsh
|
||||
SOURCE_BASH=source_bash
|
||||
else
|
||||
SOURCE_ZSH=zsh_source
|
||||
SOURCE_BASH=bash_source
|
||||
fi
|
||||
if [ -n "${ZSH_VERSION-}" ]
|
||||
then
|
||||
autoload -Uz compinit && compinit -u
|
||||
eval "$(env _IDF.PY_COMPLETE=$SOURCE_ZSH idf.py)" || echo "WARNING: Failed to load shell autocompletion for zsh version: $ZSH_VERSION!"
|
||||
elif [ -n "${BASH_SOURCE-}" ]
|
||||
then
|
||||
WARNING_MSG="WARNING: Failed to load shell autocompletion for bash version: $BASH_VERSION!"
|
||||
# shellcheck disable=SC3028,SC3054,SC2086,SC2169 # code block for 'bash' only
|
||||
[ ${BASH_VERSINFO[0]} -lt 4 ] && { echo "$WARNING_MSG"; return; }
|
||||
eval "$(env LANG=en _IDF.PY_COMPLETE=$SOURCE_BASH idf.py)" || echo "$WARNING_MSG"
|
||||
fi
|
||||
}
|
||||
|
||||
__main && __enable_autocomplete
|
||||
__cleanup $?
|
Loading…
x
Reference in New Issue
Block a user