Граф коммитов

5 Коммитов

Автор SHA1 Сообщение Дата
Ivan Moskalev 07e4953514 Invoke `node` directly in generate-specs.sh (#30781)
Summary:
Currently, Codegen bash wrapper (`generate-specs.sh`) for Xcode invokes JS-based Codegen tooling via `yarn --silent node <...>`. This breaks both:

- when Yarn is not installed (if NPM is used), for obvious reasons
- when Yarn v2 ("Berry") is active

This PR changes the way `generate-specs.sh` locates `node` executable to the following algorithm:

- use the path provided in the `NODE_BINARY` env var
- if `NODE_BINARY` env var is not defined, find `node` with `command -v node`

## Changelog

[iOS] [Fixed] - Fix Codegen silently failing when Yarn is not installed, or when Yarn v2 is active.

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

Test Plan:
### Case 1 (no Yarn installed)

1. Ensure `yarn` is not present in PATH
2. Run Xcode build
3. Check that Codegen artifacts are produced

### Case 2 (Yarn v2 is used)

1. Ensure `yarn` is running in the v2 ("Berry") mode
2. Run Xcode build
3. Check that Codegen artifacts are produced

Reviewed By: fkgozali

Differential Revision: D26187081

Pulled By: hramos

fbshipit-source-id: 77d3089f523b8c976d8223b77ff9553cb6cf68a5
2021-02-02 15:10:48 -08:00
Janic Duplessis 12fccdeea3 Make codegen more reliable on iOS (#30792)
Summary:
This addesses a few issues I noticed while migrating my app to the new build-time codegen on iOS.

1. I noticed random failures because of codegen on iOS. This is mostly due to the fact the codegen output files are not specified in the xcode script. The only reason it works relatively fine currently is because the codegen output is inside the input files directory. This has the side effect of causing files to be regenerated every build, then causes all core modules to be recompiled which adds up a significant amount of time to rebuilds. To fix this I added the generated files to the script phase output and moved the FBReactNativeSpec dir outside of the codegen source (Libraries). I moved it to the React directory as this seemed to make sense and is where a lot of iOS files are as well as the core modules. Note this might require internal changes. This removes the circular dependency between our build phase input and output so consecutive builds can be cached properly.

2. Add `set -o pipefail` to the xcode script, this helped propagate errors properly to xcode because of the `| tee` pipe so it fails at the script phase and not later with a header not found error. Also add `2>&1` to pipe stderr to stdout so errors are also captured in the log file.

3. Add the `-l` flag to the bash invocation to help finding the yarn binary. With my setup yarn is added to the system PATH in my user .profile. Adding this file will cause bash to source the user environment which xcode scripts does not by default. I think this will help with most setups.

4. If yarn is not found the `command -v yarn` would make the script exit without any output because of the -e flag. I made a change to ignore the return code and check later if YARN_BINARY is set and have an explicit error message if not.

## Changelog

[iOS] [Fixed] - Make codegen more reliable on iOS

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

Test Plan:
Tested various project states to make sure the build always succeeds in RN tester:

- Simulate fresh clone, remove all ignored files, install pods, build
- Build, delete FBReactNativeSpec generated files, build again
- Build, build again, make sure FBReactNativeSpec is cached and not rebuilt
- Make the script fail and check that xcode shows the script error logs properly

![image](https://user-images.githubusercontent.com/2677334/105891571-c8badd00-5fde-11eb-839c-259d8e448523.png)

Note: Did not test fabric

Reviewed By: fkgozali

Differential Revision: D26104213

Pulled By: hramos

fbshipit-source-id: e18d9a0b9ada7c0c2e608d29ffe88087f04605b4
2021-02-01 14:39:25 -08:00
Héctor Ramos 7a9e4ba4e9 Optionally override codegen script defaults via envvars
Summary:
The codegen helper script, `generate-specs.sh`, is being used to generate code for the FBReactNativeSpec and React-Fabric/rncore pods. The script now supports overriding several defaults by setting the following environment variables:

- SRCS_DIR: Path to JavaScript sources, defaults to $RN_DIR/Libraries/
- LIBRARY_NAME: Defaults to FBReactNativeSpec
- MODULES_OUTPUT_DIR: Defaults to Libraries/$LIBRARY_NAME/$LIBRARY_NAME
- COMPONENTS_LIBRARY_NAME: Defaults to rncore
- COMPONENTS_OUTPUT_DIR: Defaults to ReactCommon/react/renderer/components/$COMPONENTS_LIBRARY_NAME

The CocoaPods codegen integration has been updated to take advantage of these.

**Example CocoaPods usage:**

```
# packages/rn-tester/NativeModuleExample/RNTesterSpecs.podspec
Pod::Spec.new do |s|
  s.name = "RNTesterSpec"
  # ...
  use_react_native_codegen!(s, { :srcs_dir => __dir__, :modules_output_dir => __dir__ })
end
```

Changelog:
[Internal]

Reviewed By: fkgozali

Differential Revision: D25738466

fbshipit-source-id: c68f5a3cd0996283a7af287e992e2f973024f44c
2021-01-04 13:34:16 -08:00
Héctor Ramos 811ccec74e Add use_react_native_codegen!
Summary:
Consolidate CocoaPods codegen scripts under a single `use_react_native_codegen!` method in `react_native_pods.rb`.

This is the first step towards making the codegen scripts library-agnostic. There are still a handful of hardcoded assumptions in place (e.g. the output directory structure, the use of a separate directory for components), but with some work one would be able to add codegen support to arbitrary CocoaPods podspecs.

The codegen script no longer takes a CODEGEN_PATH argument, and will instead attempt to use the local react-native-codegen package if available, and fallback to using the node_modules/react-native-codegen package if not.

## Usage

The `use_react_native_codegen!` method has two arguments:

- `spec`, a pod [Specification](https://www.rubydoc.info/github/CocoaPods/Core/Pod/Specification) object.
- `options`, an optional object. Supported keys:
  - `:srcs_dir`, the path to your JavaScript sources. Your native module or component specs should be located somewhere in this directory.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D25728053

fbshipit-source-id: feec587b656d5b220598ce6196ea6bb34a9580a9
2020-12-29 16:10:34 -08:00
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