Skip to content

Commit ccd1708

Browse files
danilobuergerAndrei Shikov
authored and
Andrei Shikov
committedMar 16, 2022
Re-apply: Consider relative to pwd installation root when looking for files in rn module via cocoapods (#33427)
Summary: This re-applies Consider relative to pwd installation root when looking for files in rn module via cocoapods by danilobuerger 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 ```bash bundle exec pod install --project-directory=ios ``` ## Changelog [iOS] [Fixed] - Fix usage of cocoapods with --project-directory flag and new arch Pull Request resolved: #33427 Test Plan: 1) Enable the new arch 2) Execute from the projects root dir ```bash bundle exec pod install --project-directory=ios ``` 3) It will fail with ``` [!] Invalid `Podfile` file: [codegen] Couldn't not find react-native-codegen.. ``` 4) Apply the patch 5) Execute from the projects root dir ```bash bundle exec pod install --project-directory=ios ``` 6) It will succeed Reviewed By: cortinico Differential Revision: D34890926 Pulled By: dmitryrykun fbshipit-source-id: f7adc6196874822d5ff38f275414f529d385f2ea
1 parent 4e34e6c commit ccd1708

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed
 

‎scripts/react_native_pods.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,9 @@ def modify_flags_for_new_architecture(installer, cpp_flags)
271271
end
272272

273273
def build_codegen!(react_native_path)
274-
codegen_repo_path = "#{react_native_path}/packages/react-native-codegen";
275-
codegen_npm_path = "#{react_native_path}/../react-native-codegen";
274+
relative_installation_root = Pod::Config.instance.installation_root.relative_path_from(Pathname.pwd)
275+
codegen_repo_path = "#{relative_installation_root}/#{react_native_path}/packages/react-native-codegen";
276+
codegen_npm_path = "#{relative_installation_root}/#{react_native_path}/../react-native-codegen";
276277
codegen_cli_path = ""
277278
if Dir.exist?(codegen_repo_path)
278279
codegen_cli_path = codegen_repo_path
@@ -313,7 +314,7 @@ def checkAndGenerateEmptyThirdPartyProvider!(react_native_path)
313314
Pod::Executable.execute_command(
314315
'node',
315316
[
316-
"#{react_native_path}/scripts/generate-provider-cli.js",
317+
"#{relative_installation_root}/#{react_native_path}/scripts/generate-provider-cli.js",
317318
"--platform", 'ios',
318319
"--schemaListPath", temp_schema_list_path,
319320
"--outputDir", "#{output_dir}"
@@ -503,6 +504,7 @@ def use_react_native_codegen_discovery!(options={})
503504
app_path = options[:app_path]
504505
fabric_enabled = options[:fabric_enabled] ||= false
505506
config_file_dir = options[:config_file_dir] ||= ''
507+
relative_installation_root = Pod::Config.instance.installation_root.relative_path_from(Pathname.pwd)
506508

507509
if !app_path
508510
Pod::UI.warn '[Codegen] Error: app_path is required for use_react_native_codegen_discovery.'
@@ -518,7 +520,7 @@ def use_react_native_codegen_discovery!(options={})
518520
out = Pod::Executable.execute_command(
519521
'node',
520522
[
521-
"#{react_native_path}/scripts/generate-artifacts.js",
523+
"#{relative_installation_root}/#{react_native_path}/scripts/generate-artifacts.js",
522524
"-p", "#{app_path}",
523525
"-o", Pod::Config.instance.installation_root,
524526
"-e", "#{fabric_enabled}",

‎template/ios/Podfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ target 'HelloWorld' do
1515
# to enable hermes on iOS, change `false` to `true` and then install pods
1616
:hermes_enabled => flags[:hermes_enabled],
1717
:fabric_enabled => flags[:fabric_enabled],
18-
# An abosolute path to your application root.
19-
:app_path => "#{Dir.pwd}/.."
18+
# An absolute path to your application root.
19+
:app_path => "#{Pod::Config.instance.installation_root}/.."
2020
)
2121

2222
target 'HelloWorldTests' do

0 commit comments

Comments
 (0)
Please sign in to comment.