1# Copyright (c) Meta Platforms, Inc. and affiliates. 2# 3# This source code is licensed under the MIT license found in the 4# LICENSE file in the root directory of this source tree. 5 6# Run test manually by running `ruby react-native/scripts/react_native_pods_utils/__tests__/script_phases.test.rb` 7 8require "erb" 9 10def get_script_phases_with_codegen_discovery_ABI47_0_0(options) 11 export_vars = { 12 'RCT_SCRIPT_RN_DIR' => "$RCT_SCRIPT_POD_INSTALLATION_ROOT/#{options[:react_native_path]}", 13 'RCT_SCRIPT_APP_PATH' => "$RCT_SCRIPT_POD_INSTALLATION_ROOT/#{options[:relative_app_root]}", 14 'RCT_SCRIPT_CONFIG_FILE_DIR' => "#{options[:relative_config_file_dir] != '' ? "$RCT_SCRIPT_POD_INSTALLATION_ROOT/#{options[:relative_config_file_dir]}" : ''}", 15 'RCT_SCRIPT_OUTPUT_DIR' => "$RCT_SCRIPT_POD_INSTALLATION_ROOT", 16 'RCT_SCRIPT_FABRIC_ENABLED' => "#{options[:fabric_enabled]}", 17 'RCT_SCRIPT_TYPE' => "withCodegenDiscovery", 18 } 19 return get_script_template_ABI47_0_0(options[:react_native_path], export_vars) 20end 21 22def get_script_phases_no_codegen_discovery_ABI47_0_0(options) 23 export_vars = { 24 'RCT_SCRIPT_RN_DIR' => "${PODS_TARGET_SRCROOT}/#{options[:react_native_path]}", 25 'RCT_SCRIPT_LIBRARY_NAME' => "#{options[:library_name]}", 26 'RCT_SCRIPT_OUTPUT_DIR' => "$RCT_SCRIPT_POD_INSTALLATION_ROOT/#{options[:codegen_output_dir]}", 27 'RCT_SCRIPT_LIBRARY_TYPE' => "#{options[:library_type] ? options[:library_type] : 'all'}", 28 'RCT_SCRIPT_JS_SRCS_PATTERN' => "#{options[:js_srcs_pattern]}", 29 'RCT_SCRIPT_JS_SRCS_DIR' => "#{options[:js_srcs_dir]}", 30 'RCT_SCRIPT_CODEGEN_MODULE_DIR' => "#{options[:codegen_module_dir]}", 31 'RCT_SCRIPT_CODEGEN_COMPONENT_DIR' => "#{options[:codegen_component_dir]}", 32 'RCT_SCRIPT_FILE_LIST' => ("#{options[:file_list]}").dump, 33 } 34 return get_script_template_ABI47_0_0(options[:react_native_path], export_vars) 35end 36 37 38def get_script_template_ABI47_0_0(react_native_path, export_vars={}) 39 template =<<~EOS 40 pushd "$PODS_ROOT/../" > /dev/null 41 RCT_SCRIPT_POD_INSTALLATION_ROOT=$(pwd) 42 popd >/dev/null 43 <% export_vars.each do |(varname, value)| %> 44 export <%= varname -%>=<%= value -%> 45 <% end %> 46 47 SCRIPT_PHASES_SCRIPT="$RCT_SCRIPT_RN_DIR/scripts/react_native_pods_utils/script_phases.sh" 48 WITH_ENVIRONMENT="$RCT_SCRIPT_RN_DIR/scripts/xcode/with-environment.sh" 49 /bin/sh -c "$WITH_ENVIRONMENT $SCRIPT_PHASES_SCRIPT" 50 EOS 51 result = ERB.new(template, 0, '->').result(binding) 52 return result 53end 54