export.ps1 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 "Checking Python compatibility"
  7. python $IDF_PATH/tools/python_version_checker.py
  8. Write-Output "Adding ESP-IDF tools to PATH..."
  9. $OLD_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicates
  10. # using idf_tools.py to get $envars_array to set
  11. $envars_raw = python $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. $pair = $line.split("=") # split in name, val
  19. $var_name = $pair[0].Trim() # trim spaces on the ends of the name
  20. $var_val = $pair[1].Trim() # trim spaces on the ends of the val
  21. $envars_array += (, ($var_name, $var_val))
  22. }
  23. if ($IsWindows -eq $null) {
  24. # $IsWindows was added in PowerShell Core 6 and PowerShell 7 together with multi-platform support. # I.E. if this
  25. # internal variable is not set then PowerShell 5 is used and # the platform cannot be # anything else than Windows.
  26. $IsWindows = $true
  27. }
  28. foreach ($pair in $envars_array) {
  29. # setting the values
  30. $var_name = $pair[0].Trim() # trim spaces on the ends of the name
  31. $var_val = $pair[1].Trim() # trim spaces on the ends of the val
  32. if ($var_name -eq "PATH") {
  33. # trim "%PATH%" or "`$PATH"
  34. if ($IsWindows) {
  35. $var_val = $var_val.Trim($S + "%PATH%")
  36. } else {
  37. $var_val = $var_val.Trim($S + "`$PATH")
  38. }
  39. # apply
  40. $env:PATH = $var_val + $S + $env:PATH
  41. } else {
  42. New-Item -Path "env:$var_name" -Value "$var_val" -Force
  43. }
  44. }
  45. # Allow calling some IDF python tools without specifying the full path
  46. # ${IDF_PATH}/tools is already added by 'idf_tools.py export'
  47. $IDF_ADD_PATHS_EXTRAS = [IO.Path]::Combine(${IDF_PATH}, "components", "esptool_py", "esptool")
  48. $IDF_ADD_PATHS_EXTRAS += ${S} + [IO.Path]::Combine(${IDF_PATH}, "components", "app_update")
  49. $IDF_ADD_PATHS_EXTRAS += ${S} + [IO.Path]::Combine(${IDF_PATH}, "components", "espcoredump")
  50. $IDF_ADD_PATHS_EXTRAS += ${S} + [IO.Path]::Combine(${IDF_PATH}, "components", "partition_table")
  51. $env:PATH = $IDF_ADD_PATHS_EXTRAS + $S + $env:PATH
  52. #Compare Path's OLD vs. NEW
  53. $NEW_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicates
  54. $dif_Path = Compare-Object -ReferenceObject $OLD_PATH -DifferenceObject $NEW_PATH -PassThru
  55. if ($dif_Path -ne $null) {
  56. Write-Output "`nAdded to PATH`n-------------"
  57. Write-Output $dif_Path
  58. } else {
  59. Write-Output "No directories added to PATH:"
  60. Write-Output $OLD_PATH
  61. }
  62. Write-Output "Checking if Python packages are up to date..."
  63. Start-Process -Wait -NoNewWindow -FilePath "python" -Args "`"$IDF_PATH/tools/idf_tools.py`" check-python-dependencies"
  64. if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
  65. $uninstall = python $IDF_PATH/tools/idf_tools.py uninstall --dry-run
  66. if (![string]::IsNullOrEmpty($uninstall)){
  67. Write-Output ""
  68. Write-Output "Detected installed tools that are not currently used by active ESP-IDF version."
  69. Write-Output "$uninstall"
  70. Write-Output "For free up even more space, remove installation packages of those tools. Use option 'python.exe $IDF_PATH\tools\idf_tools.py uninstall --remove-archives'."
  71. Write-Output ""
  72. }
  73. Write-Output "
  74. Done! You can now compile ESP-IDF projects.
  75. Go to the project directory and run:
  76. idf.py build
  77. "