Skip to content

Commit

Permalink
[WIP] Changes to build fuchsia integration_flutter_test/embedder
Browse files Browse the repository at this point in the history
This is a work in progress, with changes that successfully
compile the embedder test.

This commit leverages new build rules, added in PR flutter#27996,
that enable building flutter tests as Fuchsia components, and
dependencies on Dart libraries from the Fuchsia SDK (Fuchsia Dart APIs
and Dart FIDL bindings).

Notable:

* Adds dart third_party library "quiver" version 2.1.5 to support a
  dependency from a Fuchsia Dart library required by the integration
  test.
* Leverages the recent addition of TestWithEnvironment to the Fuchsia
  SDK, and blends this class with Googletest's (gtest) `testing::Test`,
  from Flutter's pre-existing gtest (third_party dependency).
  • Loading branch information
richkadel committed Sep 24, 2021
1 parent b67fa6d commit dc99d4f
Show file tree
Hide file tree
Showing 28 changed files with 2,018 additions and 0 deletions.
3 changes: 3 additions & 0 deletions DEPS
Expand Up @@ -444,6 +444,9 @@ deps = {
'src/third_party/pkg/process_runner':
Var('github_git') + '/google/process_runner.git' + '@' + 'd632ea0bfd814d779fcc53a361ed33eaf3620a0b', # 4.0.1

'src/third_party/pkg/quiver':
Var('github_git') + '/google/quiver-dart.git' + '@' + '66f473cca1332496e34a783ba4527b04388fd561', # 2.1.5

'src/third_party/pkg/vector_math':
Var('github_git') + '/google/vector_math.dart.git' + '@' + 'v2.1.0',

Expand Down
1 change: 1 addition & 0 deletions shell/platform/fuchsia/flutter/BUILD.gn
Expand Up @@ -813,5 +813,6 @@ group("tests") {
":testing_tests",
":txt_tests",
":ui_tests",
"integration_flutter_tests",
]
}
@@ -0,0 +1,9 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

group("integration_flutter_tests") {
testonly = true

deps = [ "embedder:tests" ]
}
@@ -0,0 +1,5 @@
dworsham@google.com
sanjayc@google.com
richkadel@google.com

# COMPONENT: FlutteronFuchsia
@@ -0,0 +1,73 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

assert(is_fuchsia)

import("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/fuchsia_archive.gni")

group("tests") {
testonly = true
deps = [
":flutter_scenic_embedder_test",
"//flutter/shell/platform/fuchsia/flutter/integration_flutter_tests/embedder/child-view",
"//flutter/shell/platform/fuchsia/flutter/integration_flutter_tests/embedder/parent-view",
]
}

executable("flutter_scenic_embedder_test_bin") {
testonly = true

output_name = "flutter_scenic_embedder_test"

sources = [
"flutter-scenic-embedder-test.cc",
"flutter-scenic-embedder-test.h",
]

# This is needed for //third_party/googletest for linking zircon symbols.
libs = [ "$fuchsia_sdk_path/arch/$target_cpu/sysroot/lib/libzircon.so" ]

include_dirs = [ "//flutter/shell/platform/fuchsia/flutter/integration_flutter_tests/fuchsia_testing" ]

public_deps = [ "//third_party/googletest:gtest" ]

# The use of these dependencies is temporary and will be moved behind the
# embedder API.
flutter_deps = [
"//flutter/lib/ui",
"//third_party/dart/runtime:libdart_jit",
"//third_party/dart/runtime/platform:libdart_platform_jit",
]

deps = [
"$fuchsia_sdk_root/fidl:fuchsia.sys",
"$fuchsia_sdk_root/fidl:fuchsia.ui.app",
"$fuchsia_sdk_root/fidl:fuchsia.ui.input",
"$fuchsia_sdk_root/fidl:fuchsia.ui.policy",
"$fuchsia_sdk_root/fidl:fuchsia.ui.scenic",
"$fuchsia_sdk_root/pkg:fit",
"$fuchsia_sdk_root/pkg:sys_cpp",
"$fuchsia_sdk_root/pkg:sys_cpp_testing",
"//flutter/shell/platform/fuchsia/flutter/integration_flutter_tests/fuchsia_testing/src/lib/ui/base_view",
"$fuchsia_sdk_root/pkg:scenic_cpp",
"//third_party/googletest:gtest_main",
"//flutter/shell/platform/fuchsia/flutter/integration_flutter_tests/fuchsia_testing/src/ui/testing/views",
"$fuchsia_sdk_root/pkg:zx",
"$fuchsia_sdk_root/pkg:async-loop-cpp",
"$fuchsia_sdk_root/pkg:async-loop-default",
] + flutter_deps
}

fuchsia_test_archive("flutter_scenic_embedder_test") {
deps = [
":flutter_scenic_embedder_test_bin",
"//flutter/shell/platform/fuchsia/flutter/integration_flutter_tests/embedder/child-view",
"//flutter/shell/platform/fuchsia/flutter/integration_flutter_tests/embedder/parent-view",
]

binary = "$target_name"

cmx_file = rebase_path("meta/$target_name.cmx")
}
@@ -0,0 +1,144 @@
# `flutter scenic embedder tests`

To run the tests:

## Sync your fuchsia.git checkout to your current Fuchsia SDK version

First, sync your Fuchsia checkout and dependencies to match the versions used
to generate the Fuchsia SDK version you are using in the flutter/engine repo.
Typically, you've used `gclient sync` to download the version specified in the
flutter/engine `DEPS` file.

In a web browser, open
https://chrome-infra-packages.appspot.com/p/fuchsia/sdk/core, select your
architecture, click one of the "Instances" to open it's detail page, and then
edit the web URL to replace the selected instance ID with the instance ID you
synched with, from the DEPS file (for the same architecture).

From the new page matching your current instance ID, copy the `jiri_snapshot`
(only the value after the colon) and set a shell variable to this value:

```shell
$ JIRI_SNAPSHOT="<tag>" # for example, 6.20210809.3.1
```

Now, from your `$FUCHSIA_DIR` directory, do the following:

Use `git` to checkout the version of the `$FUCHSIA_DIR/integration` directory
matching your Fuchsia SDK's `$JIRI_SNAPSHOT`.

### Option 1: Checkout the matching tagged revision of Fuchsia, if available

Depending on your fuchsia.git configuration, you may be able to check it out by
tag:

```shell
$ cd "$FUCHSIA_DIR"
$ git -C integration checkout "tags/releases/$JIRI_SNAPSHOT"
```

### Option 2: Use git to find the matching revision of Fuchsia

But if your `$FUCHSIA_DIR/integration` git checkout doesn't have the release
tags, you may be able to find the right version by searching its git log
history:

```shell
$ cd "$FUCHSIA_DIR"
$ git -C integration log --grep="Roll sdk-core packages to version:$JIRI_SNAPSHOT"
commit abcdef1234567890abcdef123456789
Author: global-integration-roller ...
Date: ...

[roll] Roll sdk-core packages to version:6.20210809.4.1
...
```

***IMPORANT: Your search may return more than one result. If so, choose one. Or
you may get no result (perhaps due to a manual roll, or other maintenance
activity). In this case, you may need to modify the `git log` `--grep=` pattern
and drop suffixes from your `$JIRI_SNAPSHOT` version to find a closely related
version. This would not guarantee compatibility, so if you're not a gambler, you
may want to update the SDK instance ID in your local `DEPS` file, and re-run
`gclient sync`, to ensure your installed `$FUCHSIA_SDK` matches the version
returned by `git log`.***

### Update fuchsia.git to match `integration`, and sync all dependencies

```shell
$ cd "$FUCHSIA_DIR"
$ git checkout "$(sed -ne 's/ *revision="\([^"]*\).*/\1/p' $(find integration -name stem) )"
$ fx sync-from-stem # this will be very slow the first time, while it caches git history
```

The `fx sync-from-stem` command uses `jiri` to update all dependencies (other
`git` repos and CIPD prebuilts) to match the current $FUCHSIA_DIR commit (as set
by `git checkout ...` above). These versions should match the versions used when
creating the Fuchsia SDK you are using.

If you are also modifying Fuchsia, you may want to cherry-pick your changes on
top of your current checkout.

## Beware of Dart SDK differences between Flutter and Fuchsia

NOTE: These steps may or may not be necessary, and have not been confirmed
at this point.

To match Fuchsia's version of Dart, you may be able to update your DEPS file to
install a version of the Dart SDK that matches the version used in your
revision-synched `$FUCHSIA_DIR` prebuilts.

```shell
$ cat "$FUCHSIA_DIR/prebuilt/third_party/dart/linux-x64/version"
2.14.0-289.0.dev # for example
```

https://dart.googlesource.com/sdk/+/refs/tags/<the version tag from above>

You may be able to use the `tag` reference hash, to update the Dart SDK
dependency in `DEPS`, use `gclient sync` to download that version, and then
run `create_updated_flutter_deps.py` to update DEPS once more with the correct
versions of other dependencies required by the newly updated version of the
Dart SDK.

```shell
$ cd "$FLUTTER_ENGINE_DIR/src"
$ gclient sync
$ tools/dart/create_updated_flutter_deps.py
$ gclient sync
```

## Build flutter/engine:

```shell
$ cd "$FLUTTER_ENGINE_DIR/src"
$ ./flutter/tools/gn --fuchsia <flags> \
# for example: --goma --fuchsia-cpu=x64 --runtime-mode=release
$ ninja -C out/fuchsia_release_x64
```

## If needed, replace Fuchsia's flutter_runner with your custom built runner

Follow the steps in the Flutter wiki, under
[Compiling for Fuchsia](https://github.com/flutter/flutter/wiki/Compiling-the-engine#compiling-for-fuchsia),
including the subsection titled
[Deploy to Fuchsia](https://github.com/flutter/flutter/wiki/Compiling-the-engine#deploy-to-fuchsia).

## Build and reboot your Fuchsia device, for example:

```shell
$ cd "$FUCHSIA_DIR"
$ # you may want to run `fx clean`, particularly right after `fx sync-from-stem`
$ fx set core.<board> --with //bundles:tests --with-base //topaz/bundles:buildbot
$ fx build
$ fx reboot -r

$ fx pm publish -a -repo "$(cat ~/fuchsia/.fx-build-dir)/amber-files/" \
-f "$FLUTTER_ENGINE_DIR"/src/out/fuchsia_*64/flutter_scenic_embedder_test-0.far

$ fx shell run-test-component \
fuchsia-pkg://fuchsia.com/flutter_scenic_embedder_test#meta/flutter_scenic_embedder_test.cmx
```

The embedder tests must be run on a product without a graphical base shell,
such as `core` because it starts and stops Scenic.
@@ -0,0 +1,20 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/dart/dart_library.gni")
import("//flutter/tools/fuchsia/flutter/flutter_component.gni")

dart_library("lib") {
package_name = "child-view"
sources = [ "main.dart" ]

deps = []
}

flutter_component("child-view") {
manifest = "meta/child_view.cmx"
main_package = "child-view"
deps = [ ":lib" ]
}
@@ -0,0 +1,35 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
// import 'package:flutter/material.dart';

void main(List<String> args) async {
// final app = MaterialApp(home: TestApp(), debugShowCheckedModeBanner: false);
// runApp(app);
}

// See https://medium.com/icnh/flutter-without-flutter-15177c91d066
// Reacting to Touch Event

// class TestApp extends StatelessWidget {
// static const _yellow = Color.fromARGB(255, 255, 255, 0);
// static const _pink = Color.fromARGB(255, 255, 0, 255);

// final _backgroundColor = ValueNotifier(_pink);

// @override
// Widget build(BuildContext context) {
// return Listener(
// onPointerDown: (_) => _backgroundColor.value = _yellow,
// child: AnimatedBuilder(
// animation: _backgroundColor,
// builder: (context, _) {
// return Container(
// color: _backgroundColor.value,
// );
// }),
// );
// }
// }
@@ -0,0 +1,13 @@
{
"program": {
"data": "data/child_view"
},
"sandbox": {
"services": [
"fuchsia.fonts.Provider",
"fuchsia.sys.Environment",
"fuchsia.ui.input.ImeService",
"fuchsia.ui.scenic.Scenic"
]
}
}
@@ -0,0 +1,8 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

name: child_view

environment:
sdk: '>=2.12.0 <3.0.0'

0 comments on commit dc99d4f

Please sign in to comment.