export.ps1 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env pwsh
  2. $S = [IO.Path]::PathSeparator # path separator. WIN:';', UNIX:":"
  3. $IDF_PATH = $PSScriptRoot
  4. Write-Output "Setting IDF_PATH: $IDF_PATH"
  5. $env:IDF_PATH = $IDF_PATH
  6. Write-Output "Adding ESP-IDF tools to PATH..."
  7. $OLD_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicates
  8. # using idf_tools.py to get $envars_array to set
  9. $envars_raw = python $IDF_PATH/tools/idf_tools.py export --format key-value
  10. if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
  11. $envars_array # will be filled like:
  12. # [
  13. # [vname1, vval1], [vname2, vval2], ...
  14. # ]
  15. foreach ($line in $envars_raw) {
  16. $pair = $line.split("=") # split in name, val
  17. $var_name = $pair[0].Trim() # trim spaces on the ends of the name
  18. $var_val = $pair[1].Trim() # trim spaces on the ends of the val
  19. $envars_array += (, ($var_name, $var_val))
  20. }
  21. foreach ($pair in $envars_array) {
  22. # setting the values
  23. $var_name = $pair[0].Trim() # trim spaces on the ends of the name
  24. $var_val = $pair[1].Trim() # trim spaces on the ends of the val
  25. if ($var_name -eq "PATH") {
  26. # trim "%PATH%" or "`$PATH"
  27. if ($IsWindows) {
  28. $var_val = $var_val.Trim($S + "%PATH%")
  29. } else {
  30. $var_val = $var_val.Trim($S + "`$PATH")
  31. }
  32. # apply
  33. $env:PATH = $var_val + $S + $env:PATH
  34. } else {
  35. New-Item -Path "env:$var_name" -Value "$var_val" -Force
  36. }
  37. }
  38. # Allow calling some IDF python tools without specifying the full path
  39. # ${IDF_PATH}/tools is already added by 'idf_tools.py export'
  40. $IDF_ADD_PATHS_EXTRAS = [IO.Path]::Combine(${IDF_PATH}, "components", "esptool_py", "esptool")
  41. $IDF_ADD_PATHS_EXTRAS += ${S} + [IO.Path]::Combine(${IDF_PATH}, "components", "app_update")
  42. $IDF_ADD_PATHS_EXTRAS += ${S} + [IO.Path]::Combine(${IDF_PATH}, "components", "espcoredump")
  43. $IDF_ADD_PATHS_EXTRAS += ${S} + [IO.Path]::Combine(${IDF_PATH}, "components", "partition_table")
  44. $env:PATH = $IDF_ADD_PATHS_EXTRAS + $S + $env:PATH
  45. #Compare Path's OLD vs. NEW
  46. $NEW_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicates
  47. $dif_Path = Compare-Object -ReferenceObject $OLD_PATH -DifferenceObject $NEW_PATH -PassThru
  48. if ($dif_Path -ne $null) {
  49. Write-Output "`nAdded to PATH`n-------------"
  50. Write-Output $dif_Path
  51. } else {
  52. Write-Output "No directories added to PATH:"
  53. Write-Output $OLD_PATH
  54. }
  55. Write-Output "Checking if Python packages are up to date..."
  56. Start-Process -Wait -NoNewWindow -FilePath "python" -Args "`"$IDF_PATH/tools/check_python_dependencies.py`""
  57. if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
  58. Write-Output "
  59. Done! You can now compile ESP-IDF projects.
  60. Go to the project directory and run:
  61. idf.py build
  62. "