Repository navigation
Description
Currently Flutter determines the channel from the local git branch name (git symbolic-ref --short HEAD), and any branch other than stable or beta (including detached HEAD, e.g. git checkout 3.50.0, or a custom local branch) becomes [user-branch] and falls back to master feature flag defaults:
flutter/packages/flutter_tools/lib/src/version.dart
Lines 484 to 499 in 9d3c617
| String getBranchName({bool redactUnknownBranches = false}) { | |
| _branch ??= () { | |
| final String branch = _git | |
| .runSync(['symbolic-ref', '--short', 'HEAD'], workingDirectory: flutterRoot) | |
| .stdout | |
| .trim(); | |
| return branch == 'HEAD' ? '' : branch; | |
| }(); | |
| if (redactUnknownBranches || _branch!.isEmpty) { | |
| // Only return the branch names we know about; arbitrary branch names might contain PII. | |
| if (!kOfficialChannels.contains(_branch) && !kObsoleteBranches.containsKey(_branch)) { | |
| return kUserBranch; | |
| } | |
| } | |
| return _branch!; | |
| } |
flutter/packages/flutter_tools/lib/src/features.dart
Lines 465 to 471 in 9d3c617
| FeatureChannelSetting getSettingForChannel(String channel) { | |
| return switch (channel) { | |
| 'stable' => stable, | |
| 'beta' => beta, | |
| 'master' || _ => master, | |
| }; | |
| } |
This means the exact same commit can behave differently depending on how you checked it out, which is pretty confusing. Two places where this comes up:
- Pinned tag checkouts / reproducible builds (see Turn Hybrid Composition++ (HCPP) on by default #189939): checking out
3.50.0directly puts you in detached HEAD ([user-branch]), which turnsenable-hcppon by default and injects<meta-data android:name="io.flutter.embedding.android.EnableHcpp" android:value="true"/>intoAndroidManifest.xml, whereas building from thestablebranch on the exact same commit omits it. - Investigating a bug or bisecting on
stable: branching offstableto investigate an issue (or runninggit bisect) can silently run withmasterfeature flags (enable-hcpp,enable-riscv64, etc.) instead ofstable's.
There is also what seems like a separate caching bug that makes this worse: bin/cache/flutter.version.json caches channel, and shared.sh/shared.bat only deletes it when the commit SHA changes and the tool rebuilds (
flutter/bin/internal/shared.sh
Line 150 in 9d3c617
| rm -f "$FLUTTER_ROOT/bin/cache/flutter.version.json" |
stable, you initially keep stable flags, and then making even an empty commit (or checking out another commit to rebuild the tool and coming back to your untouched branch) invalidates the cache and flips the flags underneath you.
Repro (on 3.50.0 / ab2912035e)
# Case 1: Branch off `stable`, then make a commit on the investigation branch.
# Initially `bin/cache/flutter.version.json` still caches `channel: stable`
# (same commit SHA), so the new branch keeps `stable` feature flags. Once any
# commit changes the SHA, the flutter tool rebuilds, invalidates
# `flutter.version.json`, detects channel `[user-branch]`, and silently flips
# to `master` defaults (`enable-riscv64` and `enable-hcpp` turn on underneath you).
mackall-mac2:flutter mackall$ git checkout stable
Switched to branch 'stable'
Your branch is up to date with 'upstream/stable'.
post-checkout: The engine source tree has been updated.
You may need to run "gclient sync -D"
mackall-mac2:flutter mackall$ flutter doctor -v | grep "Feature flags:"
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration
mackall-mac2:flutter mackall$ git checkout -b hypothetically_investigate_stable_bug
Switched to a new branch 'hypothetically_investigate_stable_bug'
post-checkout: The engine source tree has been updated.
You may need to run "gclient sync -D"
mackall-mac2:flutter mackall$ flutter doctor -v | grep "Feature flags:"
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration
mackall-mac2:flutter mackall$ git commit --allow-empty -m "nothing"
[hypothetically_investigate_stable_bug 7e11ab92d11] nothing
mackall-mac2:flutter mackall$ flutter doctor -v | grep "Feature flags:"
Building flutter tool...
Got dependencies.
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration, enable-riscv64, enable-hcpp
# Case 2: Comparing `stable` directly against checking out a custom branch or
# detached tag (e.g. `git checkout 3.50.0`) on the exact same commit without a
# pre-cached `stable` `flutter.version.json`.
#
# Removing `bin/cache/flutter.version.json` simulates either:
# (a) a fresh checkout (e.g. CI / F-Droid builder checking out a tag directly), or
# (b) checking out `stable` -> creating an investigation branch -> checking out
# any other commit (rebuilding the tool and clearing `flutter.version.json`) ->
# checking back out to your untouched investigation branch, which now behaves
# differently (`enable-riscv64` and `enable-hcpp` enabled) with zero changes.
mackall-mac2:flutter mackall$ git checkout stable
Switched to branch 'stable'
Your branch is up to date with 'upstream/stable'.
post-checkout: The engine source tree has been updated.
You may need to run "gclient sync -D"
mackall-mac2:flutter mackall$ flutter doctor -v | grep "Feature flags:"
Building flutter tool...
Got dependencies.
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration
mackall-mac2:flutter mackall$ git checkout -b again_hypothetically_do_work
Switched to a new branch 'again_hypothetically_do_work'
post-checkout: The engine source tree has been updated.
You may need to run "gclient sync -D"
mackall-mac2:flutter mackall$ rm -f bin/cache/flutter.version.json
mackall-mac2:flutter mackall$ flutter doctor -v | grep "Feature flags:"
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration, enable-riscv64, enable-hcpp
Activity
[flutter_tools] Delete flutter.version.json when switching channels (f…
[flutter_tools] Use refreshed FlutterVersion for flutter doctor featu…