mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d1e6f8d3c4
Summary: React-native server-device connection must be via Wi-Fi. But if the OS-X server has LAN & Wi-Fi interfaces, then device bundle can be incorrectly configured to use LAN interface instead of Wi-Fi. This patch fix this issue. It greps for "baseT" (e.g. media: autoselect (1000baseT <full-duplex>)) and skip interface if it is. ## Changelog [iOS] [Fixed] - Fix LAN instead of Wi-Fi device bundle configuration Pull Request resolved: https://github.com/facebook/react-native/pull/27575 Test Plan: To reproduce an issue setup Mac OS 10.15.1 with LAN and Wi-Fi active interfaces. And connect real device (not simulator). And "ifconfig en0" in console should display LAN interface e.g.: ``` en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 options=50b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV,CHANNEL_IO> ether 78:7b:8a:d8:61:42 inet 10.15.61.16 netmask 0xffffff00 broadcast 10.15.61.255 nd6 options=201<PERFORMNUD,DAD> media: autoselect (1000baseT <full-duplex>) status: active ``` "ifconfig eg1" in console should display WiFi interface e.g.: ``` en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 options=400<CHANNEL_IO> ether 14:20:5e:03:5b:2a inet6 fe80::10e6:1cb6:54ec:1b41%en1 prefixlen 64 secured scopeid 0x5 inet 10.15.91.27 netmask 0xffffff00 broadcast 10.15.91.255 nd6 options=201<PERFORMNUD,DAD> media: autoselect status: active ``` In this case device bundle in react-native-xcode.sh script wood be incorrectly configured to use en0 (LAN interface) instead of en1(Wi-Fi) interface. My patch fixes this issue. fragment of script output before patch: ``` ... ++ ipconfig getifaddr en0 + IP=10.15.61.16 + '[' -z 10.15.61.16 '] + '[' -z 10.15.61.16 ']' + echo 10.15.61.16 + [[ -n '' ]] ... ``` After start project ob device we have time lag about 20s then debug out: ` 2019-12-20 16:58:57.530538+0300 AwesomeProject[4590:1923358] Task <164D9AB0-8473-4BA3-BD1A-EC0E92887C17>.<1> finished with error [-1001] Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSUnderlyingError=0x2838dc2d0 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=http://10.15.61.16:8081/status, NSErrorFailingURLKey=http://10.15.61.16:8081/status, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=The request timed out.} ` fragment of script output after apply patch: ``` ... ++ ipconfig getifaddr en0 + IP=10.15.61.16 + [[ -z 10.15.61.16 ]] ++ ifconfig ++ grep baseT + [[ -n media: autoselect (1000baseT <full-duplex>) media: autoselect (100baseTX <full-duplex>) ]] ++ ipconfig getifaddr en1 + IP=10.15.91.27 + '[' -z 10.15.91.27 ']' + echo 10.15.91.27 + [[ -n '' ]] ... ``` App start OK. On iPhone /iPad simulator works too. Differential Revision: D19200334 Pulled By: hramos fbshipit-source-id: 22d791b657abd16a92d075515682b4fa961b489c
132 lines
3.8 KiB
Bash
Executable File
132 lines
3.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
#
|
|
# This source code is licensed under the MIT license found in the
|
|
# LICENSE file in the root directory of this source tree.
|
|
|
|
# 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
|
|
|
|
# Print commands before executing them (useful for troubleshooting)
|
|
set -x
|
|
DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH
|
|
|
|
# Enables iOS devices to get the IP address of the machine running Metro
|
|
if [[ "$CONFIGURATION" = *Debug* && ! "$PLATFORM_NAME" == *simulator ]]; then
|
|
IP=$(ipconfig getifaddr en0)
|
|
if [[ -z "$IP" || -n "`ifconfig $value | grep 'baseT'`" ]]; then
|
|
IP=$(ipconfig getifaddr en1)
|
|
fi
|
|
if [ -z "$IP" ]; then
|
|
IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | grep -v ' 169.254.' |cut -d\ -f2 | awk 'NR==1{print $1}')
|
|
fi
|
|
|
|
echo "$IP" > "$DEST/ip.txt"
|
|
fi
|
|
|
|
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
|
|
|
|
# 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/../.."}
|
|
|
|
cd "$PROJECT_ROOT" || exit
|
|
|
|
# Define NVM_DIR and source the nvm.sh setup script
|
|
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
|
|
|
|
# Define entry file
|
|
if [[ "$ENTRY_FILE" ]]; then
|
|
# Use ENTRY_FILE defined by user
|
|
:
|
|
elif [[ -s "index.ios.js" ]]; then
|
|
ENTRY_FILE=${1:-index.ios.js}
|
|
else
|
|
ENTRY_FILE=${1:-index.js}
|
|
fi
|
|
|
|
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
|
|
. "$HOME/.nvm/nvm.sh"
|
|
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
|
|
. "$(brew --prefix nvm)/nvm.sh"
|
|
fi
|
|
|
|
# Set up the nodenv node version manager if present
|
|
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
|
|
eval "$("$HOME/.nodenv/bin/nodenv" init -)"
|
|
elif [[ -x "$(command -v brew)" && -x "$(brew --prefix nodenv)/bin/nodenv" ]]; then
|
|
eval "$("$(brew --prefix nodenv)/bin/nodenv" init -)"
|
|
fi
|
|
|
|
# Set up the ndenv of anyenv if preset
|
|
if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
|
|
export PATH=${HOME}/.anyenv/bin:${PATH}
|
|
if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then
|
|
eval "$(anyenv init -)"
|
|
fi
|
|
fi
|
|
|
|
# check and assign NODE_BINARY env
|
|
# shellcheck source=/dev/null
|
|
source "$REACT_NATIVE_DIR/scripts/node-binary.sh"
|
|
|
|
[ -z "$NODE_ARGS" ] && export NODE_ARGS=""
|
|
|
|
[ -z "$CLI_PATH" ] && export CLI_PATH="$REACT_NATIVE_DIR/cli.js"
|
|
|
|
[ -z "$BUNDLE_COMMAND" ] && BUNDLE_COMMAND="bundle"
|
|
|
|
if [[ -z "$BUNDLE_CONFIG" ]]; then
|
|
CONFIG_ARG=""
|
|
else
|
|
CONFIG_ARG="--config $BUNDLE_CONFIG"
|
|
fi
|
|
|
|
BUNDLE_FILE="$DEST/main.jsbundle"
|
|
|
|
"$NODE_BINARY" $NODE_ARGS "$CLI_PATH" $BUNDLE_COMMAND \
|
|
$CONFIG_ARG \
|
|
--entry-file "$ENTRY_FILE" \
|
|
--platform ios \
|
|
--dev $DEV \
|
|
--reset-cache \
|
|
--bundle-output "$BUNDLE_FILE" \
|
|
--assets-dest "$DEST" \
|
|
$EXTRA_PACKAGER_ARGS
|
|
|
|
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
|