Files
react-native/scripts/generate-specs.sh
T
empyrical f312e5ba84 Update iOS Fabric-related files to compile on OSS (#29810)
Summary:
Original PR contents:

This pull request updates the Podspecs and associated build scripts, and some source files so they build on OSS. RNTester now compiles with `fabric_enabled` again.

The following changes have been made:

 * Various spots that were pointing to the old `ReactCommon/fabric` location have now been updated to `ReactCommon/react/renderer`
 * Files that were attempting to use internal FB header `FBRCTFabricComponentsPlugins.h` were changed to use `RCTFabricComponentsPlugins.h`
 * `RCTFabricComponentsPlugins` in OSS was updated to include the `Image` fabric component (thanks tsapeta)
 * Replaced old `generate-rncore.sh` build script with new `generate-rncore.js` script which does not require `flow-node` and uses the `react-native-codegen` API directly, so there is no longer any need for an interim `schema-rncore.json` file.
 * Updated Yoga podspec which wasn't fully synced with changes from the main Yoga repo
 * Updated Fabric podspec with additional needed subspecs

Additions to PR by hramos:
* Replaced use of generate-rncore scripts with the original generate-native-modules-specs.sh script, which is now generate-specs.sh and supports both codegen for Native Modules and Components now (TurboModules/Fabric).
* Codegen now runs at build time as part of the Xcode build pipeline instead of as part of `pod install`. The build script is injected by the FBReactNativeSpec pod, as the pod is part of both Fabric and non-Fabric builds.

## Changelog

[General] [Fixed] - RNTester compiles with `fabric_enabled` again

Pull Request resolved: https://github.com/facebook/react-native/pull/29810

Test Plan:
RNTester now compiles and runs in the simulator again when `fabric_enabled` is set to `true`.

```
cd xplat/js/react-native-github/packages/rn-tester
USE_FABRIC=1 pod install
open RNTesterPods.xcworkspace
# Build and run
```

Reviewed By: fkgozali

Differential Revision: D24058507

Pulled By: hramos

fbshipit-source-id: 8b2ea3694e6cb9aa23f83f087e2995fd4320e2bb
2020-12-22 08:36:22 -08:00

75 lines
2.3 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.
# This script collects the JavaScript spec definitions for core
# native modules and components, then uses react-native-codegen
# to generate native code.
# The script will use the local react-native-codegen package by
# default. Optionally, set the CODEGEN_PATH to point to the
# desired codegen library (e.g. when using react-native-codegen
# from npm).
#
# Usage:
# ./scripts/generate-specs.sh
#
# Examples:
# CODEGEN_PATH=.. ./scripts/generate-specs.sh
# shellcheck disable=SC2038
set -e
THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
TEMP_DIR=$(mktemp -d /tmp/react-native-codegen-XXXXXXXX)
RN_DIR=$(cd "$THIS_DIR/.." && pwd)
CODEGEN_PATH="${CODEGEN_PATH:-$(cd "$RN_DIR/packages/react-native-codegen" && pwd)}"
YARN_BINARY="${YARN_BINARY:-$(command -v yarn)}"
USE_FABRIC="${USE_FABRIC:-0}"
cleanup () {
set +e
rm -rf "$TEMP_DIR"
set -e
}
describe () {
printf "\\n\\n>>>>> %s\\n\\n\\n" "$1"
}
main() {
SRCS_DIR=$(cd "$RN_DIR/Libraries" && pwd)
OUTPUT_DIR="$TEMP_DIR/out"
COMPONENTS_DIR="$RN_DIR/ReactCommon/react/renderer/components/rncore"
MODULES_DIR="$RN_DIR/Libraries/FBReactNativeSpec/FBReactNativeSpec"
SCHEMA_FILE="$TEMP_DIR/schema.json"
if [ ! -d "$CODEGEN_PATH/lib" ]; then
describe "Building react-native-codegen package"
pushd "$CODEGEN_PATH" >/dev/null || exit
"$YARN_BINARY"
"$YARN_BINARY" build
popd >/dev/null || exit
fi
describe "Generating schema from flow types"
"$YARN_BINARY" node "$CODEGEN_PATH/lib/cli/combine/combine-js-to-schema-cli.js" "$SCHEMA_FILE" "$SRCS_DIR"
describe "Generating native code from schema (iOS)"
pushd "$RN_DIR" >/dev/null || exit
USE_FABRIC="$USE_FABRIC" "$YARN_BINARY" --silent node scripts/generate-specs-cli.js ios "$SCHEMA_FILE" "$OUTPUT_DIR"
popd >/dev/null || exit
mkdir -p "$COMPONENTS_DIR" "$MODULES_DIR"
mv "$OUTPUT_DIR/FBReactNativeSpec.h" "$OUTPUT_DIR/FBReactNativeSpec-generated.mm" "$MODULES_DIR"
find "$OUTPUT_DIR" -type f | xargs sed -i '' 's/FBReactNativeSpec/rncore/g'
cp -R "$OUTPUT_DIR/." "$COMPONENTS_DIR"
}
trap cleanup EXIT
main "$@"