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

SDK44: source-login-scripts.sh sourcing in the wrong shell #15723

Closed
zaubara opened this issue Dec 28, 2021 · 8 comments · Fixed by #15890
Closed

SDK44: source-login-scripts.sh sourcing in the wrong shell #15723

zaubara opened this issue Dec 28, 2021 · 8 comments · Fixed by #15890
Labels
needs validation Issue needs to be validated

Comments

@zaubara
Copy link

zaubara commented Dec 28, 2021

Summary

source-login-scripts.sh will fail silently and break every iOS build, when there is bash-specific code in one of the scripts sourced profiles.

Building an app for iOS will fail with:
Command PhaseScriptExecution failed with a nonzero exit code
or rather
PhaseScriptExecution [CP-User]\ Generate\ app.config\ for\ prebuilt\ Constants.manifest ... (in target 'EXConstants' from project 'Pods')

As it turns out, get-app-config-ios.sh will run source-login-scripts.sh, which will fail silently.
$current_shell will result in "bash", so, for me, ". ~/.bash_profile" will be run. This is, however, not running in bash - it's probably zsh for me.
So, if I would source my ~/.bash_profile in zsh with the same command manually, it will fail (for me) with:

. ~/.bash_profile
/usr/local/etc/bash_completion.d/subversion:30: command not found: shopt
/usr/local/etc/bash_completion.d/subversion:350: parse error near `<'

I suspect the same happening for the script. When removing the specific code from .bash_profile, everything works.

So the workaround for users will be removing the offending code (for me, that's commenting out homebrews bash completion), while the actual fix would have to be done in source-login-scripts.sh (see 8db2fac)

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

bare

What platform(s) does this occur on?

iOS

SDK Version (managed workflow only)

No response

Environment

Expo CLI 5.0.3 environment info:
System:
OS: macOS 12.1
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.18.2 - ~/.nvm/versions/node/v14.18.2/bin/node
npm: 6.14.15 - ~/.nvm/versions/node/v14.18.2/bin/npm
Watchman: 2021.12.20.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
Android SDK:
API Levels: 19, 21, 23, 25, 26, 27, 28, 29, 30
Build Tools: 23.0.1, 23.0.2, 25.0.2, 26.0.1, 26.0.2, 27.0.3, 28.0.2, 28.0.3, 29.0.2
System Images: android-28 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom
Android NDK: 22.1.7171670
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7935034
Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
npmPackages:
babel-preset-expo: 9.0.1 => 9.0.1
expo: ^44.0.2 => 44.0.2
react: 17.0.1 => 17.0.1
react-dom: 17.0.1 => 17.0.1
react-native: 0.64.3 => 0.64.3
react-native-web: 0.17.1 => 0.17.1
npmGlobalPackages:
eas-cli: 0.42.4
expo-cli: 5.0.3
Expo Workflow: bare

Reproducible demo

Have bash-specific code in ~/.bash_profile, like homebrews bash completion:

HOMEBREW_PREFIX=$(brew --prefix)
if type brew &>/dev/null; then
for COMPLETION in "$HOMEBREW_PREFIX"/etc/bash_completion.d/*
do
[[ -f $COMPLETION ]] && source "$COMPLETION"
done
if [[ -f ${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh ]];
then
source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
fi
fi

@DrNgo
Copy link

DrNgo commented Dec 31, 2021

This was also happening to me but I'm on a 2017 MacBook pro. My fix was to go into my bash_profile and comment out everything in it. It was able to build after that

@0x079
Copy link

0x079 commented Jan 2, 2022

Had the same problem, had to migrate from bash to zsh and nuke everything in ~/.bash_profile

@Kudo
Copy link
Contributor

Kudo commented Jan 3, 2022

hi there! please let me double confirm how did you build, by expo run:ios from shell or by Xcode?

@zaubara
Copy link
Author

zaubara commented Jan 3, 2022

Hey @Kudo - thanks for dropping in!
I had the issue with both - running expo run:ios (in my zsh default console) and when building in Xcode.
($current_shell reporting as bash was from Xcode, I couldn't confirm that in zsh)

@Kudo
Copy link
Contributor

Kudo commented Jan 3, 2022

thanks @zaubara. the call flow is expected to have $current_shell as bash because Xcode build phase script by default use bash. the unclear part for me is that even $current_shell is bash in your case, how would it run in zsh? could you help to clarify for this?

@zaubara
Copy link
Author

zaubara commented Jan 4, 2022

Well, that's exactly the issue. ~/.bash_profile gets sourced, due to this:

else
   # Bash's setup script order is:
   #   /etc/profile (if it exists)
   #   The first of: ~/.bash_profile, ~/.bash_login, and ~/.profile
   # https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html

   if [ -f /etc/profile ]; then . /etc/profile; fi

   if [ -f ~/.bash_profile ]; then
      . ~/.bash_profile
   elif [ -f ~/.bash_login ]; then
      . ~/.bash_login
   elif [ -f ~/.profile ]; then
      . ~/.profile
   fi
fi

But this fails silently, if there's bash-specific code in any of those. I'm just suspecting them being run in zsh, because I can see an error when running it manually in zsh, and building works after removing the offending lines.

@Kudo
Copy link
Contributor

Kudo commented Jan 4, 2022

yep, so i would like to know why it transit from bash to zsh. maybe you can verify with these serial commands and make sure the shell insist in bash:

$ ps -cp "$$" -o comm="" | sed s/^-//
bash

$ if [ -f /etc/profile ]; then . /etc/profile; fi
$ ps -cp "$$" -o comm="" | sed s/^-//
bash

$  if [ -f ~/.bash_profile ]; then . ~/.bash_profile; fi
$ ps -cp "$$" -o comm="" | sed s/^-//
bash

$  if [ -f ~/.bash_login ]; then . ~/.bash_login; fi
$ ps -cp "$$" -o comm="" | sed s/^-//
bash

$  if [ -f ~/.profile ]; then . ~/.profile; fi
$ ps -cp "$$" -o comm="" | sed s/^-//
bash

Kudo added a commit that referenced this issue Jan 20, 2022
…ed (#15890)

# Why

fix #15809
fix #15723

# How

suppress the errors from sourcing the `source-login-scripts.sh`

# Test Plan

```sh
$ echo 'this_is_an_invalid_command >> ~/.bash_profile
$ expo run:ios
```
Kudo added a commit that referenced this issue Jan 20, 2022
…ed (#15890)

fix #15809
fix #15723

suppress the errors from sourcing the `source-login-scripts.sh`

```sh
$ echo 'this_is_an_invalid_command >> ~/.bash_profile
$ expo run:ios
```
@Kudo
Copy link
Contributor

Kudo commented Jan 20, 2022

published expo-constants@13.0.1 with the fix. please upgrade and try again. thanks!

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

Successfully merging a pull request may close this issue.

4 participants