Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export.sh doesn't work on macOS Catalina 10.15.x -- zsh default shell (IDFGH-3301) #5288

Closed
tmspzz opened this issue May 13, 2020 · 10 comments
Closed

Comments

@tmspzz
Copy link

tmspzz commented May 13, 2020

Environment

  • Development Kit: n/a
  • Kit version (for WroverKit/PicoKit/DevKitC): n/a
  • Module or chip used: n/a
  • IDF version: v4.1-beta1-182-g9778b163b
  • Build System: CMake
  • Compiler version: xtensa-esp32-elf-gcc (crosstool-NG esp-2019r2) 8.2.0
  • Operating System: macOS
  • Using an IDE?: No
  • Power Supply: n/a

Problem Description

export.sh doesn't work on macOS Catalina

Expected Behavior

export.sh works on macOS Catalina

Actual Behavior

export.sh assumes bash to be the default shell. This assumption doesn't hold on macOS Catalina where the default shell is zsh.

Steps to reproduce

  • set zsh as default shell
  • run export.sh

Debug Logs

export.sh stops with

IDF_PATH must be set before sourcing this script"

Solution

Modify export.sh with the following (I can submit a PR)

diff --git a/export.sh b/export.sh
index 0408a76bb..6b692e273 100644
--- a/export.sh
+++ b/export.sh
@@ -15,7 +15,7 @@ function realpath_int() {
 function idf_export_main() {
     # The file doesn't have executable permissions, so this shouldn't really happen.
     # Doing this in case someone tries to chmod +x it and execute...
-    if [[ -n "${BASH_SOURCE}" && ( "${BASH_SOURCE[0]}" == "${0}" ) ]]; then
+    if [[ -n "${SHELL_SOURCE}" && ( "${SHELL_SOURCE[0]}" == "${0}" ) ]]; then
         echo "This script should be sourced, not executed:"
         echo ". ${BASH_SOURCE[0]}"
         return 1
@@ -24,12 +24,12 @@ function idf_export_main() {
     if [[ -z "${IDF_PATH}" ]]
     then
         # If using bash, try to guess IDF_PATH from script location
-        if [[ -n "${BASH_SOURCE}" ]]
+        if [[ -n "${SHELL_SOURCE}" ]]
         then
             if [[ "$OSTYPE" == "darwin"* ]]; then
-                script_dir="$(realpath_int $BASH_SOURCE)"
+                script_dir="$(realpath_int $SHELL_SOURCE)"
             else
-                script_name="$(readlink -f $BASH_SOURCE)"
+                script_name="$(readlink -f $SHELL_SOURCE)"
                 script_dir="$(dirname $script_name)"
             fi
             export IDF_PATH="${script_dir}"
@@ -95,7 +95,16 @@ function idf_export_main() {
     echo ""
 }

+if [ -n "$ZSH_VERSION" ]; then
+   SHELL_SOURCE=${(%):-%x}
+elif [ -n "$BASH_VERSION" ]; then
+   SHELL_SOURCE=BASH_SOURCE
+else
+   echo "This script only works on bash or zsh."
+fi
+
 idf_export_main

+
 unset realpath_int
 unset idf_export_main
@tmspzz tmspzz changed the title export.sh doesn't work on macOS Catalina 10.15.x export.sh doesn't work on macOS Catalina 10.15.x -- zsh default shell May 13, 2020
@github-actions github-actions bot changed the title export.sh doesn't work on macOS Catalina 10.15.x -- zsh default shell export.sh doesn't work on macOS Catalina 10.15.x -- zsh default shell (IDFGH-3301) May 13, 2020
@igrr
Copy link
Member

igrr commented May 14, 2020

Hi @tmspzz, IDF_PATH detection for zhs was implemented in 1c4c584. Will backport this to release/v4.1

@tmspzz
Copy link
Author

tmspzz commented May 14, 2020

@igrr that's nice! Thanks!

Also, I'm pretty sure you're aware of it, but macOS loudly complains about using python instead of python3. And of course /usr/bin/env python defaults to python2

@igrr
Copy link
Member

igrr commented May 14, 2020

No, I'm not aware of that. What error are you getting with regards to python?

@tmspzz
Copy link
Author

tmspzz commented May 14, 2020

I think it's the same as #4774

But since the scripts start with #!/usr/bin/env python there is no (good?) way to switch to python3

@igrr
Copy link
Member

igrr commented May 14, 2020

How about brew install python3 (or any other method of your choice), and then make sure /usr/local/bin/python symlink points to /usr/local/bin/python3?

@gojimmypi
Copy link

@tmspzz if indeed the same as #4774, this solution worked for me.

I'm not sure how well that might work on a Mac.

projectgus pushed a commit that referenced this issue Jul 22, 2020
1. detect IDF_PATH in zsh, if it is not set
2. if IDF_PATH is set, check that it is valid
3. make sure IDF_PATH is exported, not just set

Related to #3793
Closes #4418
Closes #4770
Closes #5288
@igrr
Copy link
Member

igrr commented Sep 22, 2020

Has been fixed on release/v4.1 with 6ae54e7.

@igrr igrr closed this as completed Sep 22, 2020
@malachib
Copy link

Any chance this can backport into a v3.3.5? 🙏

@igrr
Copy link
Member

igrr commented Feb 21, 2021

Hi @malachib, 3.3 releases did not use install.sh/export.sh yet, please refer to the getting started guides for that version: https://docs.espressif.com/projects/esp-idf/en/release-v3.3/get-started/index.html#setup-toolchain.

@malachib
Copy link

Really? I see the install.sh right there in the v3.3.4 tag checkout -- but not an issue, I've already got the toolchain set up as described in that link so good to go. Thank you for the response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants