Skip to content

Conversation

@vashworth
Copy link
Contributor

@vashworth vashworth commented Feb 7, 2025

This moves the logic for FLUTTER_APP_FLAVOR into flutter assemble, so that it also works when ran through Xcode and not just through the Flutter CLI.

However, there's no definitive way to get the the flavor/scheme in flutter assemble, so this makes a best effort to get it by parsing it out of the CONFIGURATION. CONFIGURATION should have the name of the scheme in it, although, this is only semi-enforced, so may not always work. If it's unable to get the scheme name from the CONFIGURATION, it falls back to using the FLAVOR environment variable, which is set by the Flutter CLI and used currently.

Verified Mac_ios flavors_test_ios passes: https://ci.chromium.org/ui/p/flutter/builders/prod.shadow/Mac_ios%20flavors_test_ios/7/overview

Verified Mac flavors_test_macos passes: https://ci.chromium.org/ui/p/flutter/builders/try.shadow/Mac%20flavors_test_macos/2/overview

Fixes #155951.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Feb 7, 2025
@github-actions github-actions bot added the team-ios Owned by iOS platform team label Feb 10, 2025
@vashworth vashworth marked this pull request as ready for review February 11, 2025 21:37
@vashworth vashworth requested review from bkonyi and jmagman February 11, 2025 21:37
Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

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

A few comments/questions. In general LGTM.

Future<TaskResult> _testFlavorWhenBuiltFromXcode(String projectDir) async {
final Device device = await devices.workingDevice;
await inDirectory(projectDir, () async {
await flutter('clean');
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, why was this needed?

If you know, please add a comment.

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 was to ensure the app bundle was left over from the previous parts of the test. I changed it to just delete the app bundle since that's faster the flutter clean

'-dTargetFile=$targetPath',
'-dBuildMode=$buildMode',
if (environment['FLAVOR'] != null) '-dFlavor=${environment['FLAVOR']}',
'-dConfiguration=${environment['CONFIGURATION']}',
Copy link
Contributor

Choose a reason for hiding this comment

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

Is threre a reason this isn't similar to line 442; that is, if this is null, we would print=null, which I'm not sure is intended (if it is, probably deserves a comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, so FLAVOR is set by the Flutter CLI in Flutter/Generated.xcconfig when the --flavor is used, so may not always be present. CONFIGURATION is provided by Xcode/xcodebuild and should always be present. I'll add a comment explaining why FLAVOR may be null

Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

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

LGTM, but I'll defer final approval to Jenn and Ben.

@vashworth vashworth removed the request for review from jmagman February 12, 2025 22:52

// Delete app bundle before build to ensure checks below do not use previously
// built bundle.
final String appPath = '$projectDir/$buildDir/$configuration-iphoneos/$productName.app';
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: should we consider using path.join(...) here instead of building the path manually?

@vashworth vashworth added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 19, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 21, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 21, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 21, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 21, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 21, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 22, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 22, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 22, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 22, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 23, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 23, 2025
github-merge-queue bot pushed a commit that referenced this pull request Feb 24, 2025
…#163737)

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

This request is a subset of #157871 and follows up #162907.

#162907 actually fixed behaviour of building with native tooling not
only for iOS/macOS, but also for Android builds too: now on master, if
you start build with `gradle` instead of `flutter build ...` – you also
get the correct behaviour and `appFlavor` won't be null in runtime.
Tests in this PR will check exactly this behavior.

Another diff is the change in the method of obtaining flavor at runtime
inside test project. Before this change, method channels were used for
this, after – `appFlavor` constant. Both methods do more or less the
same thing right now, but they may diverge in future, so I guess this is
the right way to check correctness here. Also, this change was requested
and approved by Andrew in
#157871 (comment)

issue for checklist: #155951 

New test was tested here:
https://ci.chromium.org/ui/p/flutter/builders/try/Linux_pixel_7pro%20flavors_test/63/overview


## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 21, 2025
@Gustl22
Copy link
Contributor

Gustl22 commented Jul 15, 2025

I know there don't exist flavors on web, but some use the FLUTTER_APP_FLAVOR to set the flavor.dart::appFlavor variable to use it in the code internally:
https://stackoverflow.com/a/77576947/5164462

So it would be good to have an option on web to set this variable (e.g. via --flavor option), which is only available on flutter run -d chrome but not on flutter build web.

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

Labels

team-ios Owned by iOS platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flavor API should be derived at the flutter assemble level so it is set correctly when run from native tooling, like Android Studio or Xcode

5 participants