Skip to content

Commit

Permalink
Reorganize codegen script for clarity
Browse files Browse the repository at this point in the history
Summary:
This changeset is limited to whitespace and reordering changes that have no effect on the output or execution of the script. The sole purpose of this changeset is to apply these trivial changes prior to making some larger adjustments to the script in a followup.

With these changes, the ordering of statements more closely matches the order they are executed in (e.g. prepare_command before the script_phase).

Changelog:
[Internal]

Reviewed By: RSNara

Differential Revision: D29527804

fbshipit-source-id: d161ed31321d68baf420457c7aa0aa23a6fc98d2
  • Loading branch information
hramos authored and kelset committed Aug 11, 2021
1 parent 041365e commit 1b7f95b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,19 @@ def use_react_native_codegen!(spec, options={})

# Library name (e.g. FBReactNativeSpec)
modules_library_name = spec.name

# Output dir, relative to podspec that invoked this method
modules_output_dir = "React/#{modules_library_name}/#{modules_library_name}"

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

# Run the codegen as part of the Xcode build pipeline.
env_vars = "SRCS_DIR='#{js_srcs}'"
env_vars += " MODULES_OUTPUT_DIR='#{prefix}/#{modules_output_dir}'"
env_vars += " MODULES_LIBRARY_NAME='#{modules_library_name}'"

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

if ENV['USE_FABRIC'] == '1'
# We use a different library name for components, as well as an additional set of files.
# Eventually, we want these to be part of the same library as #{modules_library_name} above.
Expand All @@ -190,13 +192,17 @@ def use_react_native_codegen!(spec, options={})
generated_files = generated_files.concat(components_generated_filenames.map { |filename| "#{components_output_dir}/#{filename}" })
end

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

spec.script_phase = {
:name => 'Generate Specs',
:input_files => [js_srcs],
:output_files => ["${DERIVED_FILE_DIR}/codegen-#{modules_library_name}.log"].concat(generated_files.map { |filename| "#{prefix}/#{filename}"} ),
:script => "set -o pipefail\n\nbash -l -c '#{env_vars} ${PODS_TARGET_SRCROOT}/../../scripts/generate-specs.sh' 2>&1 | tee \"${SCRIPT_OUTPUT_FILE_0}\"",
# The final generated files will be created when this script is invoked at Xcode build time.
:script => %{set -o pipefail
bash -l -c '#{env_vars} $\{PODS_TARGET_SRCROOT\}/../../scripts/generate-specs.sh' 2>&1 | tee "${SCRIPT_OUTPUT_FILE_0}"},
:execution_position => :before_compile,
:show_env_vars_in_log => true
}
spec.prepare_command = "mkdir -p #{generated_dirs.map {|dir| "'../../#{dir}'"}.join(" ")} && touch #{generated_files.map {|file| "'../../#{file}'"}.join(" ")}"
end

0 comments on commit 1b7f95b

Please sign in to comment.