Repository: flutter
Issue: [web] Build breaks if dart format fixes an import
Labels: team,engine,platform-web,P2,team-web,triaged-web,e: engine-tool

I was doing some clandestine `dart format` in some of the files I've been working on, and I got my `felt build --host` to fail like so:

<details>
<summary>
<tt>$ rm -fr out/host_debug_unopt/ && gclient sync -D && felt build --host</tt>
</summary>

```
Updating depot_tools...
Syncing projects: 100% (135/135), done.                                                                            
Running hooks: 100% (11/11), done.                 
Running `dart pub get` in 'engine/src/flutter/lib/web_ui'
Resolving dependencies... 
  _fe_analyzer_shared 50.0.0 (51.0.0 available)
  analyzer 5.2.0 (5.3.1 available)
  archive 3.1.2 (3.3.5 available)
  collection 1.15.0 (1.17.0 available)
  crypto 3.0.1 (3.0.2 available)
  html 0.15.0 (0.15.1 available)
  image 3.0.1 (3.2.2 available)
  js 0.6.4 (0.6.5 available)
  path 1.8.0 (1.8.3 available)
  petitparser 4.4.0 (5.1.0 available)
  process 4.2.3 (4.2.4 available)
  quiver 3.0.0 (3.1.0 available)
  stack_trace 1.10.0 (1.11.0 available)
  typed_data 1.3.0 (1.3.1 available)
  uuid 3.0.6 (3.0.7 available)
  watcher 1.0.0 (1.0.2 available)
  webdriver 3.0.0 (3.0.1 available)
  webkit_inspection_protocol 1.0.0 (1.2.0 available)
  xml 5.3.1 (6.2.2 available)
  yaml 3.0.0 (3.1.1 available)
Got dependencies!
Running gn...
Using prebuilt Dart SDK binary. If you are editing Dart sources and wish to compile the Dart SDK, set `--no-prebuilt-dart-sdk`.
Generating GN files in: out/host_debug_unopt
Generating compile_commands took 52ms
Done. Made 1123 targets from 338 files in 2473ms
Running autoninja...
ninja: Entering directory `/usr/local/google/home/dit/github/engine/src/out/host_debug_unopt'
[3194/7108] ACTION //flutter/web_sdk:flutter_dartdevc_kernel_sdk_outline_sound(//build/toolchain/linux:clang_x64)
FAILED: flutter_web_sdk/kernel/ddc_outline_sound.dill 
vpython3 ../../build/gn_run_binary.py ../../flutter/prebuilts/linux-x64/dart-sdk/bin/dart /usr/local/google/home/dit/github/engine/src/flutter/prebuilts/linux-x64/dart-sdk/bin/snapshots/kernel_worker.dart.snapshot --sound-null-safety --summary-only --target ddc --packages-file file:////usr/local/google/home/dit/github/engine/src/third_party/dart/.dart_tool/package_config.json --multi-root-scheme org-dartlang-sdk --multi-root file:////usr/local/google/home/dit/github/engine/src/out/host_debug_unopt/flutter_web_sdk --libraries-file org-dartlang-sdk:///libraries.json --output /usr/local/google/home/dit/github/engine/src/out/host_debug_unopt/flutter_web_sdk/kernel/ddc_outline_sound.dill --source dart:core --source dart:ui --source dart:_engine --source dart:_skwasm_stub --source dart:_web_unicode --source dart:_web_locale_keymap --multi-root file:////usr/local/google/home/dit/github/engine/src/flutter/prebuilts/linux-x64
org-dartlang-sdk:///lib/_engine/engine/initialization.dart:19:12: Error: 'buildMode' is already declared in this scope.
String get buildMode => kReleaseMode
           ^^^^^^^^^
org-dartlang-sdk:///lib/_engine/engine/embedder.dart:8:10: Context: Previous declaration of 'buildMode'.
    show buildMode, registerHotRestartListener, renderer, window;
         ^^^^^^^^^
org-dartlang-sdk:///lib/_engine/engine/initialization.dart:38:6: Error: 'registerHotRestartListener' is already declared in this scope.
void registerHotRestartListener(ui.VoidCallback listener) {
     ^^^^^^^^^^^^^^^^^^^^^^^^^^
org-dartlang-sdk:///lib/_engine/engine/embedder.dart:8:21: Context: Previous declaration of 'registerHotRestartListener'.
    show buildMode, registerHotRestartListener, renderer, window;
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
org-dartlang-sdk:///lib/_engine/engine/renderer.dart:10:14: Error: 'renderer' is already declared in this scope.
Renderer get renderer => _renderer;
             ^^^^^^^^
org-dartlang-sdk:///lib/_engine/engine/embedder.dart:8:49: Context: Previous declaration of 'renderer'.
    show buildMode, registerHotRestartListener, renderer, window;
                                                ^^^^^^^^
org-dartlang-sdk:///lib/_engine/engine/window.dart:352:36: Error: 'window' is already declared in this scope.
final EngineSingletonFlutterWindow window =
                                   ^^^^^^
org-dartlang-sdk:///lib/_engine/engine/embedder.dart:8:59: Context: Previous declaration of 'window'.
    show buildMode, registerHotRestartListener, renderer, window;
                                                          ^^^^^^
org-dartlang-sdk:///lib/_engine/engine/embedder.dart:8:5: Error: Type 'show' not found.
    show buildMode, registerHotRestartListener, renderer, window;
    ^^^^

[3195/7108] ACTION //flutter/web_sdk:flutter_dartdevc_kernel_sdk_outline_unsound(//build/toolchain/linux:clang_x64)
FAILED: flutter_web_sdk/kernel/ddc_outline.dill 
vpython3 ../../build/gn_run_binary.py ../../flutter/prebuilts/linux-x64/dart-sdk/bin/dart /usr/local/google/home/dit/github/engine/src/flutter/prebuilts/linux-x64/dart-sdk/bin/snapshots/kernel_worker.dart.snapshot --no-sound-null-safety --summary-only --target ddc --packages-file file:////usr/local/google/home/dit/github/engine/src/third_party/dart/.dart_tool/package_config.json --multi-root-scheme org-dartlang-sdk --multi-root file:////usr/local/google/home/dit/github/engine/src/out/host_debug_unopt/flutter_web_sdk --libraries-file org-dartlang-sdk:///libraries.json --output /usr/local/google/home/dit/github/engine/src/out/host_debug_unopt/flutter_web_sdk/kernel/ddc_outline.dill --source dart:core --source dart:ui --source dart:_engine --source dart:_skwasm_stub --source dart:_web_unicode --source dart:_web_locale_keymap --multi-root file:////usr/local/google/home/dit/github/engine/src/flutter/prebuilts/linux-x64
org-dartlang-sdk:///lib/_engine/engine/initialization.dart:19:12: Error: 'buildMode' is already declared in this scope.
String get buildMode => kReleaseMode
           ^^^^^^^^^
org-dartlang-sdk:///lib/_engine/engine/embedder.dart:8:10: Context: Previous declaration of 'buildMode'.
    show buildMode, registerHotRestartListener, renderer, window;
         ^^^^^^^^^
org-dartlang-sdk:///lib/_engine/engine/initialization.dart:38:6: Error: 'registerHotRestartListener' is already declared in this scope.
void registerHotRestartListener(ui.VoidCallback listener) {
     ^^^^^^^^^^^^^^^^^^^^^^^^^^
org-dartlang-sdk:///lib/_engine/engine/embedder.dart:8:21: Context: Previous declaration of 'registerHotRestartListener'.
    show buildMode, registerHotRestartListener, renderer, window;
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
org-dartlang-sdk:///lib/_engine/engine/renderer.dart:10:14: Error: 'renderer' is already declared in this scope.
Renderer get renderer => _renderer;
             ^^^^^^^^
org-dartlang-sdk:///lib/_engine/engine/embedder.dart:8:49: Context: Previous declaration of 'renderer'.
    show buildMode, registerHotRestartListener, renderer, window;
                                                ^^^^^^^^
org-dartlang-sdk:///lib/_engine/engine/window.dart:352:36: Error: 'window' is already declared in this scope.
final EngineSingletonFlutterWindow window =
                                   ^^^^^^
org-dartlang-sdk:///lib/_engine/engine/embedder.dart:8:59: Context: Previous declaration of 'window'.
    show buildMode, registerHotRestartListener, renderer, window;
                                                          ^^^^^^
org-dartlang-sdk:///lib/_engine/engine/embedder.dart:8:5: Error: Type 'show' not found.
    show buildMode, registerHotRestartListener, renderer, window;
    ^^^^



[... many, many lines removed ...]


org-dartlang-sdk:///lib/_engine/engine/platform_dispatcher.dart:431:17: Error: Can't use 'renderer' because it is declared more than once.
            if (renderer is CanvasKitRenderer) {
                ^
org-dartlang-sdk:///lib/_engine/engine/platform_dispatcher.dart:647:5: Error: Can't use 'renderer' because it is declared more than once.
    renderer.renderScene(scene);
    ^
org-dartlang-sdk:///lib/_engine/engine/platform_dispatcher.dart:1177:7: Error: Can't use 'window' because it is declared more than once.
      window.debugOverrideDevicePixelRatio(ratio);
      ^
org-dartlang-sdk:///lib/_engine/engine/pointer_binding.dart:85:9: Error: Can't use 'registerHotRestartListener' because it is declared more than once.
        registerHotRestartListener(_instance!.dispose);
        ^
org-dartlang-sdk:///lib/_engine/engine/raw_keyboard.dart:20:5: Error: Can't use 'registerHotRestartListener' because it is declared more than once.
    registerHotRestartListener(() {
    ^
org-dartlang-sdk:///lib/_engine/engine/semantics/accessibility.dart:44:3: Error: Can't use 'registerHotRestartListener' because it is declared more than once.
  registerHotRestartListener(() {
  ^
org-dartlang-sdk:///lib/_engine/engine/semantics/semantics.dart:1424:5: Error: Can't use 'registerHotRestartListener' because it is declared more than once.
    registerHotRestartListener(() {
    ^
org-dartlang-sdk:///lib/_engine/engine/test_embedding.dart:21:3: Error: Can't use 'window' because it is declared more than once.
  window.debugOverrideDevicePixelRatio(devicePixelRatio);
  ^
org-dartlang-sdk:///lib/_engine/engine/test_embedding.dart:22:3: Error: Can't use 'window' because it is declared more than once.
  window.webOnlyDebugPhysicalSizeOverride =
  ^
org-dartlang-sdk:///lib/_engine/engine/text/measurement.dart:34:5: Error: Can't use 'registerHotRestartListener' because it is declared more than once.
    registerHotRestartListener(dispose);
    ^
org-dartlang-sdk:///lib/_engine/engine/view_embedder/dimensions_provider/dimensions_provider.dart:34:12: Error: Can't use 'window' because it is declared more than once.
    return window.devicePixelRatio;
           ^
org-dartlang-sdk:///lib/_engine/engine/window.dart:42:7: Error: Can't use 'renderer' because it is declared more than once.
      renderer.clearFragmentProgramCache();
      ^
org-dartlang-sdk:///lib/_engine/engine/window.dart:40:5: Error: Can't use 'registerHotRestartListener' because it is declared more than once.
    registerHotRestartListener(() {
    ^

[3673/7108] CXX obj/third_party/harfbuzz/src/harfbuzz_sources.hb-subset.o
ninja: build stopped: subcommand failed.
description: Sub-process failed.executable: autoninja arguments: [-C, /usr/local/google/home/dit/github/engine/src/out/host_debug_unopt] exit code: 1
```

</details>

After some bisecting, it turns out that my last `dart format` run had modified [this line](https://github.com/flutter/engine/blob/6e91204d9d94a743d6e56d73e17154968baa6325/lib/web_ui/lib/src/engine/embedder.dart#L9):

```dart
import '../engine.dart' show buildMode, registerHotRestartListener, renderer, window;
```

Into this:

```dart
import '../engine.dart'
    show buildMode, registerHotRestartListener, renderer, window;
```

**Is this a [`sdk_rewriter`](https://github.com/flutter/engine/blob/main/web_sdk/sdk_rewriter.dart) bug?**