From 139bbd376fdabc174d20dab3a2986fd28ac486d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20B=C3=BCrger?= Date: Wed, 9 Mar 2022 09:06:43 +0100 Subject: [PATCH] Consider relative to pwd installation root when looking for files in rn module via cocoapods The :reactNativePath provided by use_native_modules! is the rn module path relative to the installation root (usually ./ios). However, when executing cocoapods from a dir thats not the installation root, packages that use the relative :reactNativePath variable in their path must also consider the relative to pwd installation root. This fixes usage of cocoapods with the --project-directory flag like bundle exec pod install --project-directory=ios --- scripts/react_native_pods.rb | 10 ++++++---- template/ios/Podfile | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index a5abb36fd76d..7507a7206e43 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -277,8 +277,9 @@ def modify_flags_for_new_architecture(installer, cpp_flags) end def build_codegen!(react_native_path) - codegen_repo_path = "#{react_native_path}/packages/react-native-codegen"; - codegen_npm_path = "#{react_native_path}/../react-native-codegen"; + relative_installation_root = Pod::Config.instance.installation_root.relative_path_from(Pathname.pwd) + codegen_repo_path = "#{relative_installation_root}/#{react_native_path}/packages/react-native-codegen"; + codegen_npm_path = "#{relative_installation_root}/#{react_native_path}/../react-native-codegen"; codegen_cli_path = "" if Dir.exist?(codegen_repo_path) codegen_cli_path = codegen_repo_path @@ -319,7 +320,7 @@ def checkAndGenerateEmptyThirdPartyProvider!(react_native_path) Pod::Executable.execute_command( 'node', [ - "#{react_native_path}/scripts/generate-provider-cli.js", + "#{relative_installation_root}/#{react_native_path}/scripts/generate-provider-cli.js", "--platform", 'ios', "--schemaListPath", temp_schema_list_path, "--outputDir", "#{output_dir}" @@ -509,6 +510,7 @@ def use_react_native_codegen_discovery!(options={}) app_path = options[:app_path] fabric_enabled = options[:fabric_enabled] ||= false config_file_dir = options[:config_file_dir] ||= '' + relative_installation_root = Pod::Config.instance.installation_root.relative_path_from(Pathname.pwd) if !app_path Pod::UI.warn '[Codegen] Error: app_path is required for use_react_native_codegen_discovery.' @@ -524,7 +526,7 @@ def use_react_native_codegen_discovery!(options={}) out = Pod::Executable.execute_command( 'node', [ - "#{react_native_path}/scripts/generate-artifacts.js", + "#{relative_installation_root}/#{react_native_path}/scripts/generate-artifacts.js", "-p", "#{app_path}", "-o", Pod::Config.instance.installation_root, "-e", "#{fabric_enabled}", diff --git a/template/ios/Podfile b/template/ios/Podfile index 54920362cc31..01506faf7913 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -15,8 +15,8 @@ target 'HelloWorld' do # to enable hermes on iOS, change `false` to `true` and then install pods :hermes_enabled => flags[:hermes_enabled], :fabric_enabled => flags[:fabric_enabled], - # An abosolute path to your application root. - :app_path => "#{Dir.pwd}/.." + # An absolute path to your application root. + :app_path => "#{Pod::Config.instance.installation_root}/.." ) target 'HelloWorldTests' do