export.ps1 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env pwsh
  2. $IDF_PATH = $PSScriptRoot
  3. Write-Output "Setting IDF_PATH: $IDF_PATH"
  4. $env:IDF_PATH=$IDF_PATH
  5. Write-Output "Adding ESP-IDF tools to PATH..."
  6. $OLD_PATH=$env:PATH.split([IO.Path]::PathSeparator) | Select-Object -Unique # array without duplicates
  7. # using idf_tools.py to get $envars_array to set
  8. $envars_raw = python $IDF_PATH/tools/idf_tools.py export --format key-value
  9. if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
  10. $envars_array # will be filled like:
  11. # [
  12. # [vname1, vval1], [vname2, vval2], ...
  13. # ]
  14. foreach ($line in $envars_raw)
  15. {
  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) # setting the values
  22. {
  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([IO.Path]::PathSeparator + "%PATH%")
  29. }else{
  30. $var_val = $var_val.Trim([IO.Path]::PathSeparator + "`$PATH")
  31. }
  32. # apply
  33. $env:PATH = $var_val + [IO.Path]::PathSeparator + $env:PATH
  34. } else {
  35. New-Item -Path "env:$var_name" -Value "$var_val"
  36. }
  37. }
  38. #Compare Path's OLD vs. NEW
  39. $NEW_PATH = $env:PATH.split([IO.Path]::PathSeparator) | Select-Object -Unique # array without duplicates
  40. $dif_Path = Compare-Object -ReferenceObject $OLD_PATH -DifferenceObject $NEW_PATH -PassThru
  41. if ($dif_Path -ne $null)
  42. {
  43. Write-Output $dif_Path
  44. }
  45. else {
  46. Write-Output "No directories added to PATH:"
  47. Write-Output $OLD_PATH
  48. }
  49. Write-Output "Checking if Python packages are up to date..."
  50. Start-Process -Wait -NoNewWindow -FilePath "python" -Args "$IDF_PATH/tools/check_python_dependencies.py"
  51. if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
  52. Write-Output "
  53. Done! You can now compile ESP-IDF projects.
  54. Go to the project directory and run:
  55. idf.py build
  56. "