Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Add support for .xcode.env file in init and doctor commands #1585

Merged
merged 1 commit into from
Apr 14, 2022

Conversation

cipolleschi
Copy link
Contributor

Summary:

This PR adds the support for .xcode.env file in the init and doctor commands.
This PR depends on this other one: facebook/react-native#33546

Test Plan:

This PR is quite similar to 1530. I would rely on the same tests.
If anyone has suggestions about how to test this, I will be more than happy to implement them.

@cipolleschi
Copy link
Contributor Author

The CI is failing on two tasks related to Android (they are related to gradlew). I don't think that my PR touched those files, though... and I can see that the master branch is failing as well.

description: 'File to customize Xcode environment',
getDiagnostics: async () => {
return {
needsToBeFixed: fs.existsSync('./ios/.xcode.env'),
Copy link
Contributor

@tido64 tido64 Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is making assumptions on where the iOS project lives. Should we use the config to figure out where the closest Podfile is? And what about macOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it using findProjectRoot. I'm not sure that findPodfilePath is the right approach, because for macOS project we have an ios folder and a macos folder, both of which have their own Podfile.

$ ls -all ios
total 48
drwxr-xr-x  10 cipolleschi  staff    320  6 Apr 17:00 .
drwxr-xr-x  24 cipolleschi  staff    768  6 Apr 17:03 ..
-rw-r--r--   1 cipolleschi  staff   1106  6 Apr 16:59 Podfile
// ... other files here ...

$ ls -all macos
total 56
drwxr-xr-x  10 cipolleschi  staff    320  6 Apr 17:06 .
drwxr-xr-x  24 cipolleschi  staff    768  6 Apr 17:03 ..
-rw-r--r--   1 cipolleschi  staff   1086  6 Apr 17:03 Podfile

@cipolleschi cipolleschi force-pushed the feat/support-xcode-env branch 4 times, most recently from c4cc9fa to 6da4683 Compare April 6, 2022 16:38
label: '.xcode.env',
description: 'File to customize Xcode environment',
getDiagnostics: async () => {
const projectRoot = findProjectRoot();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat unrelated (and definitely not to be fixed in this PR), I looked briefly at the options that are passed to all CLI commands and it looks like they include this information. However, it doesn't look like they are properly forwarded to the individual fixers. It's a bit silly that we have to duplicate the effort to find this info again. Do we have an issue tracking this? cc @mikehardy @thymikee

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we track this. Would make sense

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #1588

Comment on lines 49 to 47
const src =
projectRoot +
'/node_modules/react-native/template/ios/' +
templateFilePath;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is assuming the installation path of react-native. We should probably use require.resolve instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope I used it properly. Let me know if I have to update the call.

Comment on lines 55 to 61
applePlatformFolders.forEach(async (folder) => {
const destFolder = projectRoot + folder;
const destFilePath = destFolder + '/' + xcodeEnvFile;
if (fs.existsSync(destFolder) && !fs.existsSync(destFilePath)) {
await copyFileAsync(src, destFilePath);
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is assuming the location of the .xcworkspace. I've seen many differing setups including:

  • <project-root>/ios/MyApp.xcworkspace
  • <project-root>/MyApp.xcworkspace
  • <project-root>/example/ios/MyApp.xcworkspace
  • <project-root>/apps/ios/src/MyApp.xcworkspace

Can we refactor findPodfilePath to return all found Podfiles and add a .xcode.env next to them? I think that will be more accurate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or introduce a findAllPodfilePaths helper

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thank you all for the suggestions and @tido64 for sharing its experience.
I updated the PR with the findAllPodfilePaths function, as suggested by @thymikee and adding the file in all the returned paths.

import path from 'path';
import {promisify} from 'util';
import {findProjectRoot} from '@react-native-community/cli-tools';
import findAllPodfilePaths from '@react-native-community/cli-platform-ios/src/config/findAllPodfilePaths';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't import from src since we transform the code before publishing and put it into build directory; src is not there in published files. We either need to export findAllPodfilePaths from @react-native-community/cli-platform-ios – and add a dependency on it for cli-doctor and update "references" in its tsconfig.json – or move this helper to the cli-tools package (and add a dependency on glob). I'd go with the former for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI we have a yarn watch script that builds files on the go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @thymikee, thanks for the review.
I updated the PR with your suggestion. Let me know if it's ok!

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! One thing to address and we're good :)

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏼

@thymikee thymikee merged commit 99f953e into master Apr 14, 2022
@thymikee thymikee deleted the feat/support-xcode-env branch April 14, 2022 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants