export.fish 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. 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_unset ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py export --unset) || return 1
  25. eval "$idf_unset"
  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/esptool_py/esptool
  33. set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/espcoredump
  34. set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/partition_table
  35. set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/app_update
  36. set idf_exports ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py export --add_paths_extras="$IDF_ADD_PATHS_EXTRAS") || return 1
  37. eval "$idf_exports"
  38. set -x PATH "$IDF_ADD_PATHS_EXTRAS":"$PATH"
  39. echo "Checking if Python packages are up to date..."
  40. python "$IDF_PATH"/tools/idf_tools.py check-python-dependencies || return 1
  41. set added_path_variables
  42. for entry in $PATH;
  43. if not contains $entry $oldpath
  44. set -a added_path_variables $entry
  45. end
  46. end
  47. if set -q added_path_variables[1]
  48. echo "Added the following directories to PATH:"
  49. for entry in $added_path_variables;
  50. echo $entry
  51. end
  52. else
  53. echo "All paths are already set."
  54. end
  55. set uninstall ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py uninstall --dry-run) || return 1
  56. if test -n "$uninstall"
  57. echo ""
  58. echo "Detected installed tools that are not currently used by active ESP-IDF version."
  59. echo "$uninstall"
  60. 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'."
  61. echo ""
  62. end
  63. # Clean up
  64. set -e added_path_variables
  65. set -e cmd
  66. set -e old_path
  67. set -e paths
  68. set -e path_prefix
  69. set -e path_entry
  70. set -e IDF_ADD_PATHS_EXTRAS
  71. set -e idf_exports
  72. set -e ESP_PYTHON
  73. set -e uninstall
  74. set -e script_dir
  75. set -e idf_unset
  76. # Not unsetting IDF_PYTHON_ENV_PATH, it can be used by IDF build system
  77. # to check whether we are using a private Python environment
  78. echo "Done! You can now compile ESP-IDF projects."
  79. echo "Go to the project directory and run:"
  80. echo ""
  81. echo " idf.py build"
  82. echo ""
  83. end
  84. __main
  85. set click_version (python -c 'import click; print(click.__version__.split(".")[0])')
  86. if test $click_version -lt 8
  87. eval (env _IDF.PY_COMPLETE=source_fish idf.py)
  88. else
  89. eval (env _IDF.PY_COMPLETE=fish_source idf.py)
  90. end
  91. set -e __main