Skip to content

Commit 79dd142

Browse files
Andrei Gramakovigrr
Andrei Gramakov
authored andcommitted
tools: add install.ps1, export.ps1
Closes IDF-855
1 parent aa08766 commit 79dd142

File tree

4 files changed

+115
-9
lines changed

4 files changed

+115
-9
lines changed

docs/en/get-started/index.rst

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
***********
1+
***********
22
Get Started
33
***********
44

@@ -62,7 +62,7 @@ If you have one of ESP32 development boards listed below, you can click on the l
6262
ESP-WROVER-KIT <../hw-reference/get-started-wrover-kit>
6363
ESP32-PICO-KIT <../hw-reference/get-started-pico-kit>
6464
ESP32-Ethernet-Kit <../hw-reference/get-started-ethernet-kit>
65-
65+
6666

6767
.. _get-started-step-by-step:
6868

@@ -175,6 +175,13 @@ If you want to install the tools without the help of ESP-IDF Tools Installer, op
175175
cd %userprofile%\esp\esp-idf
176176
install.bat
177177
178+
or with Windows PowerShell
179+
180+
.. code-block:: powershell
181+
182+
cd ~/esp/esp-idf
183+
./install.ps1
184+
178185
Linux and macOS
179186
~~~~~~~~~~~~~~~
180187

@@ -188,7 +195,7 @@ Customizing the tools installation path
188195

189196
The scripts introduced in this step install compilation tools required by ESP-IDF inside the user home directory: ``$HOME/.espressif`` on Linux and macOS, ``%USERPROFILE%\.espressif`` on Windows. If you wish to install the tools into a different directory, set the environment variable ``IDF_TOOLS_PATH`` before running the installation scripts. Make sure that your user has sufficient permissions to read and write this path.
190197

191-
If changing the ``IDF_TOOLS_PATH``, make sure it is set to the same value every time the ``install.bat``/``install.sh`` and ``export.bat``/``export.sh`` scripts are executed.
198+
If changing the ``IDF_TOOLS_PATH``, make sure it is set to the same value every time the Install script (``install.bat``, ``install.ps1`` or ``install.sh``) and an Export script (``export.bat``, ``export.ps1`` or ``export.sh``) are executed.
192199

193200
.. _get-started-set-up-env:
194201

@@ -208,6 +215,12 @@ Alternatively, if you want to use ESP-IDF in an existing Command Prompt window,
208215
209216
%userprofile%\esp\esp-idf\export.bat
210217
218+
or with Windows PowerShell
219+
220+
.. code-block:: powershell
221+
222+
.$HOME/esp/esp-idf/export.ps1
223+
211224
Linux and macOS
212225
~~~~~~~~~~~~~~~
213226

@@ -481,9 +494,9 @@ You should update ESP-IDF from time to time, as newer versions fix bugs and prov
481494

482495
Another solution is to update only what has changed. :ref:`The update procedure depends on the version of ESP-IDF you are using <updating>`.
483496

484-
After updating ESP-IDF, execute ``install.sh`` (``install.bat`` on Windows) again, in case the new ESP-IDF version requires different versions of tools. See instructions at :ref:`get-started-set-up-tools`.
497+
After updating ESP-IDF, execute the Install script again, in case the new ESP-IDF version requires different versions of tools. See instructions at :ref:`get-started-set-up-tools`.
485498

486-
Once the new tools are installed, update the environment using ``export.sh`` (``export.bat`` on Windows). See instructions at :ref:`get-started-set-up-env`.
499+
Once the new tools are installed, update the environment using the Export script. See instructions at :ref:`get-started-set-up-env`.
487500

488501
Related Documents
489502
=================

docs/en/get-started/windows-setup-update.rst

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@ Updating ESP-IDF tools on Windows
44

55
.. _get-started-install_bat-windows:
66

7-
Install ESP-IDF tools using ``install.bat``
8-
===========================================
7+
Install ESP-IDF tools using a script
8+
====================================
99

1010
From the Windows Command Prompt, change to the directory where ESP-IDF is installed. Then run::
1111

1212
install.bat
1313

14+
For Powershell, change to the directory where ESP-IDF is installed. Then run::
15+
16+
install.ps1
17+
1418
This will download and install the tools necessary to use ESP-IDF. If the specific version of the tool is already installed, no action will be taken.
1519
The tools are downloaded and installed into a directory specified during ESP-IDF Tools Installer process. By default, this is ``C:\Users\username\.espressif``.
1620

