-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Xcode backend refactor #23387
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
Xcode backend refactor #23387
Conversation
|
/cc @matthew-carroll - I don't know that the code will be of much interest, but the basic problems may exist on the Android side as well (inconsistency between |
|
This is a more comprehensive solution for what #23309 was trying to solve for (in part). |
| EchoError "ERROR: Flutter archive builds must be run in Release mode." | ||
| EchoError "" | ||
| EchoError "To correct, run:" | ||
| EchoError "To correct, ensure FLUTTER_BUILD_MODE to release or run:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"ensure"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh maybe you meant ensure .. is set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be ensure FLUTTER_BUILD_MODE is set to release... are you saying it should use a verb other than ensure?
| printError(' https://stackoverflow.com/questions/19842746/adding-a-build-configuration-in-xcode'); | ||
| printError(' If you have created a completely custom set of build configurations,'); | ||
| printError(' you can set the FLUTTER_BUILD_MODE=${buildInfo.modeName.toLowerCase()}'); | ||
| printError(' in the .xcconfig file for that configuration and run from Xcode.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indentation is a bit weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to avoid a wall of text in the warning - perhaps switching from hanging indent to regular indent would do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to add a couple extra new-lines and removed the extra indendtation.
| } | ||
|
|
||
| static String _baseConfigurationFor(BuildInfo buildInfo) => buildInfo.isDebug ? 'Debug' : 'Release'; | ||
| static String _baseConfigurationFor(BuildInfo buildInfo) => buildInfo.isDebug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extraneous space after =>
but also, generally we prefer to not line-break a => expression; this might be clearer as a block with if statements and returns.
|
tests? |
| # Use FLUTTER_BUILD_MODE if it's set, otherwise use the Xcode build configuration name | ||
| # This means that if someone wants to use an Xcode build config other than Debug/Profile/Release, | ||
| # they _must_ set FLUTTER_BUILD_MODE so we know what type of artifact to build. | ||
| local build_mode="$(echo "${FLUTTER_BUILD_MODE:-${CONFIGURATION}}" | tr "[:upper:]" "[:lower:]")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems really implicit and would cause issues with flavors https://medium.com/@salvatoregiordanoo/flavoring-flutter-392aaa875f36.
While you're here, I think it would be great if the flavors mechanism could be documented somewhere in https://flutter.io/docs/ if priorities could work. (So you can append to that doc the fact that you if create custom schemes / build configs, a $FLUTTER_BUILD_MODE variable needs to be defined or passed in)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flavors would already have issues with the current system, but they'd be hidden by the fact that you'd be left with whatever $FLUTTER_BUILD_MODE was set from the last time you ran from the command line. I agree this needs to be documented, but I'm not sure if we can really do much more to help flavors.
|
I've updated some existing tests to cover these scenarios. I was considering writing some tests that might exercise xcode_backend.sh with different environment variable configurations to ensure it would fail when it should. I started writing a shell script to do it but that felt messy and not well integrated with our testing framework. I guess I could write something that would shell out to it from Dart with various environment configurations, unless there's a better idea. |
|
Added some tests to test for early exits from the bash script. Add2App in general needs some integration tests. |
xster
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| EchoError "ERROR: Requested build with Flutter local engine at '${LOCAL_ENGINE}'" | ||
| EchoError "This engine is not compatible with FLUTTER_BUILD_MODE: '${build_mode}'." | ||
| EchoError "You can fix this by updating the LOCAL_ENGINE environment variable, or" | ||
| EchoError "by running flutter build ios --local-engine=..." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be more specific with the solution. e.g. you need to run --local-engine=ios_profile_unopt or some such if you use build_mode profile.
| printError(' you can set the FLUTTER_BUILD_MODE=${buildInfo.modeName.toLowerCase()}'); | ||
| printError(' in the .xcconfig file for that configuration and run from Xcode.'); | ||
| printError(''); | ||
| printError('4. Name the newly created configuration ${buildInfo.modeName}.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caveat that this step isn't necessary if you followed the 'If you have created a completely custom set of build configurations' part of the previous step.
* Use Xcode build configurations to drive Flutter build mode
This reverts commit def1d80.
Currently, the tooling and build system for Xcode set some variables to control the Flutter build mode (debug/profile/release) based on the command line options in a generated file (Generated.xcconfig).
This file should not be edited, but it can easily fall out of sync with Add2App scenarios (or if the user is just trying to build and run Runner.xcodeproj directly in Xcode). It can cause several problems (such as inconsistency between Xcode build configuration and Flutter build mode, which local engine is used, or which engine architecture is used). The engine architecture issue in particular (incorrect
$FLUTTER_FRAMEWORKS_DIRset from previous run that isn't updated by Xcode) will cause runtime errors that are confusing ("Engine could not start with configuration...").This patch does the following:
$FLUTTER_BUILD_MODEand$FLUTTER_FRAMEWORKS_DIRinGenerated.xcconfig.⌘I). (Fixes Build in profile mode when built by running Xcode's profiler #15249)$FLUTTER_BUILD_MODEfrom$CONFIGURATION, unless $FLUTTER_BUILD_MODE is explicitly set (for users with exotic/custom configurations).$LOCAL_ENGINEis set, it's compatible with the build mode (otherwise error out).flutter run --profile, which is not invoked in Add2App scenarios).