export.fish 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # This script should be sourced, not executed.
  2. # `idf_tools.py export --deactivate` create statement, with keyword unset, but fish shell support only `set --erase variable`
  3. function unset
  4. set --erase $argv
  5. end
  6. function __main
  7. set script_dir (dirname (realpath (status -f)))
  8. if not set -q IDF_PATH
  9. set -gx IDF_PATH $script_dir
  10. echo "Setting IDF_PATH to '$IDF_PATH'"
  11. end
  12. if test "$IDF_PATH" != "$script_dir"
  13. # Change IDF_PATH is important when there are 2 ESP-IDF versions in different directories.
  14. # Sourcing this script without change, would cause sourcing wrong export script.
  15. echo "Resetting IDF_PATH from '$IDF_PATH' to '$script_dir'"
  16. set IDF_PATH "$script_dir"
  17. end
  18. set oldpath = $PATH
  19. echo "Detecting the Python interpreter"
  20. source "$IDF_PATH"/tools/detect_python.fish
  21. echo "Checking Python compatibility"
  22. "$ESP_PYTHON" "$IDF_PATH"/tools/python_version_checker.py
  23. echo "Checking other ESP-IDF version."
  24. set idf_deactivate ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py export --deactivate) || return 1
  25. eval "$idf_deactivate"
  26. echo "Adding ESP-IDF tools to PATH..."
  27. # Call idf_tools.py to export tool paths
  28. set -gx IDF_TOOLS_EXPORT_CMD "$IDF_PATH"/export.fish
  29. set -gx IDF_TOOLS_INSTALL_CMD "$IDF_PATH"/install.fish
  30. # Allow calling some IDF python tools without specifying the full path
  31. # "$IDF_PATH"/tools is already added by 'idf_tools.py export'
  32. set IDF_ADD_PATHS_EXTRAS "$IDF_PATH"/components/espcoredump
  33. set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/partition_table
  34. set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/app_update
  35. set idf_exports ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py export --add_paths_extras="$IDF_ADD_PATHS_EXTRAS") || return 1
  36. eval "$idf_exports"
  37. set -x PATH "$IDF_ADD_PATHS_EXTRAS":"$PATH"
  38. echo "Checking if Python packages are up to date..."
  39. "$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py check-python-dependencies || return 1
  40. set added_path_variables
  41. for entry in $PATH;
  42. if not contains $entry $oldpath
  43. set -a added_path_variables $entry
  44. end
  45. end
  46. if set -q added_path_variables[1]
  47. echo "Added the following directories to PATH:"
  48. for entry in $added_path_variables;
  49. echo $entry
  50. end
  51. else
  52. echo "All paths are already set."
  53. end
  54. set uninstall ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py uninstall --dry-run) || return 1
  55. if test -n "$uninstall"
  56. echo ""
  57. echo "Detected installed tools that are not currently used by active ESP-IDF version."
  58. echo "$uninstall"
  59. echo "For free up even more space, remove installation packages of those tools. Use option '$ESP_PYTHON $IDF_PATH/tools/idf_tools.py uninstall --remove-archives'."
  60. echo ""
  61. end
  62. # Clean up
  63. set -e added_path_variables
  64. set -e cmd
  65. set -e old_path
  66. set -e paths
  67. set -e path_prefix
  68. set -e path_entry
  69. set -e IDF_ADD_PATHS_EXTRAS
  70. set -e idf_exports
  71. set -e ESP_PYTHON
  72. set -e uninstall
  73. set -e script_dir
  74. set -e idf_deactivate
  75. # Not unsetting IDF_PYTHON_ENV_PATH, it can be used by IDF build system
  76. # to check whether we are using a private Python environment
  77. echo "Done! You can now compile ESP-IDF projects."
  78. echo "Go to the project directory and run:"
  79. echo ""
  80. echo " idf.py build"
  81. echo ""
  82. end
  83. __main
  84. set click_version (python -c 'import click; print(click.__version__.split(".")[0])')
  85. if test $click_version -lt 8
  86. eval (env _IDF.PY_COMPLETE=source_fish idf.py)
  87. else
  88. eval (env _IDF.PY_COMPLETE=fish_source idf.py)
  89. end
  90. functions -e __main