From dc959c92719085c18a4c3aee2bbc4b03ef7e05ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Mon, 30 Jan 2023 04:03:31 -0800 Subject: [PATCH] Update `react-native-xcode.sh` to use `PROJECT_DIR` from Xcode (#35970) Summary: In a mono-repo the `react-native` package could be hoisted compared to the app directory, in which case it's not a good strategy for the `react-native-xcode.sh` script to guess the app project root relative to the location of itself. Instead I suggest to relying on a build setting provided by Xcode to derive the default app path. I could have use the `SRCROOT` instead. According to https://stackoverflow.com/questions/36323031/what-the-different-between-srcroot-and-project-dir this is equivalent and also a bit less ambiguous as I see it. I.e. I would expect most Xcode projects to be located in the `ios` directory of the app. As a workaround, before this merge, users can add the following to their "Bundle React Native code and images" build phase or `ios/.xcode.env` file: ```shell export PROJECT_ROOT="$PROJECT_DIR/.." ``` This build phase can also be used for users wanting to revert this default behaviour once merged. ## Changelog [iOS] [Changed] - Changed default `PROJECT_ROOT` (used in when bundling for iOS) to rely on the `PROJECT_DIR` build setting. Pull Request resolved: https://github.com/facebook/react-native/pull/35970 Test Plan: I've updated this locally and verified this does indeed pick up the correct app path - even in a mono-repo. To verify this: - Instantiate the template with this patch applied. - Update the "Run scheme"'s "Build Configuration" to "Release". - Build the app without errors. Reviewed By: cortinico Differential Revision: D42842636 Pulled By: cipolleschi fbshipit-source-id: 040c31ac59a8abec5f5b38f795c8e74649420bac --- scripts/react-native-xcode.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/react-native-xcode.sh b/scripts/react-native-xcode.sh index 30a5ac2227a..54a4eb9de34 100755 --- a/scripts/react-native-xcode.sh +++ b/scripts/react-native-xcode.sh @@ -58,9 +58,8 @@ 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/../.."} +# Most projects have their project root, one level up from their Xcode project dir (the "ios" directory) +PROJECT_ROOT=${PROJECT_ROOT:-"$PROJECT_DIR/.."} cd "$PROJECT_ROOT" || exit