2018-01-22 23:03:11 +03:00
|
|
|
#!/bin/bash
|
2018-09-12 01:27:47 +03:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
2018-01-22 23:03:11 +03:00
|
|
|
#
|
2018-02-17 05:24:55 +03:00
|
|
|
# This source code is licensed under the MIT license found in the
|
|
|
|
# LICENSE file in the root directory of this source tree.
|
2019-10-16 06:08:07 +03:00
|
|
|
|
2018-01-22 23:03:11 +03:00
|
|
|
# Bundle React Native app's code and image assets.
|
|
|
|
# This script is supposed to be invoked as part of Xcode build process
|
|
|
|
# and relies on environment variables (including PWD) set by Xcode
|
|
|
|
|
2018-08-21 04:28:52 +03:00
|
|
|
# Print commands before executing them (useful for troubleshooting)
|
|
|
|
set -x
|
|
|
|
DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH
|
|
|
|
|
2019-08-16 20:35:31 +03:00
|
|
|
# Enables iOS devices to get the IP address of the machine running Metro
|
2018-08-21 04:28:52 +03:00
|
|
|
if [[ "$CONFIGURATION" = *Debug* && ! "$PLATFORM_NAME" == *simulator ]]; then
|
2020-04-28 19:29:43 +03:00
|
|
|
for num in 0 1 2 3 4 5 6 7 8; do
|
|
|
|
IP=$(ipconfig getifaddr en${num})
|
|
|
|
if [ ! -z "$IP" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
iOS build - en0 and en1 used when generating ip.txt file (#25462)
Summary:
When `en0` is not assigned and `en1` is in use along with another interface present on the machine that uses a self-assigned address (169.254.xxx.xxx), the ip.txt file contains the self-assigned address. This causes the app reload/debug actions to fail when deployed to a physical device. see https://github.com/facebook/react-native/issues/25460
Code change looks at the value assigned to `en1` if `en0` is not set. If `en1` is not available on the machine or not set, then it will be empty. If both `en0` and `en1` are not set, the existing code was modified exclude addresses that are self-assigned, as they will most likely be unavailable to the connected device (iPhone, iPad, etc.).
## Changelog
[Internal] [Fixed] - en0 and en1 are used when generating the ip.txt file for iOS device debug builds
Pull Request resolved: https://github.com/facebook/react-native/pull/25462
Test Plan:
execute `ifconfig`:
```
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
nd6 options=201<PERFORMNUD,DAD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
XHC20: flags=0<> mtu 0
XHC0: flags=0<> mtu 0
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
ether 38:f9:d3:0d:aa:fe
nd6 options=201<PERFORMNUD,DAD>
media: autoselect (none)
status: inactive
en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
options=60<TSO4,TSO6>
ether 42:00:84:a8:f6:00
media: autoselect <full-duplex>
status: inactive
en3: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
options=60<TSO4,TSO6>
ether 42:00:84:a8:f6:01
media: autoselect <full-duplex>
status: active
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=63<RXCSUM,TXCSUM,TSO4,TSO6>
ether 42:00:84:a8:f6:00
inet6 fe80::e:80be:b322:79b7%bridge0 prefixlen 64 secured scopeid 0x9
inet 169.254.209.63 netmask 0xffff0000 broadcast 169.254.255.255
Configuration:
id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
ipfilter disabled flags 0x2
member: en2 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 7 priority 0 path cost 0
member: en3 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 8 priority 0 path cost 0
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
ap1: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
ether 3a:f9:d3:9a:14:05
media: autoselect
status: inactive
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 38:f9:d3:9a:14:05
inet6 fe80::1444:113e:d65:5fb3%en1 prefixlen 64 secured scopeid 0xb
inet 192.168.1.115 netmask 0xffffff00 broadcast 192.168.1.255
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
ether 0a:f9:d3:9a:14:05
media: autoselect
status: inactive
awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1484
ether 6a:fe:9d:f0:39:3f
inet6 fe80::68fe:9dff:fef0:393f%awdl0 prefixlen 64 scopeid 0xd
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
inet6 fe80::c992:4ed:9399:85bc%utun0 prefixlen 64 scopeid 0xe
nd6 options=201<PERFORMNUD,DAD>
utun1: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1380
inet6 fe80::f5de:860a:fd07:ee87%utun1 prefixlen 64 scopeid 0xf
nd6 options=201<PERFORMNUD,DAD>
utun2: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1380
inet6 fe80::3115:b6a0:6625:23ee%utun2 prefixlen 64 scopeid 0x11
nd6 options=201<PERFORMNUD,DAD>
en5: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether e2:33:8e:95:93:9b
inet6 fe80::cea:8f7a:b379:ebcd%en5 prefixlen 64 secured scopeid 0x10
inet 169.254.167.11 netmask 0xffff0000 broadcast 169.254.255.255
nd6 options=201<PERFORMNUD,DAD>
media: autoselect (100baseTX <full-duplex>)
status: active
```
execute `ipconfig getifaddr en0`: (produces nothing)
execute `ipconfig getifaddr en1`:
```
192.168.1.115
```
execute `ipconfig getifaddr en99`: (produces nothing - non-existent case)
existing code `ifconfig | grep 'inet ' | grep -v ' 127.' | cut -d\ -f2 | awk 'NR==1{print $1}'` yields:
```
169.254.209.63
```
modified code ` ifconfig | grep 'inet ' | grep -v ' 127.' | grep -v ' 169.254.' | cut -d\ -f2 | awk 'NR==1{print $1}'` yields:
```
192.168.1.115
```
Differential Revision: D16099639
Pulled By: cpojer
fbshipit-source-id: bd480a5f638efc58611d22cef4ba5193052b713d
2019-07-03 12:27:49 +03:00
|
|
|
if [ -z "$IP" ]; then
|
|
|
|
IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | grep -v ' 169.254.' |cut -d\ -f2 | awk 'NR==1{print $1}')
|
2018-08-21 04:28:52 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$IP" > "$DEST/ip.txt"
|
|
|
|
fi
|
|
|
|
|
2018-01-22 23:03:11 +03:00
|
|
|
if [[ "$SKIP_BUNDLING" ]]; then
|
|
|
|
echo "SKIP_BUNDLING enabled; skipping."
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$CONFIGURATION" in
|
|
|
|
*Debug*)
|
|
|
|
if [[ "$PLATFORM_NAME" == *simulator ]]; then
|
|
|
|
if [[ "$FORCE_BUNDLING" ]]; then
|
|
|
|
echo "FORCE_BUNDLING enabled; continuing to bundle."
|
|
|
|
else
|
|
|
|
echo "Skipping bundling in Debug for the Simulator (since the packager bundles for you). Use the FORCE_BUNDLING flag to change this behavior."
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Bundling for physical device. Use the SKIP_BUNDLING flag to change this behavior."
|
|
|
|
fi
|
|
|
|
|
|
|
|
DEV=true
|
|
|
|
;;
|
|
|
|
"")
|
|
|
|
echo "$0 must be invoked by Xcode"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
DEV=false
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-09-22 16:14:20 +03:00
|
|
|
# Path to react-native folder inside node_modules
|
|
|
|
REACT_NATIVE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
|
# The project should be located next to where react-native is installed
|
|
|
|
# in node_modules.
|
|
|
|
PROJECT_ROOT=${PROJECT_ROOT:-"$REACT_NATIVE_DIR/../.."}
|
2018-01-22 23:03:11 +03:00
|
|
|
|
2019-05-13 17:26:47 +03:00
|
|
|
cd "$PROJECT_ROOT" || exit
|
2018-01-22 23:03:11 +03:00
|
|
|
|
|
|
|
# Define entry file
|
2019-02-28 00:30:50 +03:00
|
|
|
if [[ "$ENTRY_FILE" ]]; then
|
|
|
|
# Use ENTRY_FILE defined by user
|
|
|
|
:
|
|
|
|
elif [[ -s "index.ios.js" ]]; then
|
2020-06-18 23:24:23 +03:00
|
|
|
ENTRY_FILE=${1:-index.ios.js}
|
|
|
|
else
|
|
|
|
ENTRY_FILE=${1:-index.js}
|
|
|
|
fi
|
|
|
|
|
2021-09-01 10:15:04 +03:00
|
|
|
if [[ $DEV != true && ! -f "$ENTRY_FILE" ]]; then
|
2020-06-18 23:24:23 +03:00
|
|
|
echo "error: Entry file $ENTRY_FILE does not exist. If you use another file as your entry point, pass ENTRY_FILE=myindex.js" >&2
|
|
|
|
exit 2
|
2018-01-22 23:03:11 +03:00
|
|
|
fi
|
|
|
|
|
2021-04-02 23:55:18 +03:00
|
|
|
# Find path to Node
|
|
|
|
# shellcheck source=/dev/null
|
2021-09-17 20:10:43 +03:00
|
|
|
source "$REACT_NATIVE_DIR/scripts/find-node.sh"
|
2019-01-16 03:11:10 +03:00
|
|
|
|
2019-04-10 17:35:59 +03:00
|
|
|
# check and assign NODE_BINARY env
|
2019-04-30 13:05:06 +03:00
|
|
|
# shellcheck source=/dev/null
|
|
|
|
source "$REACT_NATIVE_DIR/scripts/node-binary.sh"
|
2018-01-22 23:03:11 +03:00
|
|
|
|
2020-11-03 12:13:01 +03:00
|
|
|
[ -z "$HERMES_CLI_PATH" ] && HERMES_CLI_PATH="$PODS_ROOT/hermes-engine/destroot/bin/hermesc"
|
|
|
|
|
|
|
|
if [[ -z "$USE_HERMES" && -f "$HERMES_CLI_PATH" ]]; then
|
|
|
|
echo "Enabling Hermes byte-code compilation. Disable with USE_HERMES=false if needed."
|
|
|
|
USE_HERMES=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $USE_HERMES == true && ! -f "$HERMES_CLI_PATH" ]]; then
|
|
|
|
echo "error: USE_HERMES is set to true but the hermesc binary could not be " \
|
2021-10-02 07:21:03 +03:00
|
|
|
"found at ${HERMES_CLI_PATH}. Perhaps you need to run 'bundle exec pod install' or otherwise " \
|
2020-11-03 12:13:01 +03:00
|
|
|
"point the HERMES_CLI_PATH variable to your custom location." >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2018-12-01 04:27:53 +03:00
|
|
|
[ -z "$NODE_ARGS" ] && export NODE_ARGS=""
|
|
|
|
|
2018-12-11 06:04:56 +03:00
|
|
|
[ -z "$CLI_PATH" ] && export CLI_PATH="$REACT_NATIVE_DIR/cli.js"
|
2018-01-22 23:03:11 +03:00
|
|
|
|
|
|
|
[ -z "$BUNDLE_COMMAND" ] && BUNDLE_COMMAND="bundle"
|
|
|
|
|
2020-08-27 11:16:30 +03:00
|
|
|
[ -z "$COMPOSE_SOURCEMAP_PATH" ] && COMPOSE_SOURCEMAP_PATH="$REACT_NATIVE_DIR/scripts/compose-source-maps.js"
|
|
|
|
|
2018-01-22 23:03:11 +03:00
|
|
|
if [[ -z "$BUNDLE_CONFIG" ]]; then
|
|
|
|
CONFIG_ARG=""
|
|
|
|
else
|
2019-01-29 07:09:55 +03:00
|
|
|
CONFIG_ARG="--config $BUNDLE_CONFIG"
|
2018-01-22 23:03:11 +03:00
|
|
|
fi
|
|
|
|
|
2020-08-27 11:16:30 +03:00
|
|
|
BUNDLE_FILE="$CONFIGURATION_BUILD_DIR/main.jsbundle"
|
|
|
|
|
2021-09-28 21:12:58 +03:00
|
|
|
EXTRA_ARGS=()
|
2020-08-27 11:16:30 +03:00
|
|
|
|
|
|
|
case "$PLATFORM_NAME" in
|
|
|
|
"macosx")
|
|
|
|
BUNDLE_PLATFORM="macos"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
BUNDLE_PLATFORM="ios"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2021-06-11 11:09:43 +03:00
|
|
|
if [ "${IS_MACCATALYST}" = "YES" ]; then
|
|
|
|
BUNDLE_PLATFORM="ios"
|
|
|
|
fi
|
|
|
|
|
2020-08-27 11:16:30 +03:00
|
|
|
EMIT_SOURCEMAP=
|
|
|
|
if [[ ! -z "$SOURCEMAP_FILE" ]]; then
|
|
|
|
EMIT_SOURCEMAP=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
PACKAGER_SOURCEMAP_FILE=
|
|
|
|
if [[ $EMIT_SOURCEMAP == true ]]; then
|
|
|
|
if [[ $USE_HERMES == true ]]; then
|
|
|
|
PACKAGER_SOURCEMAP_FILE="$CONFIGURATION_BUILD_DIR/$(basename $SOURCEMAP_FILE)"
|
|
|
|
else
|
|
|
|
PACKAGER_SOURCEMAP_FILE="$SOURCEMAP_FILE"
|
|
|
|
fi
|
2021-09-28 21:12:58 +03:00
|
|
|
EXTRA_ARGS+=("--sourcemap-output" "$PACKAGER_SOURCEMAP_FILE")
|
2020-08-27 11:16:30 +03:00
|
|
|
fi
|
2018-01-22 23:03:11 +03:00
|
|
|
|
2020-12-02 04:15:07 +03:00
|
|
|
# Hermes doesn't require JS minification.
|
|
|
|
if [[ $USE_HERMES == true && $DEV == false ]]; then
|
2021-09-28 21:12:58 +03:00
|
|
|
EXTRA_ARGS+=("--minify" "false")
|
2020-12-02 04:15:07 +03:00
|
|
|
fi
|
|
|
|
|
2018-12-01 04:27:53 +03:00
|
|
|
"$NODE_BINARY" $NODE_ARGS "$CLI_PATH" $BUNDLE_COMMAND \
|
2018-01-22 23:03:11 +03:00
|
|
|
$CONFIG_ARG \
|
|
|
|
--entry-file "$ENTRY_FILE" \
|
2020-08-27 11:16:30 +03:00
|
|
|
--platform "$BUNDLE_PLATFORM" \
|
2018-01-22 23:03:11 +03:00
|
|
|
--dev $DEV \
|
|
|
|
--reset-cache \
|
|
|
|
--bundle-output "$BUNDLE_FILE" \
|
|
|
|
--assets-dest "$DEST" \
|
2021-09-28 21:12:58 +03:00
|
|
|
"${EXTRA_ARGS[@]}" \
|
|
|
|
"${EXTRA_PACKAGER_ARGS[@]}"
|
2018-01-22 23:03:11 +03:00
|
|
|
|
2020-08-27 11:16:30 +03:00
|
|
|
if [[ $USE_HERMES != true ]]; then
|
2020-10-23 03:53:51 +03:00
|
|
|
cp "$BUNDLE_FILE" "$DEST/"
|
2020-08-27 11:16:30 +03:00
|
|
|
BUNDLE_FILE="$DEST/main.jsbundle"
|
|
|
|
else
|
|
|
|
EXTRA_COMPILER_ARGS=
|
|
|
|
if [[ $DEV == true ]]; then
|
|
|
|
EXTRA_COMPILER_ARGS=-Og
|
|
|
|
else
|
|
|
|
EXTRA_COMPILER_ARGS=-O
|
|
|
|
fi
|
|
|
|
if [[ $EMIT_SOURCEMAP == true ]]; then
|
|
|
|
EXTRA_COMPILER_ARGS="$EXTRA_COMPILER_ARGS -output-source-map"
|
|
|
|
fi
|
2020-12-02 04:15:07 +03:00
|
|
|
"$HERMES_CLI_PATH" -emit-binary $EXTRA_COMPILER_ARGS -out "$DEST/main.jsbundle" "$BUNDLE_FILE"
|
2020-08-27 11:16:30 +03:00
|
|
|
if [[ $EMIT_SOURCEMAP == true ]]; then
|
2020-11-03 12:13:01 +03:00
|
|
|
HBC_SOURCEMAP_FILE="$BUNDLE_FILE.map"
|
2020-08-27 11:16:30 +03:00
|
|
|
"$NODE_BINARY" "$COMPOSE_SOURCEMAP_PATH" "$PACKAGER_SOURCEMAP_FILE" "$HBC_SOURCEMAP_FILE" -o "$SOURCEMAP_FILE"
|
|
|
|
fi
|
2020-11-03 12:13:01 +03:00
|
|
|
BUNDLE_FILE="$DEST/main.jsbundle"
|
2020-08-27 11:16:30 +03:00
|
|
|
fi
|
|
|
|
|
2018-01-22 23:03:11 +03:00
|
|
|
if [[ $DEV != true && ! -f "$BUNDLE_FILE" ]]; then
|
|
|
|
echo "error: File $BUNDLE_FILE does not exist. This must be a bug with" >&2
|
|
|
|
echo "React Native, please report it here: https://github.com/facebook/react-native/issues"
|
|
|
|
exit 2
|
|
|
|
fi
|