Skip to content

Commit

Permalink
Re-apply: Consider relative to pwd installation root when looking for…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
danilobuerger authored and facebook-github-bot committed Mar 16, 2022
1 parent 10d2e4c commit 9e7d91f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,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
Expand Down Expand Up @@ -320,7 +321,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}"
Expand Down Expand Up @@ -510,6 +511,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.'
Expand All @@ -525,7 +527,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}",
Expand Down
4 changes: 2 additions & 2 deletions template/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9e7d91f

Please sign in to comment.