From 24e60804faad6840f5ef50f8ea652dd6e67c7705 Mon Sep 17 00:00:00 2001 From: Yegor Date: Wed, 25 Sep 2019 13:51:00 -0700 Subject: [PATCH] [web] filter test targets; cache host.dart compilation (flutter/engine#12445) * filter test targets; cache host.dart compilation --- .../flutter/lib/web_ui/dev/environment.dart | 2 +- .../flutter/lib/web_ui/dev/test_runner.dart | 47 +++++++++++++++---- engine/src/flutter/lib/web_ui/pubspec.yaml | 2 +- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/dev/environment.dart b/engine/src/flutter/lib/web_ui/dev/environment.dart index c6c08542324..4cc3d300a2f 100644 --- a/engine/src/flutter/lib/web_ui/dev/environment.dart +++ b/engine/src/flutter/lib/web_ui/dev/environment.dart @@ -85,7 +85,7 @@ class Environment { )); /// Path to the "web_engine_tester" package. - io.Directory get goldenTesterRootDir => io.Directory(pathlib.join( + io.Directory get webEngineTesterRootDir => io.Directory(pathlib.join( webSdkRootDir.path, 'web_engine_tester', )); diff --git a/engine/src/flutter/lib/web_ui/dev/test_runner.dart b/engine/src/flutter/lib/web_ui/dev/test_runner.dart index 8a4fddc72ca..1dc88669b74 100644 --- a/engine/src/flutter/lib/web_ui/dev/test_runner.dart +++ b/engine/src/flutter/lib/web_ui/dev/test_runner.dart @@ -49,10 +49,10 @@ class TestsCommand extends Command { _copyAhemFontIntoWebUi(); await _buildHostPage(); - await _buildTests(); final List targets = this.targets.map((t) => FilePath.fromCwd(t)).toList(); + await _buildTests(targets: targets); if (targets.isEmpty) { await _runAllTests(); } else { @@ -143,27 +143,52 @@ class TestsCommand extends Command { } } - // TODO(yjbanov): skip rebuild if host.dart hasn't changed. Future _buildHostPage() async { + final String hostDartPath = path.join('lib', 'static', 'host.dart'); + final io.File hostDartFile = io.File(path.join( + environment.webEngineTesterRootDir.path, + hostDartPath, + )); + final io.File timestampFile = io.File(path.join( + environment.webEngineTesterRootDir.path, + '$hostDartPath.js.timestamp', + )); + + final String timestamp = hostDartFile.statSync().modified.millisecondsSinceEpoch.toString(); + if (timestampFile.existsSync()) { + final String lastBuildTimestamp = timestampFile.readAsStringSync(); + if (lastBuildTimestamp == timestamp) { + // The file is still fresh. No need to rebuild. + return; + } else { + // Record new timestamp, but don't return. We need to rebuild. + print('${hostDartFile.path} timestamp changed. Rebuilding.'); + } + } else { + print('Building ${hostDartFile.path}.'); + } + final int exitCode = await runProcess( environment.dart2jsExecutable, [ - 'lib/static/host.dart', + hostDartPath, '-o', - 'lib/static/host.dart.js', + '$hostDartPath.js', ], - workingDirectory: environment.goldenTesterRootDir.path, + workingDirectory: environment.webEngineTesterRootDir.path, ); if (exitCode != 0) { io.stderr.writeln( - 'Failed to compile tests. Compiler exited with exit code $exitCode'); + 'Failed to compile ${hostDartFile.path}. Compiler exited with exit code $exitCode'); io.exit(1); } + + // Record the timestamp to avoid rebuilding unless the file changes. + timestampFile.writeAsStringSync(timestamp); } - Future _buildTests() async { - // TODO(yjbanov): learn to build only requested tests: https://github.com/flutter/flutter/issues/37810 + Future _buildTests({ List targets }) async { final int exitCode = await runProcess( environment.pubExecutable, [ @@ -173,6 +198,12 @@ class TestsCommand extends Command { 'test', '-o', 'build', + if (targets != null) + for (FilePath path in targets) + ...[ + '--build-filter=${path.relativeToWebUi}.js', + '--build-filter=${path.relativeToWebUi}.browser_test.dart.js', + ], ], workingDirectory: environment.webUiRootDir.path, ); diff --git a/engine/src/flutter/lib/web_ui/pubspec.yaml b/engine/src/flutter/lib/web_ui/pubspec.yaml index 60deee67e8d..15c6e879055 100644 --- a/engine/src/flutter/lib/web_ui/pubspec.yaml +++ b/engine/src/flutter/lib/web_ui/pubspec.yaml @@ -13,7 +13,7 @@ dev_dependencies: path: 1.6.4 test: 1.6.5 quiver: 2.0.5 - build_runner: 1.6.5 + build_runner: 1.7.0 build_test: 0.10.8 build_web_compilers: 2.1.5 yaml: 2.2.0