Skip to content

Commit 78c8547

Browse files
[stable] fix: forward --build-name and --build-number to desktop version.json (#191602)
### Issue Link: #152236 ### Impact Description: On desktop platforms (Linux, Windows, macOS), passing `--build-name` or `--build-number` to `flutter build` does not forward these values to the desktop assemble build backend. As a result, the generated `flutter_assets/version.json` contains default pubspec version values instead of the values passed on the command line, breaking version reporting in packages like `package_info_plus` and CI release pipelines. ### Changelog Description: [flutter/152236] Forward `--build-name` and `--build-number` flags to the desktop build pipeline so generated `version.json` reflects command-line build version parameters on desktop platforms. ### Workaround: Manually edit the version string in `pubspec.yaml` prior to building. ### Risk: ### Test Coverage: ### Validation Steps: 1. Run `flutter build linux --build-name=4.5.6 --build-number=789` (or on windows/macos). 2. Inspect the generated `build/linux/x64/release/bundle/data/flutter_assets/version.json`. 3. Verify that `version.json` contains `"version": "4.5.6"` and `"build_number": "789"`.
1 parent 2c72122 commit 78c8547

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
@@ -393,6 +393,8 @@ class BuildInfo {
393393
'EXTRA_FRONT_END_OPTIONS': extraFrontEndOptions.join(','),
394394
if (extraGenSnapshotOptions.isNotEmpty)
395395
'EXTRA_GEN_SNAPSHOT_OPTIONS': extraGenSnapshotOptions.join(','),
396+
'BUILD_NAME': ?buildName,
397+
'BUILD_NUMBER': ?buildNumber,
396398
'SPLIT_DEBUG_INFO': ?splitDebugInfoPath,
397399
'TRACK_WIDGET_CREATION': trackWidgetCreation.toString(),
398400
'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
@@ -289,6 +289,20 @@ void main() {
289289
});
290290
});
291291

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

0 commit comments

Comments
 (0)