export.ps1 2.0 KB

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