Repository navigation
Pass web-defines to the web builder in all run configurations - #189622
auto-submit[bot] merged 4 commits into
Conversation
|
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. |
1989db4 to
6241e70
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for forwarding and substituting --web-define values during flutter drive and flutter run commands for web targets. It updates DriveCommand, DriverService, WebDriverService, and ResidentWebRunner to accept and propagate webDefines. Additionally, new unit, integration, and web shard tests are introduced to verify that --web-define placeholders are correctly substituted in the output and served files, and that this substitution persists across hot reloads and hot restarts. There are no review comments, and I have no feedback to provide.
There was a problem hiding this comment.
Code Review
This pull request adds support for forwarding --web-define flags to the web runner during flutter drive and flutter run commands, ensuring placeholders are correctly substituted in index.html and flutter_bootstrap.js. Feedback suggests scoping the buildEnvironment variable inside a test group in resident_web_runner_test.dart to avoid state leakage, and relaxing the SDK constraint in the test project's pubspec to improve compatibility.
…e modes and to flutter drive
--web-define substitution of {{PLACEHOLDER}} tokens in web/index.html and
flutter_bootstrap.js worked in debug flutter run (serve-time substitution in
WebAssetServer) and in flutter build web (webDefine:-prefixed entries in the
build Environment consumed by WebTemplatedFiles), but not in flutter run
--profile or --release: ResidentWebRunner stored the parsed defines in
_webDefines and then omitted them from both WebBuilder.buildWeb() calls in
the non-debug branch, and ReleaseAssetServer serves the build output verbatim
with no serve-time templating, so the placeholders were never replaced.
This passes webDefines to both buildWeb() call sites (the initial build in
run() and the rebuild on hot restart), matching how flutter build web already
passes them. Debug --wasm runs take the same branch and are fixed as a side
effect. flutter drive never forwarded web-defines in any mode, so the flag is
now plumbed through DriverService.start() into WebDriverService and on to the
web runner.
## Tests
Added tests asserting the build Environment receives the webDefine:-prefixed
defines in profile mode, on the rebuild after a hot restart in release mode,
and in debug --wasm mode; that WebDriverService forwards web-defines to the
web runner; and that the drive command forwards --web-define values to
DriverService.start(). Existing web-define coverage for flutter build web and
debug-mode serving is unchanged and passing.
08383a7 to
a8c93db
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for forwarding --web-define arguments to the web runner during flutter drive and flutter run commands, updating the driver services and runner configurations accordingly. It also introduces integration and unit tests to verify that placeholders are correctly substituted in the output files and maintained across hot restarts and reloads. The review feedback suggests simplifying the test project's continuous loop to prevent high CPU usage, wrapping the test driver teardown in a try-finally block to ensure temporary directory cleanup, and adding a connection timeout to the HTTP client to prevent test hangs.
|
|
||
| expect(await residentWebRunner.run(), 0); | ||
| expect(buildEnvironment, isNotNull); | ||
| expect(buildEnvironment!.defines['webDefine:VERSION'], 'v1.2.3'); |
There was a problem hiding this comment.
We can just perform this check in the callback below instead of setting buildEnvironment here and in other test cases.
There was a problem hiding this comment.
@bkonyi fixed, now we do the assertions in the callback for all the new tests.
|
autosubmit label was removed for flutter/flutter/189622, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.
|
--web-definesubstitution of{{PLACEHOLDER}}tokens inweb/index.htmlandflutter_bootstrap.jsworked in debugflutter run(serve-time substitution inWebAssetServer) and influtter build web(webDefine:-prefixed entries in thebuild
Environmentconsumed by theWebTemplatedFilestarget), but not influtter run --profileor--release:ResidentWebRunnerstored the parseddefines in
_webDefinesand then omitted them from bothWebBuilder.buildWeb()calls in the non-debug branch, and
ReleaseAssetServerserves the build outputverbatim with no serve-time templating, so the placeholders were never replaced.
This passes
webDefinesto bothbuildWeb()call sites (the initial build inrun()and the rebuild on hot restart), matching howflutter build webalreadypasses them. Debug
--wasmruns take the same branch and are fixed as a sideeffect.
flutter drivenever forwarded web-defines in any mode, so the flag isnow plumbed through
DriverService.start()intoWebDriverServiceand on to theweb runner.
Added unit tests assert that the build
Environmentreceives thewebDefine:-prefixed defines in profile mode, on the rebuild after a hot restartin release mode, and in debug
--wasmmode; thatWebDriverServiceforwardsweb-defines to the web runner; and that the drive command forwards
--web-definevalues to
DriverService.start().Added end-to-end tests run the real tool against a fixture project whose
web/index.htmlandweb/flutter_bootstrap.jscontain{{MY_VERSION}}and{{API_URL}}placeholders:flutter build webin debug/profile/release mustsubstitute them in
build/web/index.htmlandbuild/web/flutter_bootstrap.js,and
flutter run -d web-serverin debug/profile/release must serve substitutedHTML, including after hot reload (debug) and hot restart (all three modes).
Existing web-define coverage for
flutter build weband debug-mode serving isunchanged and passing.
Fixes #8885 (was closed, but the problem was actually this - the flag was only passed on specific run configurations). Also related to PR #175805 and issue #127853
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.