mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Mike Grabowski
parent
0636c458a6
commit
e5888de3b5
@@ -4,44 +4,19 @@
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
require "json"
|
||||
require_relative "../../scripts/react_native_pods.rb"
|
||||
|
||||
package = JSON.parse(File.read(File.join(__dir__, "..", "..", "package.json")))
|
||||
version = package['version']
|
||||
|
||||
source = { :git => 'https://github.com/facebook/react-native.git' }
|
||||
codegen_path_prefix = ".."
|
||||
if version == '1000.0.0'
|
||||
# This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in.
|
||||
source[:commit] = `git rev-parse HEAD`.strip
|
||||
codegen_path_prefix = "packages"
|
||||
else
|
||||
source[:tag] = "v#{version}"
|
||||
end
|
||||
|
||||
react_native_path = File.join(__dir__, "..", "..")
|
||||
srcs_dir = File.join(__dir__, "..")
|
||||
codegen_script_path = File.join(react_native_path, "scripts", "generate-specs.sh")
|
||||
codegen_path = File.join(react_native_path, codegen_path_prefix, "react-native-codegen")
|
||||
codegen_command = "CODEGEN_PATH=#{codegen_path} sh '#{codegen_script_path}' | tee \"${SCRIPT_OUTPUT_FILE_0}\""
|
||||
modules_output_dir = File.join(__dir__, "FBReactNativeSpec")
|
||||
components_output_dir = File.join(react_native_path, "ReactCommon", "react", "renderer", "components", "rncore")
|
||||
generated_filenames = [ "FBReactNativeSpec.h", "FBReactNativeSpec-generated.mm" ]
|
||||
generated_files = generated_filenames.map { |filename| File.join(modules_output_dir, filename) }
|
||||
|
||||
if ENV['USE_FABRIC'] == '1'
|
||||
components_generated_filenames = [
|
||||
"ComponentDescriptors.h",
|
||||
"EventEmitters.cpp",
|
||||
"EventEmitters.h",
|
||||
"Props.cpp",
|
||||
"Props.h",
|
||||
"RCTComponentViewHelpers.h",
|
||||
"ShadowNodes.cpp",
|
||||
"ShadowNodes.h"
|
||||
]
|
||||
generated_files = generated_files.concat(components_generated_filenames.map { |filename| File.join(components_output_dir, filename) })
|
||||
end
|
||||
|
||||
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
||||
folly_version = '2020.01.13.00'
|
||||
|
||||
@@ -72,12 +47,5 @@ Pod::Spec.new do |s|
|
||||
s.dependency "React-jsi", version
|
||||
s.dependency "ReactCommon/turbomodule/core", version
|
||||
|
||||
s.prepare_command = "mkdir -p #{modules_output_dir} #{components_output_dir} && touch #{generated_files.reduce() { |str, file| str + " " + file }}"
|
||||
s.script_phase = {
|
||||
:name => 'Generate Specs',
|
||||
:input_files => [srcs_dir],
|
||||
:output_files => ["$(DERIVED_FILE_DIR)/codegen.log"],
|
||||
:script => codegen_command,
|
||||
:execution_position => :before_compile
|
||||
}
|
||||
use_react_native_codegen! (s)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user