Set the LANG when invoking cocoapods#45710
Conversation
DanTup
left a comment
There was a problem hiding this comment.
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).
dev/bots/test.dart
Outdated
| <String>['install'], | ||
| workingDirectory: podfile.parent.path, | ||
| environment: <String, String>{ | ||
| 'LANG': '${Platform.localeName}.UTF8', |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
/cc @zanderso who probably knows more about that
There was a problem hiding this comment.
This is running on the iOS Simulator (iPhone), it gets null.
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).
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Got it - sounds like it'll always be set in for contexts where this code runs then.
There was a problem hiding this comment.
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)
|
Ok, so I tested this with: But it didn't work... After some fiddling, I found that it has to be 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) 🤷♂️ |
|
On macOS, the command line VM doesn't use LANG to compute |
|
Is there any chance that we just want to always force this to |
🤷🏼♂️ 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 |
|
I'll keep using the (massaged) platform encoding. I'm just thinking the Podfile is always going to be en_US encoded. |
|
Tested with the update and it seems to work fine, so LGTM once the tests pass (which seems to be because of a |
jmagman
left a comment
There was a problem hiding this comment.
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.
|
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. |
d097625 to
7b90866
Compare
| 'FLUTTER_FRAMEWORK_DIR': 'engine/path', | ||
| 'COCOAPODS_DISABLE_STATS': 'true', | ||
| 'CP_REPOS_DIR': cocoapodsRepoDir, | ||
| 'LANG': 'en_US.UTF8', |
There was a problem hiding this comment.
Did you mean to replace CP_REPOS_DIR?
There was a problem hiding this comment.
It should be back now.
|
As long as this passes CI, going to look to land on red since it seems like it should fix the redness. |
|
@dnfield Thanks! Tested this on master and it now works both from CLI and VS Code 👍 |

Description
When invoked from the command line, this is fine, but when invoked from an IDE the
$LANGenv var isn't set by the IDE. We could remove this is CocoRelated 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.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?