Skip to content

Commit da01f60

Browse files
Kudoide
authored and
Duc Nguyen Duy
committed
Deprecate source-login-scripts.sh (expo#18330)
# Why the `source-login-scripts.sh` introduced a lot of pain where the community reported much build errors from it. it doesn't support shells other than zsh and bash. this pr find a new way to deal with xcode building issues that it cannot find the correct nodejs path. close ENG-4864 close ENG-5242 # How react-native introduces `.xcode.env` and `.xcode.env.local` for developers to override the `$NODE_BINARY`: facebook/react-native#33546 to make sure building success from expo-constants, expo-updates, and also the app target when generating bundles. i would like to reuse the `.xcode.env` and `.xcode.env.local` from react-native. this pr further generates `.xcode.env.local` automatically for the app during `pod install`. we can ensure that `pod install` is executed from shell and nodejs is available. so we will generate `export NODE_BINARY="$(command -v node)"` in the `.xcode.env.local`. for xcode, the path will be `$PODS_ROOT/../.xcode.env.local`, every xcode subprojects can source the file to get correct `$NODE_BINARY`. # Test Plan - building bare-expo from xcode (opening xcode by macos finder) - building bare-expo by `yarn ios` - updates e2e ci passed - building expo-go (prerequisite: expo#18344) Co-authored-by: James Ide <[email protected]>
1 parent 0878838 commit da01f60

File tree

33 files changed

+198
-223
lines changed

33 files changed

+198
-223
lines changed

Diff for: .gitattributes

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
*.pbxproj binary linguist-generated
2-
ios/Exponent.xcodeproj/project.pbxproj merge=union -text diff linguist-generated
3-
apps/bare-expo/ios/BareExpo.xcodeproj/project.pbxproj merge=union -text diff linguist-generated
4-
apps/bare-sandbox/ios/bare-sandbox.xcodeproj/project.pbxproj merge=union -text diff linguist-generated
5-
templates/expo-template-bare-minimum/ios/HelloWorld.xcodeproj/project.pbxproj merge=union -text diff linguist-generated
1+
*.pbxproj merge=union -text diff linguist-generated
62
packages/*/build/** -diff linguist-generated
73
packages/*/plugin/build/** -diff linguist-generated
84
packages/@*/*/build/** -diff linguist-generated

Diff for: .github/actions/expo-caches/action.yml

-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ runs:
107107
id: tools-modules-cache
108108
with:
109109
path: |
110-
bin/et
111-
bin/expotools
112110
tools/node_modules
113111
key: ${{ runner.os }}-tools-modules-${{ hashFiles('tools/yarn.lock') }}
114112

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,5 @@ docs/pages/versions/*/react-native/*.diff
148148
# iOS
149149
/ios/Pods
150150
/ios/build
151+
**/ios/.xcode.env.local
151152
/.vs

Diff for: android/expoview/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,12 @@ class GenerateDynamicMacrosPlugin implements Plugin<Project> {
235235
it.toLowerCase().contains("release")
236236
} ? "release" : "debug"
237237

238-
workingDir '../../tools/bin'
238+
workingDir '../../bin'
239239

240240
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
241-
commandLine 'cmd.exe', '/c', "expotools.js android-generate-dynamic-macros --configuration ${configuration}"
241+
commandLine 'cmd.exe', '/c', "expotools android-generate-dynamic-macros --configuration ${configuration}"
242242
} else {
243-
commandLine "./expotools.js", "android-generate-dynamic-macros", "--configuration", configuration
243+
commandLine "./expotools", "android-generate-dynamic-macros", "--configuration", configuration
244244
}
245245
}
246246
}

Diff for: apps/bare-expo/ios/BareExpo.xcodeproj/project.pbxproj

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: apps/bare-expo/ios/Build-Phases/generate-dynamic-macros.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
set -exo pipefail
44

5-
if [ -z "$EXPO_TOOLS_DIR" ]; then
5+
if [[ -z "$EXPO_TOOLS_DIR" ]]; then
66
EXPO_TOOLS_DIR="${SRCROOT}/../../../tools"
77
fi
88

