Fix flutter build web ignoring --web-define flag#182079
Fix flutter build web ignoring --web-define flag#182079auto-submit[bot] merged 8 commits intoflutter:masterfrom
flutter build web ignoring --web-define flag#182079Conversation
The `--web-define` CLI option was registered in `BuildWebCommand` via `usesWebDefineOption()` but the values were never extracted or passed through the build pipeline. This caused `flutter build web --web-define=KEY=VALUE` to silently ignore the defines, while `flutter run` worked correctly. The fix threads web-define values through the full build chain: 1. `build_web.dart`: Call `extractWebDefines()` and pass result to `buildWeb()`. 2. `compile.dart`: Add `kWebDefinePrefix` constant and `webDefines` parameter to `buildWeb()`, storing prefixed entries in `Environment.defines`. 3. `web.dart`: In `WebTemplatedFiles.build()`, extract web-define entries from the environment and pass them to both `withSubstitutions()` calls (bootstrap + index.html).
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where flutter build web ignored the --web-define flag. The changes correctly thread the web-define values through the build pipeline, from command-line parsing to the web template substitution. The implementation is clean and well-tested. I have one minor suggestion regarding adding documentation to a modified public method to align with the repository's style guide.
c935562 to
0a58482
Compare
9a01cce to
34794db
Compare
bkonyi
left a comment
There was a problem hiding this comment.
Thanks for your contribution, @mkucharski17! Just a couple of comments, but overall this looks good to me.
mdebbar
left a comment
There was a problem hiding this comment.
Thanks for contributing this fix!
Overall, the fix looks good to me!
I only have one suggestion: In order to prevent a similar issue from happening in the future, I'm thinking we should make the webDefines parameter required in buildWeb and in withSubstitutions. That would ensure all callers remember to pass webDefines. Thoughts?
|
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
…2273) <!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> This PR fixes a problem introduced in flutter#175805 that caused a build to exception to be thrown if variables like `{{this}}` were defined in the web `index.html`, but were not explicitly set by `--web-define=this=VALUE`. Resolves flutter#182243 Note: As per flutter#182076, this will always show the warning if ran with `flutter build web`, whereas `flutter run -d ...` works fine, regardless of whether you've set the variable or not. That is set to be fixed in flutter#182079, and does not have to do with this PR. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [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. - [x] 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. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [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/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Navaron Bracke <[email protected]>
…2273) <!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> This PR fixes a problem introduced in flutter#175805 that caused a build to exception to be thrown if variables like `{{this}}` were defined in the web `index.html`, but were not explicitly set by `--web-define=this=VALUE`. Resolves flutter#182243 Note: As per flutter#182076, this will always show the warning if ran with `flutter build web`, whereas `flutter run -d ...` works fine, regardless of whether you've set the variable or not. That is set to be fixed in flutter#182079, and does not have to do with this PR. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [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. - [x] 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. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [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/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Navaron Bracke <[email protected]>
## 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 <[email protected]>
…2273) <!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> This PR fixes a problem introduced in flutter#175805 that caused a build to exception to be thrown if variables like `{{this}}` were defined in the web `index.html`, but were not explicitly set by `--web-define=this=VALUE`. Resolves flutter#182243 Note: As per flutter#182076, this will always show the warning if ran with `flutter build web`, whereas `flutter run -d ...` works fine, regardless of whether you've set the variable or not. That is set to be fixed in flutter#182079, and does not have to do with this PR. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [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. - [x] 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. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [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/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Navaron Bracke <[email protected]>
Summary
flutter build web --web-define=KEY=VALUEsilently ignored the--web-defineflag. The option was registered viausesWebDefineOption()but the values were never extracted or passed through the build pipeline.flutter runwas unaffected as it correctly callsextractWebDefines().This PR threads web-define values through the full
flutter build webchain:build_web.dart: CallextractWebDefines()and pass the result tobuildWeb().compile.dart: AddkWebDefinePrefixconstant andwebDefinesparameter tobuildWeb(), storing prefixed entries inEnvironment.defines.web.dart: InWebTemplatedFiles.build(), extract web-define entries from the environment and pass them to bothwithSubstitutions()calls (bootstrap + index.html).Related to #175805.
Fixes #182076
Test plan
build_web_test.dart:--web-definevalues are passed toEnvironment.defineswithwebDefine:prefix.--web-defineand no prefixed entries are present.web_test.dart:WebTemplatedFilessubstitutes web-define variables inindex.html.WebTemplatedFilessubstitutes web-define variables influtter_bootstrap.js.WebTemplatedFilesworks correctly with no web-define variables.build_web_test.dart(24/24),web_test.dart(619/619), andweb_template_test.dart(16/16) pass.