Skip to content

Commit 3238466

Browse files
fix: forward --build-name and --build-number to desktop version.json (flutter#190130)
On desktop, `flutter build linux --build-name=4.5.6` produces a `flutter_assets/version.json` that still shows the pubspec default (`1.0.0`) instead of the value passed on the command line. The same happens with `--build-number`. That `version.json` (read by `package_info_plus`) is generated by the assemble target's `getVersionInfo`, which already honors the `BuildName` and `BuildNumber` defines. The break is upstream in the desktop build pipeline: those defines never reach `flutter assemble`. `BuildInfo.toEnvironmentConfig()`, which produces the environment map written into the generated CMake config, leaves the build name and number out, and `tool_backend.dart` does not forward them when it invokes assemble. Android and web are unaffected because they go through `toBuildSystemEnvironment()`, which already includes both values. This forwards the two values through the desktop path, following the same pattern already used for split-debug-info and tree-shake-icons. `toEnvironmentConfig()` now emits `BUILD_NAME` and `BUILD_NUMBER` via the existing null-aware map entries, and `tool_backend.dart` reads them and adds `-dBuildName` and `-dBuildNumber` to the assemble invocation next to the other optional defines. Because the map entries are null-aware, the keys are simply absent when the flags are not supplied, so default behavior is unchanged. No change is needed in `linux.dart`, which already applies these defines when they are present. Reproduced by the issue triager and reconfirmed by another user on 3.29.2. I added a `toEnvironmentConfig` unit test in `build_info_test.dart` that asserts the new keys appear when a build name and number are set. The existing encoding test keeps passing because null values stay omitted. Fixes flutter#152236 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [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. - [ ] 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. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [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/ [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md Co-authored-by: Ben Konyi <[email protected]>
1 parent 72311a8 commit 3238466

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎packages/flutter_tools/bin/tool_backend.dart‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Future<void> main(List<String> arguments) async {
2626
final String? localEngineHost = Platform.environment['LOCAL_ENGINE_HOST'];
2727
final String? projectDirectory = Platform.environment['PROJECT_DIR'];
2828
final String? splitDebugInfo = Platform.environment['SPLIT_DEBUG_INFO'];
29+
final String? buildName = Platform.environment['BUILD_NAME'];
30+
final String? buildNumber = Platform.environment['BUILD_NUMBER'];
2931
final trackWidgetCreation = Platform.environment['TRACK_WIDGET_CREATION'] == 'true';
3032
final treeShakeIcons = Platform.environment['TREE_SHAKE_ICONS'] == 'true';
3133
final verbose = Platform.environment['VERBOSE_SCRIPT_LOGGING'] == 'true';
@@ -98,6 +100,8 @@ or
98100
if (codeSizeDirectory != null) '-dCodeSizeDirectory=$codeSizeDirectory',
99101
if (flavor != null && flavor.isNotEmpty) '-dFlavor=$flavor',
100102
if (splitDebugInfo != null) '-dSplitDebugInfo=$splitDebugInfo',
103+
if (buildName != null) '-dBuildName=$buildName',
104+
if (buildNumber != null) '-dBuildNumber=$buildNumber',
101105
if (dartDefines != null) '--DartDefines=$dartDefines',
102106
if (extraGenSnapshotOptions != null) '--ExtraGenSnapshotOptions=$extraGenSnapshotOptions',
103107
if (frontendServerStarterPath != null) '-dFrontendServerStarterPath=$frontendServerStarterPath',

‎packages/flutter_tools/lib/src/build_info.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ class BuildInfo {
417417
'EXTRA_FRONT_END_OPTIONS': extraFrontEndOptions.join(','),
418418
if (extraGenSnapshotOptions.isNotEmpty)
419419
'EXTRA_GEN_SNAPSHOT_OPTIONS': extraGenSnapshotOptions.join(','),
420+
'BUILD_NAME': ?buildName,
421+
'BUILD_NUMBER': ?buildNumber,
420422
'SPLIT_DEBUG_INFO': ?splitDebugInfoPath,
421423
'TRACK_WIDGET_CREATION': trackWidgetCreation.toString(),
422424
'TREE_SHAKE_ICONS': treeShakeIcons.toString(),

‎packages/flutter_tools/test/general.shard/build_info_test.dart‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,20 @@ void main() {
292292
});
293293
});
294294

295+
testWithoutContext('toEnvironmentConfig includes build name and build number', () {
296+
const buildInfo = BuildInfo(
297+
BuildMode.release,
298+
null,
299+
buildName: '4.5.6',
300+
buildNumber: '7',
301+
treeShakeIcons: false,
302+
packageConfigPath: 'foo/.dart_tool/package_config.json',
303+
);
304+
305+
expect(buildInfo.toEnvironmentConfig()['BUILD_NAME'], '4.5.6');
306+
expect(buildInfo.toEnvironmentConfig()['BUILD_NUMBER'], '7');
307+
});
308+
295309
testWithoutContext('toGradleConfig encoding of standard values', () {
296310
const buildInfo = BuildInfo(
297311
BuildMode.debug,

0 commit comments

Comments
 (0)