1721
.. _get-started-export_bat-windows:
1822

19-
Add ESP-IDF tools to PATH using ``export.bat``
20-
==============================================
23+
Add ESP-IDF tools to PATH using an export script
24+
================================================
2125

2226
ESP-IDF tools installer creates a Start menu shortcut for "ESP-IDF Command Prompt". This shortcut opens a Command Prompt window where all the tools are already available.
2327

@@ -28,4 +32,9 @@ In the command prompt where you need to use ESP-IDF, change to the directory whe
2832
cd %userprofile%\esp\esp-idf
2933
export.bat
3034

35+
Alternatively in the Powershell where you need to use ESP-IDF, change to the directory where ESP-IDF is installed, then execute ``export.ps1``::
36+
37+
cd ~/esp/esp-idf
38+
export.ps1
39+
3140
When this is done, the tools will be available in this command prompt.

export.ps1

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
if ($env:MSYSTEM -ne $null) {
2+
Write-Output "This .ps1 file is for Windows Powershell only. When using MSYS, run:`n. ./export.sh."
3+
exit 1
4+
}
5+
6+
7+
$IDF_PATH = $PSScriptRoot
8+
9+
Write-Output "Setting IDF_PATH: $IDF_PATH"
10+
$env:IDF_PATH=$IDF_PATH
11+
12+
Write-Output "Adding ESP-IDF tools to PATH..."
13+
$OLD_PATH=$env:Path.split(";") | Select-Object -Unique # array without duplicates
14+
# using idf_tools.py to get $envars_array to set
15+
$envars_raw = python.exe $IDF_PATH\tools\idf_tools.py export --format key-value
16+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
17+
18+
$envars_array # will be filled like:
19+
# [
20+
# [vname1, vval1], [vname2, vval2], ...
21+
# ]
22+
foreach ($line in $envars_raw)
23+
{
24+
$pair = $line.split("=") # split in name, val
25+
$var_name = $pair[0].Trim() # trim spaces on the ends of the name
26+
$var_val = $pair[1].Trim() # trim spaces on the ends of the val
27+
$var_val = $var_val -replace "%(.+)%", "`$env:`$1" # convert var syntax to PS using RegEx
28+
$var_val = $ExecutionContext.InvokeCommand.ExpandString($var_val) # expand variables to values
29+
$envars_array+=(,($var_name, $var_val))
30+
}
31+
32+
foreach ($pair in $envars_array) # setting the values
33+
{
34+
$var_name = $pair[0].Trim() # trim spaces on the ends of the name
35+
$var_val = $pair[1].Trim() # trim spaces on the ends of the val
36+
Set-Item -Path "Env:$var_name" -Value "$var_val"
37+
}
38+
39+
#Compare Path's OLD vs. NEW
40+
$NEW_PATH = $env:Path.split(";") | Select-Object -Unique # array without duplicates
41+
$dif_Path = Compare-Object -ReferenceObject $OLD_PATH -DifferenceObject $NEW_PATH -PassThru
42+
if ($dif_Path -ne $null)
43+
{
44+
Write-Output $dif_Path
45+
}
46+
else {
47+
Write-Output "No directories added to PATH:"
48+
Write-Output $OLD_PATH
49+
}
50+
51+
52+
Write-Output "Checking if Python packages are up to date..."
53+
54+
Start-Process -Wait -NoNewWindow -FilePath "python" -Args "$IDF_PATH/tools/check_python_dependencies.py"
55+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
56+
57+
Write-Output "
58+
Done! You can now compile ESP-IDF projects.
59+
Go to the project directory and run:
60+
idf.py build
61+
62+
"

install.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
if ($env:MSYSTEM -ne $null) {
2+
Write-Output "This .ps1 file is for Windows Powershell only. When using MSYS, run:`n. ./export.sh."
3+
exit 1
4+
}
5+
6+
7+
$IDF_PATH = $PSScriptRoot
8+
9+
10+
Write-Output "Installing ESP-IDF tools"
11+
Start-Process -Wait -NoNewWindow -FilePath "python.exe" -Args "$IDF_PATH/tools/idf_tools.py install"
12+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
13+
14+
Write-Output "Setting up Python environment"
15+
Start-Process -Wait -NoNewWindow -FilePath "python.exe" -Args "$IDF_PATH/tools/idf_tools.py install-python-env"
16+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE} # if error
17+
18+
19+
Write-Output "
20+
All done! You can now run:
21+
export.ps1
22+
"

0 commit comments

Comments
 (0)