Skip to content

Commit d90fe67

Browse files
hramosfacebook-github-bot
authored andcommitted
Extend codegen script to take library name, output dir arguments
Summary: Extend the codegen script to allow arbitrary library name to be passed along as an argument, as well as the desired output directory for TurboModules and Fabric output. New arguments: - `:library_name` - `:modules_output_dir` - `:components_output_dir` These arguments remain optional, and in their absence, the codegen will generate output that should work for the FBReactNativeSpec core native modules use case. Internally, the script has been updated to use the correct path for the core modules use case as well as third party modules. Changelog: [Internal] - Extend the codegen script to take additional parameters Reviewed By: RSNara Differential Revision: D29243707 fbshipit-source-id: 1921bd3e5fd62d7cbf4c8b5089acfdd112f4b014
1 parent 3fefe04 commit d90fe67

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

scripts/react_native_pods.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,33 +152,33 @@ def react_native_post_install(installer)
152152
def use_react_native_codegen!(spec, options={})
153153
return if ENV['DISABLE_CODEGEN'] == '1'
154154

155-
# The path to react-native
156-
prefix = options[:path] ||= "${PODS_TARGET_SRCROOT}/../.."
155+
# The prefix to react-native
156+
prefix = options[:react_native_path] ||= "../.."
157157

158158
# The path to JavaScript files
159159
js_srcs = options[:js_srcs_dir] ||= "#{prefix}/Libraries"
160160

161161
# Library name (e.g. FBReactNativeSpec)
162-
modules_library_name = spec.name
162+
modules_library_name = options[:library_name] ||= spec.name
163163

164-
# Output dir, relative to podspec that invoked this method
165-
modules_output_dir = "React/#{modules_library_name}/#{modules_library_name}"
164+
# Output dir, relative to podspec that invoked this method
165+
modules_output_dir = options[:modules_output_dir] ||= "#{prefix}/React/#{modules_library_name}/#{modules_library_name}"
166166

167167
generated_dirs = [ modules_output_dir ]
168168
generated_filenames = [ "#{modules_library_name}.h", "#{modules_library_name}-generated.mm" ]
169169
generated_files = generated_filenames.map { |filename| "#{modules_output_dir}/#{filename}" }
170170

171171
# Run the codegen as part of the Xcode build pipeline.
172-
env_vars = "SRCS_DIR='#{js_srcs}'"
173-
env_vars += " MODULES_OUTPUT_DIR='#{prefix}/#{modules_output_dir}'"
172+
env_vars = "SRCS_DIR='${PODS_TARGET_SRCROOT}/#{js_srcs}'"
173+
env_vars += " MODULES_OUTPUT_DIR='${PODS_TARGET_SRCROOT}/#{modules_output_dir}'"
174174
env_vars += " MODULES_LIBRARY_NAME='#{modules_library_name}'"
175175

176176
if ENV['USE_FABRIC'] == '1'
177177
# We use a different library name for components, as well as an additional set of files.
178178
# Eventually, we want these to be part of the same library as #{modules_library_name} above.
179-
components_output_dir = "ReactCommon/react/renderer/components/rncore/"
179+
components_output_dir = options[:components_output_dir] ||= "#{prefix}/ReactCommon/react/renderer/components/rncore/"
180180
generated_dirs.push components_output_dir
181-
env_vars += " COMPONENTS_OUTPUT_DIR='#{prefix}/#{components_output_dir}'"
181+
env_vars += " COMPONENTS_OUTPUT_DIR='${PODS_TARGET_SRCROOT}/#{components_output_dir}'"
182182
components_generated_filenames = [
183183
"ComponentDescriptors.h",
184184
"EventEmitters.cpp",
@@ -193,15 +193,17 @@ def use_react_native_codegen!(spec, options={})
193193
end
194194

195195
# Prepare filesystem by creating empty files that will be picked up as references by CocoaPods.
196-
spec.prepare_command = "mkdir -p #{generated_dirs.map {|dir| "'../../#{dir}'"}.join(" ")} && touch #{generated_files.map {|file| "'../../#{file}'"}.join(" ")}"
196+
spec.prepare_command = "mkdir -p #{generated_dirs.join(" ")} && touch #{generated_files.join(" ")}"
197197

198198
spec.script_phase = {
199199
:name => 'Generate Specs',
200-
:input_files => [js_srcs],
201-
:output_files => ["${DERIVED_FILE_DIR}/codegen-#{modules_library_name}.log"].concat(generated_files.map { |filename| "#{prefix}/#{filename}"} ),
200+
:input_files => [ "${PODS_TARGET_SRCROOT}/#{js_srcs}" ], # This also needs to be relative to Xcode
201+
:output_files => ["${DERIVED_FILE_DIR}/codegen-#{modules_library_name}.log"].concat(generated_files.map { |filename| " ${PODS_TARGET_SRCROOT}/#{filename}"} ),
202202
# The final generated files will be created when this script is invoked at Xcode build time.
203203
:script => %{set -o pipefail
204-
bash -l -c '#{env_vars} $\{PODS_TARGET_SRCROOT\}/../../scripts/generate-specs.sh' 2>&1 | tee "${SCRIPT_OUTPUT_FILE_0}"},
204+
205+
bash -l -c '#{env_vars} $\{PODS_TARGET_SRCROOT\}/#{prefix}/scripts/generate-specs.sh' 2>&1 | tee "${SCRIPT_OUTPUT_FILE_0}"
206+
},
205207
:execution_position => :before_compile,
206208
:show_env_vars_in_log => true
207209
}

0 commit comments

Comments
 (0)