From b306f4b4bbd6ee60350e6c4a334dc4472843c73b Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Fri, 11 Oct 2024 22:09:40 +0800 Subject: [PATCH 1/2] feat(tools): Added Windows Powershell export script Signed-off-by: Dennis Liu --- export.ps1 | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 export.ps1 diff --git a/export.ps1 b/export.ps1 new file mode 100644 index 00000000..442c1c8d --- /dev/null +++ b/export.ps1 @@ -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 From fd045f709c5df2de6c2e1015c365d3ef6df20d5e Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Fri, 11 Oct 2024 23:40:01 +0800 Subject: [PATCH 2/2] doc: Added statement for powershell export case Signed-off-by: Dennis Liu --- docs/en/get-started/index.rst | 36 +++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/docs/en/get-started/index.rst b/docs/en/get-started/index.rst index debaee9d..a9ae7eee 100644 --- a/docs/en/get-started/index.rst +++ b/docs/en/get-started/index.rst @@ -90,16 +90,40 @@ Windows Or first download the full ESP-IDF Windows Installer from `ESP-IDF Windows Installer `_ (Please download the `ESP-IDF versions `_ 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: