Matan Lurey ed6acfd197 Introduce a GN rule that (explicitly) generates a dart test wrapper (flutter/engine#55475)
Closes https://github.com/flutter/flutter/issues/155769.

This is a variant of the approach in https://github.com/flutter/engine/pull/52241, based on feedback from @jakemac53 and @jonahwilliams (who originally sped up `dart test` significantly by using `frontend_server` under the scenes: https://github.com/dart-lang/test/pull/1399), in short:

```gn
# tools/engine_tool/BUILD.gn

import("//flutter/build/dart/internal/gen_dartcli_call.gni")

gen_dartcli_call("tests") {
  args = [ "test" ]
  cwd = "//flutter/tools/engine_tool"
}
```

This stanza, when built (`ninja -C ../out/host_debug flutter/tools/engine_tool:tests`) generates the following file:

```sh
# ../out/host_debug/gen/flutter/tools/engine_tool/tests

set -e

# Needed because if it is set, cd may print the path it changed to.
unset CDPATH

# Store the current working directory.
prev_cwd=$(pwd)

# Set a trap to restore the working directory.
trap 'cd "$prev_cwd"' EXIT

CD_PATH="/Users/matanl/Developer/engine/src/flutter/tools/engine_tool"
if [ -n "$CD_PATH" ]; then
  cd "$CD_PATH"
fi

/Users/matanl/Developer/engine/src/flutter/prebuilts/macos-arm64/dart-sdk/bin/dart "test"
```

In turn, when executed (`../out/host_debug/gen/flutter/tools/engine_tool/tests`) it just runs `dart test`:

```sh
flutter % ../out/host_debug/gen/flutter/tools/engine_tool/tests
Building package executable... 
Built test:test.
00:00 +0: test/test_command_test.dart: test command executes test                                                                                                                                                                                                          
00:00 +3: test/run_command_test.dart: run command invokes flutter run
...
00:00 +117: All tests passed!
```

There is no actual compilation performed by the tool (that is handled implicitly by `dart test`), and as a result neither a `depfile` is needed, nor generating a pre-compiled artifact like a snapshot or AOT elf/assembly. 

---

This work is incomplete, that is, we'd want to properly tag the executable so `et` can find it, and create a wrapper template (i.e. `dart_test`) that tightens things up a bit, but I wanted to show the work at this intermediate step to get feedback before moving forward.

/cc @jonahwilliams, @jtmcdole as well.
2024-09-30 21:39:36 +00:00
..