Skip to content

Set the LANG when invoking cocoapods#45710

Merged
dnfield merged 8 commits intoflutter:masterfrom
dnfield:cocoapods_lang
Dec 2, 2019
Merged

Set the LANG when invoking cocoapods#45710
dnfield merged 8 commits intoflutter:masterfrom
dnfield:cocoapods_lang

Conversation

@dnfield
Copy link
Contributor

@dnfield dnfield commented Nov 27, 2019

Description

When invoked from the command line, this is fine, but when invoked from an IDE the $LANG env var isn't set by the IDE. We could remove this is Coco

Related Issues

google/flutter-desktop-embedding#586
CocoaPods/CocoaPods#9347

Tests

I added the following tests:

Updated tests to expect this variable is set.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@dnfield dnfield requested review from DanTup and jmagman November 27, 2019 17:31
@fluttergithubbot fluttergithubbot added c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels. labels Nov 27, 2019
Copy link
Contributor

@DanTup DanTup left a comment

Choose a reason for hiding this comment

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

Thanks! 🙂

Added one question about a fallback (since I saw localeName return null in a Flutter app, but I don't know if it was specifically being in a Flutter app that was the reason).

<String>['install'],
workingDirectory: podfile.parent.path,
environment: <String, String>{
'LANG': '${Platform.localeName}.UTF8',
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a fallback if Platform.localeName is not set? I don't know if it'd happen for a CLI app, but when I was testing I noticed it wasn't set when I printed it inside a Flutter app, though it was set when running a CLI app (even when there was no LANG var set invoking the CLI app).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/dart-lang/sdk/blob/master/runtime/bin/platform_macos.cc#L190 Is the impl for macOS/iOS. https://github.com/dart-lang/sdk/blob/master/runtime/bin/platform_android.cc#L121 android.

These look like they shouldn't return null... In fact,the main wrapper for it throws an error if they do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/cc @zanderso who probably knows more about that

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 running on the iOS Simulator (iPhone), it gets null.

Screenshot 2019-11-27 at 6 07 14 pm

If it's only when running on-device, it might not matter (I can't imagine the flutter tool will be running pod on a device), but if there's another reason it's null (eg. that might occur for a real flutter_tool user on their host OS) we might need to guard against it (defaulting to en_US would presumably be fine).

Copy link
Member

Choose a reason for hiding this comment

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

Platform.localeName can give null if the embedder overrides _Platform._localeClosure with a function that returns null. See: https://github.com/dart-lang/sdk/blob/master/sdk/lib/io/platform_impl.dart#L48.

The command line Dart VM doesn't override it, so Platform.localeName won't give null.

The engine does override it here: https://github.com/flutter/engine/blob/32ca0cc7d347235d8ae1ed53e49c4f0de97bd03c/lib/ui/dart_runtime_hooks.cc#L143

With: https://github.com/flutter/engine/blob/32ca0cc7d347235d8ae1ed53e49c4f0de97bd03c/lib/ui/hooks.dart#L68

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it - sounds like it'll always be set in for contexts where this code runs then.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, there are test failures are because this is null somewhere that's being called while testing:

00:06 +58: test/general.shard/persistent_tool_state_test.dart: state can be set and persists                                                                                                           NoSuchMethodError: The method 'replaceAll' was called on null.
Receiver: null
Tried calling: replaceAll("-", "_")
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1      CocoaPods.cocoaPodsVersionText (package:flutter_tools/src/macos/cocoapods.dart:83:40)

@DanTup
Copy link
Contributor

DanTup commented Nov 27, 2019

Ok, so I tested this with:

cd examples/flutter_gallery
flutter clean
LANG= flutter run -d macos -v

But it didn't work... After some fiddling, I found that it has to be UTF-8 (note the dash) and that the first part needs to be en_GB and not en-GB (as given by Dart).

So this worked:

'${platform.localeName.replaceAll('-', '_')}.UTF-8'

I can't find any info on these formats (eg. why it needs to be an underscore there, yet Dart has a dash) 🤷‍♂️

@zanderso
Copy link
Member

On macOS, the command line VM doesn't use LANG to compute Platform.localeName. See: https://github.com/dart-lang/sdk/blob/master/runtime/bin/platform_macos.cc#L190

@dnfield
Copy link
Contributor Author

dnfield commented Nov 27, 2019

Is there any chance that we just want to always force this to en_US.UTF-8?

@DanTup
Copy link
Contributor

DanTup commented Nov 27, 2019

Is there any chance that we just want to always force this to en_US.UTF-8?

🤷🏼‍♂️

I'm not all that familiar with CocoaPods. I can't think of anything obvious it might do differently based on language, and if we used the existing env variable first and only set that if it wasn't already set, I think that limits the scope (and gives a way for people to force it back if required).

@jmagman
Copy link
Member

jmagman commented Nov 27, 2019

I'm not all that familiar with CocoaPods. I can't think of anything obvious it might do differently based on language, and if we used the existing env variable first and only set that if it wasn't already set, I think that limits the scope (and gives a way for people to force it back if required).

It's using https://docs.ruby-lang.org/en/2.1.0/Encoding.html to check for a Encoding::UTF_8 ("UTF-8") match.

@dnfield
Copy link
Contributor Author

dnfield commented Nov 27, 2019

I'll keep using the (massaged) platform encoding. I'm just thinking the Podfile is always going to be en_US encoded.

@DanTup
Copy link
Contributor

DanTup commented Nov 28, 2019

Tested with the update and it seems to work fine, so LGTM once the tests pass (which seems to be because of a null for localeName somewhere).

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

Is there any chance that we just want to always force this to en_US.UTF-8?

That would be my vote. Just hard-code it.

@dnfield
Copy link
Contributor Author

dnfield commented Dec 2, 2019

That will probably resolve my test issue as well. I'm going to do that for now. We can fix it later if we determine that you ever want a non en_US locale for pod.

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

LGTM

'FLUTTER_FRAMEWORK_DIR': 'engine/path',
'COCOAPODS_DISABLE_STATS': 'true',
'CP_REPOS_DIR': cocoapodsRepoDir,
'LANG': 'en_US.UTF8',
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to replace CP_REPOS_DIR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be back now.

@dnfield
Copy link
Contributor Author

dnfield commented Dec 2, 2019

As long as this passes CI, going to look to land on red since it seems like it should fix the redness.

@dnfield dnfield merged commit 088fa24 into flutter:master Dec 2, 2019
@dnfield dnfield deleted the cocoapods_lang branch December 2, 2019 21:26
@DanTup
Copy link
Contributor

DanTup commented Dec 3, 2019

@dnfield Thanks! Tested this on master and it now works both from CLI and VS Code 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants