Skip to content

Commit

Permalink
Ensure codegen runs at Xcode buildtime
Browse files Browse the repository at this point in the history
Summary: Changelog:

Differential Revision: D25138896

fbshipit-source-id: 222353bd6ecb56928a2994baea2c393e6926283c
  • Loading branch information
hramos authored and facebook-github-bot committed Nov 21, 2020
1 parent c727b00 commit c766781
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Libraries/FBReactNativeSpec/FBReactNativeSpec.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ package = JSON.parse(File.read(File.join(__dir__, "..", "..", "package.json")))
version = package['version']

source = { :git => 'https://github.com/facebook/react-native.git' }
scripts_path = "../../node_modules/react-native/scripts"
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
scripts_path = "../../scripts"
else
source[:tag] = "v#{version}"
end
Expand Down Expand Up @@ -44,4 +46,6 @@ Pod::Spec.new do |s|
s.dependency "React-Core", version
s.dependency "React-jsi", version
s.dependency "ReactCommon/turbomodule/core", version

s.script_phase = { :name => 'Generate Native Modules Code', :output_files => ['FBReactNativeSpec/FBReactNativeSpec.h', 'FBReactNativeSpec/FBReactNativeSpec-generated.mm'], :script => 'ruby "$(scripts_path)/codegen-native-modules.rb"', :execution_position => :before_compile}
end
8 changes: 8 additions & 0 deletions scripts/codegen-native-modules.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 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.

require_relative 'react_native_pods'

codegen_core_modules()
26 changes: 18 additions & 8 deletions scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

require 'tmpdir'

def use_react_native! (options={})
# The prefix to the react-native
prefix = options[:path] ||= "../node_modules/react-native"
Expand Down Expand Up @@ -111,18 +113,26 @@ def flipper_post_install(installer)

# Pre Install processing for Native Modules
def codegen_pre_install(installer, options={})
# Path to React Native
prefix = options[:path] ||= "../node_modules/react-native"
codegen_core_modules(options)
end

# Handle Core Modules
def codegen_core_modules(options={})
prefix = options[:path] ||= "../../node_modules/react-native"
codegen_path = options[:codegen_path] ||= "#{prefix}/../react-native-codegen"
library_name = options[:library_name] ||= "FBReactNativeSpec"
output_dir = options[:output_dir] ||= "#{prefix}/Libraries/#{library_name}/#{library_name}"
srcs_dir = "#{prefix}/Libraries"

codegen(prefix, srcs_dir, library_name, output_dir, options)
end

# Path to react-native-codegen
def codegen(prefix, srcs_dir, library_name, output_dir, options)
codegen_path = options[:codegen_path] ||= "#{prefix}/../react-native-codegen"

# Handle Core Modules
Dir.mktmpdir do |dir|
native_module_spec_name = "FBReactNativeSpec"
schema_file = dir + "/schema-#{native_module_spec_name}.json"
srcs_dir = "#{prefix}/Libraries"
schema_file = dir + "/schema-#{library_name}.json"
schema_generated = system("node #{codegen_path}/lib/cli/combine/combine-js-to-schema-cli.js #{schema_file} #{srcs_dir}") or raise "Could not generate Native Module schema"
specs_generated = system("node #{prefix}/scripts/generate-native-modules-specs-cli.js ios #{schema_file} #{srcs_dir}/#{native_module_spec_name}/#{native_module_spec_name}") or raise "Could not generate code for #{native_module_spec_name}"
specs_generated = system("node #{prefix}/scripts/generate-native-modules-specs-cli.js ios #{schema_file} #{output_dir} #{library_name}") or raise "Could not generate code for #{library_name}"
end
end

0 comments on commit c766781

Please sign in to comment.