Skip to content

Commit

Permalink
Fix config file dir incorrectly set in the build time codegen. (#32946)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #32946

Changelog: [Internal]
This fixes a bug where config file dir was incorrectly and breaks the codegen which runs when building an app.

Reviewed By: dmitryrykun

Differential Revision: D33724558

fbshipit-source-id: 0c04c1d41f2fb9b958da64fa414746695cea60cb
  • Loading branch information
sota000 authored and facebook-github-bot committed Jan 24, 2022
1 parent e6a3410 commit c48e5ac
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
20 changes: 19 additions & 1 deletion scripts/react_native_pods_utils/__tests__/script_phases.snap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

def snap_get_script_phases_with_codegen_discovery()
def snap_get_script_phases_with_codegen_discovery_with_config_file_dir()
return <<~EOS
pushd "$PODS_ROOT/../" > /dev/null
RCT_SCRIPT_POD_INSTALLATION_ROOT=$(pwd)
Expand All @@ -21,6 +21,24 @@ def snap_get_script_phases_with_codegen_discovery()
EOS
end

def snap_get_script_phases_with_codegen_discovery_without_config_file_dir()
return <<~EOS
pushd "$PODS_ROOT/../" > /dev/null
RCT_SCRIPT_POD_INSTALLATION_ROOT=$(pwd)
popd >/dev/null
export RCT_SCRIPT_RN_DIR=$RCT_SCRIPT_POD_INSTALLATION_ROOT/../..
export RCT_SCRIPT_APP_PATH=$RCT_SCRIPT_POD_INSTALLATION_ROOT/
export RCT_SCRIPT_CONFIG_FILE_DIR=
export RCT_SCRIPT_OUTPUT_DIR=$RCT_SCRIPT_POD_INSTALLATION_ROOT
export RCT_SCRIPT_FABRIC_ENABLED=true
export RCT_SCRIPT_TYPE=withCodegenDiscovery
SCRIPT_PHASES_SCRIPT=\"$RCT_SCRIPT_RN_DIR/scripts/react_native_pods_utils/script_phases.sh\"
/bin/sh -c \"$SCRIPT_PHASES_SCRIPT\"
EOS
end

def snap_get_script_phases_no_codegen_discovery()
return <<~EOS
pushd "$PODS_ROOT/../" > /dev/null
Expand Down
13 changes: 11 additions & 2 deletions scripts/react_native_pods_utils/__tests__/script_phases.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@

class TestScriptPhases < Minitest::Test

def test_get_script_phases_with_codegen_discovery
def test_get_script_phases_with_codegen_discovery_with_config_file_dir
result = get_script_phases_with_codegen_discovery(
react_native_path: '../..',
relative_app_root: '',
relative_config_file_dir: 'node_modules',
fabric_enabled: true)
assert_equal snap_get_script_phases_with_codegen_discovery, result
assert_equal snap_get_script_phases_with_codegen_discovery_with_config_file_dir, result
end

def test_get_script_phases_with_codegen_discovery_without_config_file_dir
result = get_script_phases_with_codegen_discovery(
react_native_path: '../..',
relative_app_root: '',
relative_config_file_dir: '',
fabric_enabled: true)
assert_equal snap_get_script_phases_with_codegen_discovery_without_config_file_dir, result
end

def test_get_script_phases_no_codegen_discovery()
Expand Down
4 changes: 2 additions & 2 deletions scripts/react_native_pods_utils/script_phases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

# Run test manually by running `ruby react-native/scripts/react_native_pods_utils/__test__/script_phases.test.rb`
# Run test manually by running `ruby react-native/scripts/react_native_pods_utils/__tests__/script_phases.test.rb`

require "erb"

def get_script_phases_with_codegen_discovery(options)
export_vars = {
'RCT_SCRIPT_RN_DIR' => "$RCT_SCRIPT_POD_INSTALLATION_ROOT/#{options[:react_native_path]}",
'RCT_SCRIPT_APP_PATH' => "$RCT_SCRIPT_POD_INSTALLATION_ROOT/#{options[:relative_app_root]}",
'RCT_SCRIPT_CONFIG_FILE_DIR' => "#{options[:relative_config_file_dir] ? "$RCT_SCRIPT_POD_INSTALLATION_ROOT/#{options[:relative_config_file_dir]}" : ''}",
'RCT_SCRIPT_CONFIG_FILE_DIR' => "#{options[:relative_config_file_dir] != '' ? "$RCT_SCRIPT_POD_INSTALLATION_ROOT/#{options[:relative_config_file_dir]}" : ''}",
'RCT_SCRIPT_OUTPUT_DIR' => "$RCT_SCRIPT_POD_INSTALLATION_ROOT",
'RCT_SCRIPT_FABRIC_ENABLED' => "#{options[:fabric_enabled]}",
'RCT_SCRIPT_TYPE' => "withCodegenDiscovery",
Expand Down

0 comments on commit c48e5ac

Please sign in to comment.