1# This script should be sourced, not executed.
2
3function idf_export_main
4    if not set -q IDF_PATH
5        echo "IDF_PATH must be set before sourcing this script"
6        return 1
7    end
8
9    set oldpath = $PATH
10
11    echo "Detecting the Python interpreter"
12    source "$IDF_PATH"/tools/detect_python.fish
13
14    echo "Adding ESP-IDF tools to PATH..."
15    # Call idf_tools.py to export tool paths
16    set -x IDF_TOOLS_EXPORT_CMD "$IDF_PATH"/export.fish
17    set -x IDF_TOOLS_INSTALL_CMD "$IDF_PATH"/install.fish
18    set idf_exports ("$ESP_PYTHON" "$IDF_PATH"/tools/idf_tools.py export) || return 1
19    eval "$idf_exports"
20
21    echo "Checking if Python packages are up to date..."
22    python "$IDF_PATH"/tools/check_python_dependencies.py || return 1
23
24    # Allow calling some IDF python tools without specifying the full path
25    # "$IDF_PATH"/tools is already added by 'idf_tools.py export'
26    set IDF_ADD_PATHS_EXTRAS "$IDF_PATH"/components/esptool_py/esptool
27    set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/espcoredump
28    set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/partition_table
29    set IDF_ADD_PATHS_EXTRAS "$IDF_ADD_PATHS_EXTRAS":"$IDF_PATH"/components/app_update
30    set -x PATH "$IDF_ADD_PATHS_EXTRAS":"$PATH"
31
32    set added_path_variables
33    for entry in $PATH;
34        if not contains $entry $oldpath
35            set -a added_path_variables $entry
36        end
37    end
38    if set -q added_path_variables[1]
39        echo "Added the following directories to PATH:"
40        for entry in $added_path_variables;
41            echo $entry
42        end
43    else
44        echo "All paths are already set."
45    end
46
47    # Clean up
48    set -e added_path_variables
49    set -e cmd
50    set -e old_path
51    set -e paths
52    set -e path_prefix
53    set -e path_entry
54    set -e IDF_ADD_PATHS_EXTRAS
55    set -e idf_exports
56    set -e ESP_PYTHON
57
58    # Not unsetting IDF_PYTHON_ENV_PATH, it can be used by IDF build system
59    # to check whether we are using a private Python environment
60
61    echo "Done! You can now compile ESP-IDF projects."
62    echo "Go to the project directory and run:"
63    echo ""
64    echo "  idf.py build"
65    echo ""
66end
67
68idf_export_main
69
70eval (env _IDF.PY_COMPLETE=source_fish idf.py)
71
72set -e idf_export_main
73