Skip to content

[stable] fix: forward --build-name and --build-number to desktop version.json - #191602

Merged
auto-submit[bot] merged 1 commit into
flutter:flutter-3.47-candidate.0from
flutteractionsbot:cp-stable-32384666b443e8609e3655665f2d1fd8726bfd02
Aug 24, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:flutter-3.47-candidate.0from
flutteractionsbot:cp-stable-32384666b443e8609e3655665f2d1fd8726bfd02

Conversation

@flutteractionsbot

@flutteractionsbot flutteractionsbot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Low
  • Medium
  • High

Test Coverage:

  • Yes
  • No

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".

…lutter#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]>
@flutteractionsbot flutteractionsbot added the cp: review Cherry-picks in the review queue label Aug 24, 2026
@flutteractionsbot

Copy link
Copy Markdown
Contributor Author

@bkonyi please fill out the PR description above, afterwards the release team will review this request.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 24, 2026
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Aug 24, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter.

Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed.

@bkonyi bkonyi changed the title [CP-stable]fix: forward --build-name and --build-number to desktop version.json [stable] fix: forward --build-name and --build-number to desktop version.json Aug 24, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces BUILD_NAME and BUILD_NUMBER environment variables to tool_backend.dart and build_info.dart, and adds a test case in build_info_test.dart. The review feedback notes that the syntax used for these variables in build_info.dart is invalid and should be replaced with collection if statements. Additionally, the feedback suggests checking that the variables are non-empty before appending them to the arguments list in tool_backend.dart, and adding a test case to verify the behavior when they are null.

Comment on lines +396 to +397
'BUILD_NAME': ?buildName,
'BUILD_NUMBER': ?buildNumber,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Using ?buildName and ?buildNumber is invalid Dart syntax and will cause compilation errors. Instead, use Dart's idiomatic collection if to conditionally include these keys in the map literal only when they are non-null.

      if (buildName != null) 'BUILD_NAME': buildName,
      if (buildNumber != null) 'BUILD_NUMBER': buildNumber,
References
  1. Follow Effective Dart and Flutter style guidelines for idiomatic Dart code, such as using collection if for conditional map entries. (link)

Comment on lines +103 to +104
if (buildName != null) '-dBuildName=$buildName',
if (buildNumber != null) '-dBuildNumber=$buildNumber',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To prevent passing empty strings as build name or build number arguments (which could cause issues in the build system), check that they are both non-null and non-empty, matching the pattern used for flavor.

Suggested change
if (buildName != null) '-dBuildName=$buildName',
if (buildNumber != null) '-dBuildNumber=$buildNumber',
if (buildName != null && buildName.isNotEmpty) '-dBuildName=$buildName',
if (buildNumber != null && buildNumber.isNotEmpty) '-dBuildNumber=$buildNumber',

Comment on lines +302 to +304
expect(buildInfo.toEnvironmentConfig()['BUILD_NAME'], '4.5.6');
expect(buildInfo.toEnvironmentConfig()['BUILD_NUMBER'], '7');
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

It is good practice to verify the behavior when buildName and buildNumber are null. Since we conditionally omit these keys when they are null, we should assert that they are not present in the returned environment config map.

    expect(buildInfo.toEnvironmentConfig()['BUILD_NAME'], '4.5.6');
    expect(buildInfo.toEnvironmentConfig()['BUILD_NUMBER'], '7');

    const buildInfoNull = BuildInfo(
      BuildMode.release,
      null,
      treeShakeIcons: false,
      packageConfigPath: 'foo/.dart_tool/package_config.json',
    );
    expect(buildInfoNull.toEnvironmentConfig().containsKey('BUILD_NAME'), isFalse);
    expect(buildInfoNull.toEnvironmentConfig().containsKey('BUILD_NUMBER'), isFalse);
  }

@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 24, 2026
@auto-submit
auto-submit Bot merged commit 78c8547 into flutter:flutter-3.47-candidate.0 Aug 24, 2026
10 checks passed
@flutteractionsbot
flutteractionsbot deleted the cp-stable-32384666b443e8609e3655665f2d1fd8726bfd02 branch August 24, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD cp: review Cherry-picks in the review queue tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants