[CP-stable]Fix flutter build web ignoring --web-define flag#182344
Conversation
## Summary `flutter build web --web-define=KEY=VALUE` silently ignored the `--web-define` flag. The option was registered via `usesWebDefineOption()` but the values were never extracted or passed through the build pipeline. `flutter run` was unaffected as it correctly calls `extractWebDefines()`. This PR threads web-define values through the full `flutter build web` chain: - **`build_web.dart`**: Call `extractWebDefines()` and pass the result to `buildWeb()`. - **`compile.dart`**: Add `kWebDefinePrefix` constant and `webDefines` parameter to `buildWeb()`, storing prefixed entries in `Environment.defines`. - **`web.dart`**: In `WebTemplatedFiles.build()`, extract web-define entries from the environment and pass them to both `withSubstitutions()` calls (bootstrap + index.html). Related to flutter#175805. Fixes flutter#182076 ## Test plan - Added 2 tests in `build_web_test.dart`: - Verifies `--web-define` values are passed to `Environment.defines` with `webDefine:` prefix. - Verifies builds succeed without `--web-define` and no prefixed entries are present. - Added 3 tests in `web_test.dart`: - `WebTemplatedFiles` substitutes web-define variables in `index.html`. - `WebTemplatedFiles` substitutes web-define variables in `flutter_bootstrap.js`. - `WebTemplatedFiles` works correctly with no web-define variables. - All existing tests in `build_web_test.dart` (24/24), `web_test.dart` (619/619), and `web_template_test.dart` (16/16) pass. --------- Co-authored-by: Mouad Debbar <mdebbar@google.com>
|
@mdebbar please fill out the PR description above, afterwards the release team will review this request. |
|
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. |
There was a problem hiding this comment.
Code Review
This pull request is a cherry-pick to the stable branch. The changes address an issue where flutter build web was ignoring the --web-define flag. The modifications pass the --web-define values from the command line into the build environment, allowing them to be used for variable substitution in web template files such as index.html. New tests are included to verify this functionality. The changes appear correct and complete.
2ac4854
into
flutter:flutter-3.41-candidate.0
This pull request is created by automatic cherry pick workflow
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.
Issue Link:
What is the link to the issue this cherry-pick is addressing?
#182076
Impact Description:
What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)?
Does it impact development (ex. flutter doctor crashes when Android Studio is installed),
or the shipping of production apps (the app crashes on launch).
This information is for domain experts and release engineers to understand the consequences of saying yes or no to the cherry pick.
The
--web-definefeature works during development (i.e.flutter run), but doesn't work for production (i.e.flutter build web).Changelog Description:
Explain this cherry pick:
See best practices for examples.
Fix
flutter build webignoring--web-defineflagWorkaround:
Is there a workaround for this issue?
No workaround.
Risk:
What is the risk level of this cherry-pick?
Test Coverage:
Are you confident that your fix is well-tested by automated tests?
Validation Steps:
What are the steps to validate that this fix works?
Follow repro steps in #182076