Add --flavor support for Linux desktop builds#187029
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for the --flavor option to Flutter Linux builds, modifying build directory logic, binary naming, and application IDs. The flavor is passed to CMake and the C++ runner to enable flavor-aware behavior, such as dynamic window titles. Review feedback suggests mitigating a potential format string vulnerability in the C++ template and implementing a check for missing binary names to prevent invalid file path construction.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
robert-ancell
left a comment
There was a problem hiding this comment.
Nice work!
In this review I was particularly thinking about the application ID naming and any side effects that might have, the means of passing this to the application via CMake and consistency with other platforms. The choices all seem appropriate to me. I can see a very similar solution working for Windows.
I would like a second review from someone who has used the flavor system in Flutter (I have not) - @loic-sharma can you suggest someone for that?
|
I published an application on Flathub; the original application ID was |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
FYI, I left feedback on the Windows PR, #187034, that should also be addressed on this PR as well :) |
…add-linux-flavors-support
Head branch was pushed to by a user without write access
robert-ancell
left a comment
There was a problem hiding this comment.
I'm happy with this - @loic-sharma was there anything left to match the Windows PR?
|
The branch cutoff date of 3.47 is July 7th, so this feature will not appear in 3.47? |
|
@kjxbyz maybe they want to keep them separate on purpose. Who knows |
|
@AngeloAvv It sounds quite frustrating. |
|
It looks like this did make the 3.47 cutoff. See: https://github.com/flutter/flutter/commits/flutter-3.47-candidate.0?author=AngeloAvv |
Flutter desktop on Linux currently has no equivalent of the
--flavorplumbing that already exists for Android, iOS, and macOS:flutter build linux --flavor Xis rejected at the command-parser level,flutter run -d linux --flavor Xemits a "flavor only supported on Android, iOS, macOS" warning, and there is no convention for producing per-flavor binaries or build directories. This PR wires the existing flavor infrastructure end-to-end on Linux so that multiple flavors can coexist in the same project without colliding on disk or in the runner.What changes
flutter build linuxaccepts--flavorvia the sharedusesFlavorOption()helper.LinuxDevice.supportsFlavorsreturnstrue, soflutter run -d linux --flavor Xno longer warns and now drives the flavored build pipeline.build/linux/<arch>/<flavor>/<mode>/(parity with Android/iOS/macOS). Projects that don't pass--flavorkeep the legacybuild/linux/<arch>/<mode>/layout — no migration required.-DFLUTTER_APP_FLAVOR=<flavor>so the generated project can react to the flavor at configure time.BINARY_NAMEwith-<flavor>andAPPLICATION_IDwith.<flavor>whenFLUTTER_APP_FLAVORis defined, matching the AndroidapplicationIdSuffixconvention. The branch is guarded byif(DEFINED FLUTTER_APP_FLAVOR AND NOT FLUTTER_APP_FLAVOR STREQUAL ""), so existing projects regenerated from this template behave identically when no flavor is passed.linux.tmpl/runner/CMakeLists.txt+my_application.cc.tmpl) exposesFLUTTER_APP_FLAVORas a compile-time preprocessor define (same mechanism already used forAPPLICATION_ID) and uses it to suffix the GTK window title, giving projects a one-line entry point for flavor-aware native behavior without any additional Flutter tool surface area.appFlavorgetter frompackage:flutter/services.dart, which readsFLUTTER_APP_FLAVORfrom the dart-defines thattoEnvironmentConfig()already produces. No framework changes required.Design choices
APPLICATION_IDsuffix mirrors Android (it.example.app→it.example.app.free) so packaging tooling and.desktopfiles have a stable convention to key off.ls build/linux/x64/and see each flavor side-by-side..desktopfiles, and snap/deb packaging remain the project's responsibility — this PR intentionally keeps the tool agnostic and only standardizes the plumbing.Tests
test/general.shard/linux/build_linux_flavor_test.dartcovers:flutter build linux --flavor appleinvokes CMake with-DFLUTTER_APP_FLAVOR=appleand a flavored working directory, and the success log referencesbuild/linux/x64/apple/release/bundle.getCmakeExecutableNamereturns the base binary name without a flavor, andname-flavorwhen a flavor is provided (empty string treated as no flavor).test/commands.shard/hermetic/build_linux_test.dart(25 cases) continues to pass with no changes, confirming the legacy no-flavor path is unaffected.Manual verification
Generated an example project, then ran the full matrix:
All three builds coexist in
build/linux/x64/without overwriting each other, and the Dart UI readsappFlavorcorrectly at runtime in each binary.Backward compatibility
--flavorsee no change: same build directory, same binary name, sameAPPLICATION_ID, same generated CMake.linux/CMakeLists.txtto keep working; they only need to regenerate (or hand-patch theif(DEFINED FLUTTER_APP_FLAVOR)branch) to opt into flavor support.Fixes #162373
Pre-launch Checklist
///).