export.fish 3.8 KB

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