Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powershell export (AUD-5758) #1292

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions docs/en/get-started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,40 @@ Windows
Or first download the full ESP-IDF Windows Installer from `ESP-IDF Windows Installer <https://dl.espressif.com/dl/esp-idf>`_ (Please download the `ESP-IDF versions <https://github.com/espressif/esp-adf/blob/master/README.md#idf-version>`_ supported by ESP-ADF). And then turn off the antivirus software (Because it may prevent the installation as the software writes the Windows system regedit) and install the downloaded file. After the installation is complete, open the ESP-IDF CMD shortcut icon on the desktop, the script will automatically help you download submodules, and set environment variables such as ``IDF_PATH``.


3. Set the ``ADF_PATH`` by running the following commands::
3. Set the ``ADF_PATH`` by running the following commands:

.\export.bat
echo %ADF_PATH%
**Using Command Prompt (cmd.exe):**

.. code-block:: batch

4. If your ``ADF_PATH`` variable prints correctly, it's time to compile the ADF routines::
.\export.bat
echo %ADF_PATH%

**Using PowerShell:**

.. code-block:: powershell

.\export.ps1
echo $ADF_PATH
// or
echo $env:ADF_PATH

4. If your ``ADF_PATH`` variable prints correctly, it's time to compile the ADF routines:

**Using Command Prompt (cmd.exe):**

.. code-block:: batch

cd %ADF_PATH%\examples\get-started\play_mp3_control
idf.py build flash monitor

**Using PowerShell:**

.. code-block:: powershell

cd $ADF_PATH\examples\get-started\play_mp3_control
idf.py build flash monitor

cd %ADF_PATH%\examples\get-started\play_mp3_control
idf.py build flash monitor


.. _get-started-step-by-step:
Expand Down
113 changes: 113 additions & 0 deletions export.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
## Usage
# ./export.ps1

## Function Definitions

function ErrorHandling {
Write-Host "The script encountered an error." -ForegroundColor Red
exit 1
}

function NewLine {
Write-Host ""
}

function ShowExampleCommands {
# Display help and example commands
Write-Output ""
Write-Output "The following command can be executed now to view detailed usage:"
Write-Output ""
Write-Output " idf.py --help"
Write-Output ""
Write-Output "Compilation example (The commands highlighted in yellow below are optional: Configure the chip and project settings separately):"
Write-Output ""
Write-Output " cd $ADF_PATH\examples\cli"
Write-Output " idf.py set-target esp32"
Write-Output " idf.py menuconfig"
Write-Output " idf.py build"
}

## Export.ps1 Starts
NewLine

# Set ADF_PATH to the script's directory
$ADF_PATH = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$ADF_PATH = $ADF_PATH.TrimEnd('\')

# export $env:ADF_PATH to current terminal
$env:ADF_PATH = "$ADF_PATH"

# export $ADF_PATH to current terminal
Write-Host "Export '`$ADF_PATH: $ADF_PATH' to current terminal" -ForegroundColor Yellow
Set-Variable -Name ADF_PATH -Value $env:ADF_PATH -Scope Global

# Check if IDF_PATH is already defined
if (-not $env:IDF_PATH) {
# export $env:IDF_PATH to current terminal
$env:IDF_PATH = Join-Path $ADF_PATH "esp-idf"
# export $IDF_PATH to current terminal
Write-Host "Export '`$IDF_PATH: $env:IDF_PATH' to current terminal" -ForegroundColor Yellow
Set-Variable -Name IDF_PATH -Value $env:IDF_PATH -Scope Global
}

# Display ADF_PATH and IDF_PATH
NewLine
Write-Host "ADF_PATH: $env:ADF_PATH" -ForegroundColor Blue
Write-Host "IDF_PATH: $env:IDF_PATH" -ForegroundColor Blue
NewLine

# Check if export.ps1 exists before calling it
$exportPs1Path = Join-Path $env:IDF_PATH "export.ps1"
if (-Not (Test-Path $exportPs1Path)) {
Write-Host "ESP-IDF export.ps1 does not exist at path: $exportPs1Path" -ForegroundColor Red
ErrorHandling
}

# Call ESP-IDF export.ps1
try {
Write-Host "Calling ESP-IDF export.ps1..." -ForegroundColor Yellow
Write-Host "===" -ForegroundColor Yellow
. $exportPs1Path
} catch {
Write-Host "Failed to execute ESP-IDF export.ps1." -ForegroundColor Red
ErrorHandling
}

# Check the exit code of export.ps1
if ($LASTEXITCODE -ne 0) {
Write-Host "The script encountered an error in ESP-IDF export.ps1." -ForegroundColor Red
Write-Host "ESP-IDF export.ps1 exit code: $LASTEXITCODE" -ForegroundColor Red
ErrorHandling
} else {
Write-Host "ESP-IDF export.ps1 executed successfully!" -ForegroundColor Green
}

# Run the Python script to apply patches
$applyPatchCmd = Join-Path $ADF_PATH "tools\adf_install_patches.py"
try {
NewLine
Write-Host "Calling 'python.exe $applyPatchCmd'" -ForegroundColor Yellow
Write-Host "===" -ForegroundColor Yellow
python.exe "$applyPatchCmd" apply-patch
} catch {
Write-Host "Failed to execute adf_install_patches.py." -ForegroundColor Red
ErrorHandling
}

# Check the exit code of the Python script
if ($LASTEXITCODE -ne 0) {
Write-Host "The script encountered an error while applying adf patches." -ForegroundColor Red
Write-Host "adf_install_patches.py exit code: $LASTEXITCODE" -ForegroundColor Red
ErrorHandling
} else {
NewLine
Write-Host "Patch installed successfully!" -ForegroundColor Green
}

NewLine
ShowExampleCommands
NewLine

# If the script reaches this point, it has completed successfully
Write-Host "Exported successfully!" -ForegroundColor Green
exit 0