9-
# Sourcing login scripts on macOS-11 runners is broken but can be omitted.
10-
if [ -z "$CI" ]; then
11-
source ${EXPO_TOOLS_DIR}/source-login-scripts.sh
9+
if [[ -f "$PODS_ROOT/../.xcode.env" ]]; then
10+
source "$PODS_ROOT/../.xcode.env"
11+
fi
12+
if [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then
13+
source "$PODS_ROOT/../.xcode.env.local"
1214
fi
1315

1416
export PATH="${SRCROOT}/../../../bin:$PATH"

Diff for: apps/bare-expo/scripts/setup-android-project.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ else
99
yarn
1010
fi
1111

12-
../../tools/bin/expotools.js android-generate-dynamic-macros --configuration $1 --bare
12+
CURR_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
13+
"${CURR_DIR}/../../../bin/expotools" android-generate-dynamic-macros --configuration $1 --bare
1314
echo " ✅ Generete dynamic macros"

Diff for: apps/bare-sandbox/ios/bare-sandbox.xcodeproj/project.pbxproj

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: apps/native-tests/ios/NativeTests.xcodeproj/project.pbxproj

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: bin/expotools

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ set -euo pipefail
55
script_dir=$(dirname "$0")
66
repository_root="${script_dir}/.."
77
expotools_dir="`cd ${repository_root}/tools;pwd;`"
8+
NODE_BINARY=${NODE_BINARY:-node}
89

9-
exec "${expotools_dir}/bin/expotools.js" "$@"
10+
$NODE_BINARY "${expotools_dir}/bin/expotools.js" "$@"

Diff for: ios/Build-Phases/generate-dynamic-macros.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
set -exo pipefail
44

5-
if [ -z "$EXPO_TOOLS_DIR" ]; then
5+
if [[ -z "$EXPO_TOOLS_DIR" ]]; then
66
EXPO_TOOLS_DIR="${SRCROOT}/../tools"
77
fi
88

9-
# Sourcing login scripts on macOS-11 runners is broken but can be omitted.
10-
if [ -z "$CI" ]; then
11-
source ${EXPO_TOOLS_DIR}/source-login-scripts.sh
9+
if [[ -f "$PODS_ROOT/../.xcode.env" ]]; then
10+
source "$PODS_ROOT/../.xcode.env"
11+
fi
12+
if [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then
13+
source "$PODS_ROOT/../.xcode.env.local"
1214
fi
1315

1416
export PATH="${SRCROOT}/../bin:$PATH"

Diff for: packages/expo-constants/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### 🐛 Bug fixes
1010

11+
- Deprecated the unreliable `source-login-scripts.sh` and sourcing the Node.js binary path from `.xcode.env` and `.xcode.env.local`. ([#18330](https://github.com/expo/expo/pull/18330) by [@kudo](https://github.com/kudo))
12+
1113
### 💡 Others
1214

1315
## 13.2.2 — 2022-07-16

Diff for: packages/expo-constants/scripts/get-app-config-ios.sh

+2-18
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,7 @@ set -eo pipefail
44

55
DEST="$CONFIGURATION_BUILD_DIR"
66
RESOURCE_BUNDLE_NAME="EXConstants.bundle"
7-
# ref: https://github.com/facebook/react-native/blob/c974cbff04a8d90ac0f856dbada3fc5a75c75b49/scripts/react-native-xcode.sh#L59-L65
8-
# Path to expo-constants folder inside node_modules
9-
EXPO_CONSTANTS_PACKAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
10-
11-
# Suppress environment errors from sourcing the login scripts
12-
set +e
13-
source "$EXPO_CONSTANTS_PACKAGE_DIR/scripts/source-login-scripts.sh"
14-
set -e
15-
16-
NODE_BINARY=${NODE_BINARY:-node}
17-
18-
if ! [ -x "$(command -v "$NODE_BINARY")" ]; then
19-
echo 'Error: cannot find the node binary. Try setting the NODE_BINARY variable in the ' \
20-
'"Bundle React Native code and images" Build Phase to the absolute path to your node binary. ' \
21-
'You can find it by executing "which node" in a terminal window.' >&2
22-
exit 1
23-
fi
7+
EXPO_CONSTANTS_PACKAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
248

259
# For classic main project build phases integration, will be no-op to prevent duplicated app.config creation.
2610
#
@@ -38,4 +22,4 @@ PROJECT_ROOT=${PROJECT_ROOT:-"$EXPO_CONSTANTS_PACKAGE_DIR/../.."}
3822

3923
cd "$PROJECT_ROOT" || exit
4024

41-
"$NODE_BINARY" "${EXPO_CONSTANTS_PACKAGE_DIR}/scripts/getAppConfig.js" "$PROJECT_ROOT" "$DEST/$RESOURCE_BUNDLE_NAME"
25+
"${EXPO_CONSTANTS_PACKAGE_DIR}/scripts/with-node.sh" "${EXPO_CONSTANTS_PACKAGE_DIR}/scripts/getAppConfig.js" "$PROJECT_ROOT" "$DEST/$RESOURCE_BUNDLE_NAME"

Diff for: packages/expo-constants/scripts/source-login-scripts.sh

-52
This file was deleted.

Diff for: packages/expo-constants/scripts/with-node.sh

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# Copyright 2018-present 650 Industries. All rights reserved.
4+
#
5+
# @generated by expo-module-scripts
6+
#
7+
# USAGE:
8+
# ./with-node.sh command
9+
10+
CURR_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
11+
12+
# Start with a default
13+
NODE_BINARY=$(command -v node)
14+
export NODE_BINARY
15+
16+
# Override the default with the global environment
17+
ENV_PATH="$PODS_ROOT/../.xcode.env"
18+
if [[ -f "$ENV_PATH" ]]; then
19+
source "$ENV_PATH"
20+
fi
21+
22+
# Override the global with the local environment
23+
LOCAL_ENV_PATH="${ENV_PATH}.local"
24+
if [[ -f "$LOCAL_ENV_PATH" ]]; then
25+
source "$LOCAL_ENV_PATH"
26+
fi
27+
28+
if [[ -n "$NODE_BINARY" && -x "$NODE_BINARY" ]]; then
29+
echo "Node found at: ${NODE_BINARY}"
30+
else
31+
cat >&2 << EOF
32+
[ERROR] Could not find "node" while running an Xcode build script. You need to specify the path to your Node.js executable by defining an environment variable named NODE_BINARY in your project's .xcode.env or .xcode.env.local file. You can set this up quickly by running:
33+
34+
echo "export NODE_BINARY=\$(command -v node)" >> .xcode.env
35+
36+
in the ios folder of your project.
37+
EOF
38+
exit 1
39+
fi
40+
41+
# Execute argument, if present
42+
if [[ "$#" -gt 0 ]]; then
43+
"$NODE_BINARY" $@
44+
fi

Diff for: packages/expo-module-scripts/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Fixed `expo-module prepare` error if target packages contain temporary kotlin build files. ([#17023](https://github.com/expo/expo/pull/17023) by [@kudo](https://github.com/kudo))
1515
- Improved support of nvm sourcing in iOS shell scripts. ([#17109](https://github.com/expo/expo/pull/17109) by [@liamronancb](https://github.com/liamronancb))
1616
- Fixed `source-login-scripts.sh` ~/zlogin typo. ([#17622](https://github.com/expo/expo/pull/17622) by [@vrgimael](https://github.com/vrgimael))
17+
- Deprecated the unreliable `source-login-scripts.sh` and sourcing the Node.js binary path from `.xcode.env` and `.xcode.env.local`. ([#18330](https://github.com/expo/expo/pull/18330) by [@kudo](https://github.com/kudo))
1718

1819
### 💡 Others
1920

Diff for: packages/expo-module-scripts/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Running `yarn` will now run the `prepare` script, which generates any missing fi
6767

6868
Besides, running `yarn prepare` script will also synchronize optional files from `expo-module-scripts` when the file is present and contains the `@generated` pattern:
6969

70-
- [`source-login-scripts.sh`](./templates/scripts/source-login-scripts.sh): An Xcode build phase script helper for Node.js binary resolution. For example, we need to source login shell configs for `nvm`.
70+
- [`with-node.sh`](./templates/scripts/with-node.sh): An Xcode build phase script helper for Node.js binary resolution. It sources the project's **.xcode.env** and **.xcode.env.local** files, which may define an environment variable named `NODE_BINARY` to specify the file path of the Node.js binary to run.
7171

7272
### 🔌 Config Plugin
7373

Diff for: packages/expo-module-scripts/bin/expo-module-configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ shopt -s dotglob
1010
# and its content contains the string `@generated`.
1111
OPTIONAL_TEMPLATE_FILES=(
1212
# add a relative file path from `templates/` for each new optional file
13-
"scripts/source-login-scripts.sh"
13+
"scripts/with-node.sh"
1414
)
1515

1616
# returns relative file paths inside a given directory without the leading "./".

Diff for: packages/expo-module-scripts/templates/scripts/source-login-scripts.sh

-52
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# Copyright 2018-present 650 Industries. All rights reserved.
4+
#
5+
# @generated by expo-module-scripts
6+
#
7+
# USAGE:
8+
# ./with-node.sh command
9+
10+
CURR_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
11+
12+
# Start with a default
13+
NODE_BINARY=$(command -v node)
14+
export NODE_BINARY
15+
16+
# Override the default with the global environment
17+
ENV_PATH="$PODS_ROOT/../.xcode.env"
18+
if [[ -f "$ENV_PATH" ]]; then
19+
source "$ENV_PATH"
20+
fi
21+
22+
# Override the global with the local environment
23+
LOCAL_ENV_PATH="${ENV_PATH}.local"
24+
if [[ -f "$LOCAL_ENV_PATH" ]]; then
25+
source "$LOCAL_ENV_PATH"
26+
fi
27+
28+
if [[ -n "$NODE_BINARY" && -x "$NODE_BINARY" ]]; then
29+
echo "Node found at: ${NODE_BINARY}"
30+
else
31+
cat >&2 << EOF
32+
[ERROR] Could not find "node" while running an Xcode build script. You need to specify the path to your Node.js executable by defining an environment variable named NODE_BINARY in your project's .xcode.env or .xcode.env.local file. You can set this up quickly by running:
33+
34+
echo "export NODE_BINARY=\$(command -v node)" >> .xcode.env
35+
36+
in the ios folder of your project.
37+
EOF
38+
exit 1
39+
fi
40+
41+
# Execute argument, if present
42+
if [[ "$#" -gt 0 ]]; then
43+
"$NODE_BINARY" $@
44+
fi

0 commit comments

Comments
 (0)