export.ps1 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. function idf.py { &python "$IDF_PATH\tools\idf.py" $args }
  47. function espefuse.py { &python "$IDF_PATH\components\esptool_py\esptool\espefuse.py" $args }
  48. function espsecure.py { &python "$IDF_PATH\components\esptool_py\esptool\espsecure.py" $args }
  49. function otatool.py { &python "$IDF_PATH\components\app_update\otatool.py" $args }
  50. function parttool.py { &python "$IDF_PATH\components\partition_table\parttool.py" $args }
  51. #Compare Path's OLD vs. NEW
  52. $NEW_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicates
  53. $dif_Path = Compare-Object -ReferenceObject $OLD_PATH -DifferenceObject $NEW_PATH -PassThru
  54. if ($dif_Path -ne $null) {
  55. Write-Output "`nAdded to PATH`n-------------"
  56. Write-Output $dif_Path
  57. } else {
  58. Write-Output "No directories added to PATH:"
  59. Write-Output $OLD_PATH
  60. }
  61. Write-Output "Checking if Python packages are up to date..."
  62. Start-Process -Wait -NoNewWindow -FilePath "python" -Args "`"$IDF_PATH/tools/idf_tools.py`" check-python-dependencies"
  63. if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
  64. $uninstall = python "$IDF_PATH/tools/idf_tools.py" uninstall --dry-run
  65. if (![string]::IsNullOrEmpty($uninstall)){
  66. Write-Output ""
  67. Write-Output "Detected installed tools that are not currently used by active ESP-IDF version."
  68. Write-Output "$uninstall"
  69. 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'."
  70. Write-Output ""
  71. }
  72. Write-Output "
  73. Done! You can now compile ESP-IDF projects.
  74. Go to the project directory and run:
  75. idf.py build
  76. "