forked from react/react-native
-
Notifications
You must be signed in to change notification settings - Fork 2
Create scripts for building patched React Native #9
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| // @flow | ||
| const { | ||
| downloadHermesSourceTarball, | ||
| expandHermesSourceTarball, | ||
| } = require('../packages/react-native/scripts/hermes/hermes-utils'); | ||
| const { REPO_ROOT } = require('./consts'); | ||
| const fs = require('fs'); | ||
| const { rm } = require('fs/promises'); | ||
| const {cp, exec} = require('shelljs'); | ||
|
|
||
| /** | ||
| * This script is used as a part of Patching React Native. See: | ||
| * https://www.notion.so/wanderlog/Patching-React-Native-17b4797ed24d481eb2155c9daec1ba98?source=copy_link | ||
| * | ||
| * This section goes over how we created it: | ||
| * ["How did we figure out the steps for Create scripts for building patched React Native](https://www.notion.so/wanderlog/Patching-React-Native-17b4797ed24d481eb2155c9daec1ba98?source=copy_link#2aef9a6861f68016a0def8edec2d3d5a) | ||
| * | ||
| * This code is largely copied from other files per the comments below. | ||
| * | ||
| * If this script fails, we can debug it by running it with `CI=true` to see | ||
| * all the intermediate commands the Shell scripts run, since the scripts | ||
| * enable `set -x` when `CI` is set. | ||
| */ | ||
| async function buildPackage() { | ||
| const reactNativePackagePath = `${REPO_ROOT}/packages/react-native`; | ||
|
|
||
| // This part of the code downloads the Hermes source code and expands it. | ||
| // Start copied from scripts/release-testing/utils/testing-utils.js | ||
| const hermesCoreSourceFolder = `${reactNativePackagePath}/sdks/hermes`; | ||
|
|
||
| if (!fs.existsSync(hermesCoreSourceFolder)) { | ||
| console.info('The Hermes source folder is missing. Downloading...'); | ||
| downloadHermesSourceTarball(); | ||
| expandHermesSourceTarball(); | ||
| } | ||
|
|
||
| // need to move the scripts inside the local hermes cloned folder | ||
| // cp sdks/hermes-engine/utils/*.sh <your_hermes_checkout>/utils/. | ||
| cp( | ||
| `${reactNativePackagePath}/sdks/hermes-engine/hermes-engine.podspec`, | ||
| `${reactNativePackagePath}/sdks/hermes/hermes-engine.podspec`, | ||
| ); | ||
| cp( | ||
| `${reactNativePackagePath}/sdks/hermes-engine/hermes-utils.rb`, | ||
| `${reactNativePackagePath}/sdks/hermes/hermes-utils.rb`, | ||
| ); | ||
| cp( | ||
| `${reactNativePackagePath}/sdks/hermes-engine/utils/*.sh`, | ||
| `${reactNativePackagePath}/sdks/hermes/utils/.`, | ||
| ); | ||
| // End copied from scripts/release-testing/utils/testing-utils.js | ||
|
|
||
| // Builds the types_generated. We figured this out by asking: | ||
| // "What code in this project creates the types_generated directory?" | ||
| exec('yarn build-types', {cwd: REPO_ROOT}); | ||
|
|
||
| // Builds the FBReactNativeSpec. We figured this out by asking: | ||
| // "What code in this project creates the FBReactNativeSpec directory?" | ||
| exec('yarn install && yarn prepack', {cwd: reactNativePackagePath}); | ||
| // We don't need the README.md file | ||
| await rm(`${reactNativePackagePath}/README.md`); | ||
|
|
||
| // build-mac-framework.sh builds hermes and hermesc binaries for MacOS. | ||
| // I figured this out by: | ||
| // | ||
| // 1. Running the code in `buildAllArtifacts` below (uncomment the line) | ||
| // below | ||
| // 2. Running `find . -name hermes` and seeing that the file was in | ||
| // `./packages/react-native/sdks/hermes/build_macosx/bin/hermes` | ||
| // 3. Finding references to build_macosx and seeing it was likely created | ||
| // by the build_apple_framework function | ||
| // 4. Finding callers of the build_apple_framework function | ||
|
|
||
| // MAC_DEPLOYMENT_TARGET is used by get_mac_deployment_target in | ||
| // build-mac-framework.sh. The value to set is taken from | ||
| // publish-release.yml | ||
| process.env.MAC_DEPLOYMENT_TARGET = "10.15"; | ||
| exec( | ||
| 'bash ./utils/build-mac-framework.sh', | ||
| {cwd: `${reactNativePackagePath}/sdks/hermes`}, | ||
| ); | ||
|
|
||
| // Uncomment this to build all the artifacts for Hermes, including ones that we | ||
| // don't need. | ||
| // buildAllArtifacts(hermesCoreSourceFolder); | ||
|
|
||
| // We figured out the files to copy by running: | ||
| // `find . -name hermesc` and and `find . -name hermes | grep bin` | ||
| // | ||
| // We figured out the destination directory by looking at the the paths in | ||
| // the official React Native NPM package: https://www.npmjs.com/package/react-native/v/0.81.5?activeTab=code | ||
| const hermesDir = `${reactNativePackagePath}/sdks/hermes/build_macosx/bin`; | ||
| const hermescDir = `${reactNativePackagePath}/sdks/hermes/build_host_hermesc/bin`; | ||
| const destinationDir = `${reactNativePackagePath}/sdks/hermesc/osx-bin`; | ||
| console.info(`Copying files from ${hermesDir} to ${destinationDir}`); | ||
| console.info(`Copying files from ${hermescDir} to ${destinationDir}`); | ||
| await fs.promises.mkdir(destinationDir, { recursive: true }); | ||
| cp('-r', `${hermesDir}/*`, `${destinationDir}/`); | ||
| cp('-r', `${hermescDir}/*`, `${destinationDir}/`); | ||
| } | ||
|
|
||
| /** | ||
| * This function builds all the artifacts for Hermes, including ones that we | ||
| * don't need. We used it initially to figure out which subtasks built the hermes | ||
| * and hermesc binaries. | ||
| */ | ||
| // eslint-disable-next-line no-unused-vars | ||
| function buildAllArtifacts(hermesCoreSourceFolder) { | ||
| // These versions were copied from publish-release.yml | ||
| process.env.IOS_DEPLOYMENT_TARGET = '15.1'; | ||
| process.env.MAC_DEPLOYMENT_TARGET = '10.15'; | ||
| process.env.XROS_DEPLOYMENT_TARGET = '1.0'; | ||
|
|
||
| // Start copied from scripts/release-testing/utils/testing-utils.js | ||
| const jsiFolder = `${reactNativePackagePath}/ReactCommon/jsi`; | ||
|
|
||
| const buildTypeiOSArtifacts = 'Debug'; | ||
|
|
||
| // the android ones get set into /private/tmp/maven-local | ||
| const localMavenPath = '/private/tmp/maven-local'; | ||
|
|
||
| // Generate native files for iOS | ||
| generateiOSArtifacts( | ||
| jsiFolder, | ||
| hermesCoreSourceFolder, | ||
| buildTypeiOSArtifacts, | ||
| localMavenPath, | ||
| ); | ||
| // End copied from scripts/release-testing/utils/testing-utils.js | ||
| } | ||
|
|
||
| buildPackage(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| SAVED_ROOT_FILES_NAME="saved-root-files" | ||
|
|
||
| # Parse command line arguments | ||
| help_text_and_exit() { | ||
| cat <<END | ||
| Usage: bash move-react-native-package.sh [--reverse] [--help] | ||
| Example: | ||
| bash move-react-native-package.sh --reverse | ||
| bash move-react-native-package.sh --help | ||
|
|
||
| This script is used as a part of Patching React Native. See: | ||
| https://www.notion.so/wanderlog/Patching-React-Native-17b4797ed24d481eb2155c9daec1ba98?source=copy_link | ||
|
|
||
| We need to do this because the installed NPM package consists of files within | ||
| the /packages/react-native directory. Since we install from Github, we need to | ||
| create a tag with those files at the root. | ||
|
|
||
| This script moves the react-native package to the root directory and updates | ||
| the .gitignore. It saves the moved files in a directory called | ||
| $SAVED_ROOT_FILES_NAME. | ||
|
|
||
| If --reverse is passed, all operations are reversed. | ||
|
|
||
| END | ||
| exit 1 | ||
| } | ||
|
|
||
| while [ $# -gt 0 ]; do | ||
| case $1 in | ||
| --reverse) REVERSE=true; shift 1;; | ||
| --help) help_text_and_exit; | ||
| esac | ||
| done | ||
|
|
||
| echo "Starting react-native package move script..." | ||
|
|
||
|
|
||
| # Get the repository root directory | ||
| # We want this directory to be correct even if the script has been moved by | ||
| # itself. | ||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| PARENT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" | ||
| PARENT_BASENAME=$(basename "$PARENT_DIR") | ||
|
|
||
| if [ "$PARENT_BASENAME" = "$SAVED_ROOT_FILES_NAME" ]; then | ||
| REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" | ||
| else | ||
| REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" | ||
| fi | ||
| cd "$REPO_ROOT" | ||
|
|
||
| SAVED_ROOT_FILES_PATH="$REPO_ROOT/$SAVED_ROOT_FILES_NAME" | ||
|
|
||
| # Forward moves | ||
| if [ "$REVERSE" != true ]; then | ||
| # Check if we've already moved the package | ||
| if [ -d "$SAVED_ROOT_FILES_PATH" ]; then | ||
| echo "Error: $SAVED_ROOT_FILES_NAME directory already exists. Nothing to do." | ||
| exit 1 | ||
| fi | ||
|
|
||
| mkdir -p "$SAVED_ROOT_FILES_PATH/packages" | ||
|
|
||
| echo "Saving existing .gitignore to saved-root-files/.gitignore" | ||
| cp -f "$REPO_ROOT/.gitignore" "$SAVED_ROOT_FILES_PATH/.gitignore" | ||
|
|
||
| echo "Updating .gitignore to add, modify, and delete lines" | ||
| # On macOS, sed -i requires an extension argument (use empty string for in-place) | ||
| # Remove /packages/react-native from paths | ||
| sed -i '' 's|/packages/react-native/|/|g' "$REPO_ROOT/.gitignore" | ||
|
|
||
| # Remove any lines that remove things we want to keep | ||
| # We determined these by doing these steps, and then repeating them until we | ||
| # didn't miss any files: | ||
| # | ||
| # 1. Doing `yarn add react-native@^0.81.5` | ||
| # 2. Listing the files by doing `find node_modules/react-native > originalFiles.txt` | ||
| # 3. Installing our fork of react-native | ||
| # 4. Running the same command to list the files again | ||
| # 5. Diffing the two files to see what was missed | ||
| sed -E -i '' '/^\/?vendor/d' "$REPO_ROOT/.gitignore" | ||
| sed -E -i '' '/^\/?sdks\/hermesc/d' "$REPO_ROOT/.gitignore" | ||
| sed -i '' '/types_generated/d' "$REPO_ROOT/.gitignore" | ||
| sed -i '' '/FBReactNativeSpec/d' "$REPO_ROOT/.gitignore" | ||
| echo "/saved-root-files/" >> "$REPO_ROOT/.gitignore" | ||
|
|
||
| echo "Moving all files to $SAVED_ROOT_FILES_PATH" | ||
| for item in "$REPO_ROOT"/*; do | ||
| item_name=$(basename "$item") | ||
| # Skip the directory itself | ||
| if [ "$item_name" != "$SAVED_ROOT_FILES_NAME" ]; then | ||
| echo "- Moving $item_name to $SAVED_ROOT_FILES_PATH" | ||
| mv -f "$item" "$SAVED_ROOT_FILES_PATH/" | ||
| fi | ||
| done | ||
|
|
||
| echo "Moving /packages/react-native contents to root..." | ||
|
|
||
| mv -f "$SAVED_ROOT_FILES_PATH/packages/react-native"/* "$REPO_ROOT/" | ||
|
|
||
| echo "Script completed successfully" | ||
|
|
||
| # Reverse moves | ||
| else | ||
| echo "Reversing operations: moving files from $SAVED_ROOT_FILES_NAME back to root..." | ||
|
|
||
| if [ ! -d "$SAVED_ROOT_FILES_PATH" ]; then | ||
| echo "Error: $SAVED_ROOT_FILES_NAME directory not found. Nothing to reverse." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Moving react-native package contents to within saved-root-files/packages" # Ensure the directory exists | ||
| mkdir -p "$SAVED_ROOT_FILES_PATH/packages/react-native" | ||
|
|
||
| for item in "$REPO_ROOT"/*; do | ||
| item_name=$(basename "$item") | ||
| if [ "$item_name" != "$SAVED_ROOT_FILES_NAME" ]; then | ||
| echo "- Moving $item_name back to packages/react-native" | ||
| mv -f "$item" "$SAVED_ROOT_FILES_NAME/packages/react-native/" | ||
| fi | ||
| done | ||
|
|
||
| echo "Moving .gitignore back to root" | ||
| mv -f "$SAVED_ROOT_FILES_PATH/.gitignore" "$REPO_ROOT/.gitignore" | ||
|
|
||
| echo "Moving all files back to root" | ||
| mv -f "$SAVED_ROOT_FILES_PATH"/* "$REPO_ROOT/" | ||
|
|
||
| echo "Deleting $SAVED_ROOT_FILES_NAME" | ||
| rm -rf "$SAVED_ROOT_FILES_PATH" | ||
|
|
||
| echo "Reverse operation completed successfully" | ||
| exit 0 | ||
| fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.