Skip to content

fix: forward --build-name and --build-number to desktop version.json - #190130

Merged
auto-submit[bot] merged 2 commits into
flutter:masterfrom
ishaquehassan:fix/152236-desktop-build-name-version-json
Aug 10, 2026
Merged

auto-submit[bot] merged 2 commits into
flutter:masterfrom
ishaquehassan:fix/152236-desktop-build-name-version-json

Conversation

@ishaquehassan

Copy link
Copy Markdown
Contributor

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 #152236

Pre-launch Checklist

On desktop, BuildInfo.toEnvironmentConfig() left out the build name and
number, so tool_backend.dart never passed them on to flutter assemble.
The generated flutter_assets/version.json kept the pubspec default
instead of the value given to --build-name or --build-number.

Emit BUILD_NAME and BUILD_NUMBER from toEnvironmentConfig() using the
existing null-aware map entries, and forward them as -dBuildName and
-dBuildNumber in tool_backend.dart next to the other optional defines.
The keys are absent when the flags are not supplied, so default
behavior is unchanged.

Fixes flutter#152236
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jul 28, 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 adds support for extracting and passing BUILD_NAME and BUILD_NUMBER environment variables to the backend tool, including them in the environment configuration map, and adds a unit test to verify this behavior. A critical compilation error was identified in build_info.dart where invalid Dart syntax is used to conditionally add these variables to the configuration map; using collection if elements is recommended instead.

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.

critical

The syntax 'BUILD_NAME': ?buildName, is not valid Dart and will cause a compilation error. To conditionally include map entries only when their values are non-null, use Dart's collection if elements.

      if (buildName != null) 'BUILD_NAME': buildName,
      if (buildNumber != null) 'BUILD_NUMBER': buildNumber,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah this one is actually fine, it is a null-aware map entry (Dart 3.9). The same ?value form is already used a few lines up for SPLIT_DEBUG_INFO, CODE_SIZE_DIRECTORY and FLAVOR, so I just matched that. Rewriting only these two as if (x != null) would make them inconsistent with the rest of the map. analyze is clean and the new test passes on it too.

@bkonyi bkonyi added the CICD Run CI/CD label Aug 10, 2026
@bkonyi
bkonyi requested review from bkonyi and chingjun August 10, 2026 17:56
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 10, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Aug 10, 2026
@chingjun chingjun added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 10, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 10, 2026
Merged via the queue into flutter:master with commit 3238466 Aug 10, 2026
28 of 29 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 10, 2026
@bkonyi bkonyi added the cp: stable cherry pick this pull request to stable release candidate branch label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD cp: stable cherry pick this pull request to stable release candidate branch tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--build-name is ignored on linux

3 participants