From a8e923191554fe0669c59ebcf7401714548f1db5 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Thu, 18 Jan 2018 16:05:19 -0800 Subject: [PATCH] Accommodate `flutter test --preview-dart-2` on windows and linux (flutter/engine#4564) * Support .packages option in frontend_server, bundle_path in main_mac. This is needed to be able to run in mode. * Remove byte store tests * Remove unused import * Fix formatting * Enable flutter test argument passing on win and linux. * Fix formatting --- .../flutter/frontend_server/lib/server.dart | 15 ++++------ .../frontend_server/test/server_test.dart | 29 +------------------ .../shell/platform/darwin/desktop/main_mac.mm | 21 ++++++++++++-- .../shell/platform/linux/main_linux.cc | 8 ++++- .../flutter/shell/platform/win/main_win.cc | 8 +++++ 5 files changed, 40 insertions(+), 41 deletions(-) diff --git a/engine/src/flutter/frontend_server/lib/server.dart b/engine/src/flutter/frontend_server/lib/server.dart index 81b8be9b30..b24a31ddce 100644 --- a/engine/src/flutter/frontend_server/lib/server.dart +++ b/engine/src/flutter/frontend_server/lib/server.dart @@ -11,7 +11,6 @@ import 'package:args/args.dart'; // that would replace api used below. This api was made private in // an effort to discourage further use. // ignore_for_file: implementation_imports -import 'package:front_end/src/api_prototype/byte_store.dart'; import 'package:front_end/src/api_prototype/compiler_options.dart'; import 'package:front_end/src/api_prototype/incremental_kernel_generator.dart'; @@ -32,10 +31,6 @@ ArgParser _argParser = new ArgParser(allowTrailingOptions: true) ..addOption('sdk-root', help: 'Path to sdk root', defaultsTo: '../../out/android_debug/flutter_patched_sdk') - ..addOption('byte-store', - help: 'Path to file byte store used to keep incremental compiler state.' - ' If omitted, then memory byte store is used.', - defaultsTo: null) ..addFlag('aot', help: 'Run compiler in AOT mode (enables whole-program transformations)', defaultsTo: false) @@ -48,7 +43,10 @@ ArgParser _argParser = new ArgParser(allowTrailingOptions: true) ' Intended use is to satisfy different loading strategies implemented' ' by gen_snapshot(which needs platform embedded) vs' ' Flutter engine(which does not)', - defaultsTo: true); + defaultsTo: true) + ..addOption('packages', + help: '.packages file to use for compilation', + defaultsTo: '.packages'); String _usage = ''' Usage: server [options] [input.dart] @@ -147,12 +145,9 @@ class _FrontendCompiler implements CompilerInterface { final String boundaryKey = new Uuid().generateV4(); _outputStream.writeln('result $boundaryKey'); final Uri sdkRoot = _ensureFolderPath(options['sdk-root']); - final String byteStorePath = options['byte-store']; final CompilerOptions compilerOptions = new CompilerOptions() - ..byteStore = byteStorePath != null - ? new FileByteStore(byteStorePath) - : new MemoryByteStore() ..sdkRoot = sdkRoot + ..packagesFileUri = options['packages'] != null ? Uri.base.resolveUri(new Uri.file(options['packages'])) : null ..strongMode = options['strong'] ..target = new FlutterTarget(new TargetFlags(strongMode: options['strong'])) ..reportMessages = true; diff --git a/engine/src/flutter/frontend_server/test/server_test.dart b/engine/src/flutter/frontend_server/test/server_test.dart index 9f77525db6..a473f2b3fd 100644 --- a/engine/src/flutter/frontend_server/test/server_test.dart +++ b/engine/src/flutter/frontend_server/test/server_test.dart @@ -78,29 +78,6 @@ Future main() async { expect(capturedArgs.single['strong'], equals(true)); }); - test('compile from command line with file byte store', () async { - final List args = [ - 'server.dart', - '--sdk-root', - 'sdkroot', - '--byte-store', - 'path/to/bytestore' - ]; - final int exitcode = await starter(args, compiler: compiler); - expect(exitcode, equals(0)); - final List capturedArgs = - verify( - compiler.compile( - argThat(equals('server.dart')), - captureAny, - generator: any, - ) - ).captured; - expect(capturedArgs.single['sdk-root'], equals('sdkroot')); - expect(capturedArgs.single['byte-store'], equals('path/to/bytestore')); - expect(capturedArgs.single['strong'], equals(false)); - }); - test('compile from command line with link platform', () async { final List args = [ 'server.dart', @@ -124,14 +101,12 @@ Future main() async { }); }); - group('interactive file store compile with mocked compiler', () { + group('interactive compile with mocked compiler', () { final CompilerInterface compiler = new _MockedCompiler(); final List args = [ '--sdk-root', 'sdkroot', - '--byte-store', - 'path/to/bytestore', ]; test('compile one file', () async { @@ -143,8 +118,6 @@ Future main() async { expect(invocation.positionalArguments[0], equals('server.dart')); expect(invocation.positionalArguments[1]['sdk-root'], equals('sdkroot')); - expect(invocation.positionalArguments[1]['byte-store'], - equals('path/to/bytestore')); expect(invocation.positionalArguments[1]['strong'], equals(false)); compileCalled.sendPort.send(true); } diff --git a/engine/src/flutter/shell/platform/darwin/desktop/main_mac.mm b/engine/src/flutter/shell/platform/darwin/desktop/main_mac.mm index c8fd14326a..8087d0e92c 100644 --- a/engine/src/flutter/shell/platform/darwin/desktop/main_mac.mm +++ b/engine/src/flutter/shell/platform/darwin/desktop/main_mac.mm @@ -12,13 +12,30 @@ #include "flutter/shell/platform/darwin/common/platform_mac.h" #include "flutter/shell/platform/darwin/desktop/flutter_application.h" #include "flutter/shell/testing/testing.h" +#include "lib/fxl/command_line.h" +#include "lib/fxl/logging.h" + +static fxl::CommandLine InitializedCommandLine() { + std::vector args_vector; + + for (NSString* arg in [NSProcessInfo processInfo].arguments) { + args_vector.emplace_back(arg.UTF8String); + } + + return fxl::CommandLineFromIterators(args_vector.begin(), args_vector.end()); +} int main(int argc, const char* argv[]) { [FlutterApplication sharedApplication]; - shell::PlatformMacMain("", "", ""); + // Can't use shell::Shell::Shared().GetCommandLine() because it is initialized only + // in shell::PlatformMacMain call below. + auto command_line = InitializedCommandLine(); - const auto& command_line = shell::Shell::Shared().GetCommandLine(); + std::string bundle_path = ""; + command_line.GetOptionValue(FlagForSwitch(shell::Switch::FlutterAssetsDir), &bundle_path); + + shell::PlatformMacMain("", "", bundle_path); // Print help. if (command_line.HasOption(shell::FlagForSwitch(shell::Switch::Help))) { diff --git a/engine/src/flutter/shell/platform/linux/main_linux.cc b/engine/src/flutter/shell/platform/linux/main_linux.cc index dba837bf70..a20d425ed1 100644 --- a/engine/src/flutter/shell/platform/linux/main_linux.cc +++ b/engine/src/flutter/shell/platform/linux/main_linux.cc @@ -77,7 +77,13 @@ void RunNonInteractive(fxl::CommandLine initial_command_line, // one time initialization. fml::MessageLoop::EnsureInitializedForCurrentThread(); - shell::Shell::InitStandalone(initial_command_line); + std::string bundle_path = ""; + initial_command_line.GetOptionValue( + FlagForSwitch(shell::Switch::FlutterAssetsDir), &bundle_path); + + shell::Shell::InitStandalone(initial_command_line, + /* icu_data_path= */ "", + /* application_library_path= */ "", bundle_path); // Note that this task observer must be added after the observer that drains // the microtask queue. diff --git a/engine/src/flutter/shell/platform/win/main_win.cc b/engine/src/flutter/shell/platform/win/main_win.cc index d555ecde95..e6fb8e9efb 100644 --- a/engine/src/flutter/shell/platform/win/main_win.cc +++ b/engine/src/flutter/shell/platform/win/main_win.cc @@ -78,6 +78,14 @@ void RunNonInteractive(fxl::CommandLine initial_command_line, // one time initialization. fml::MessageLoop::EnsureInitializedForCurrentThread(); + std::string bundle_path = ""; + initial_command_line.GetOptionValue( + FlagForSwitch(shell::Switch::FlutterAssetsDir), &bundle_path); + + shell::Shell::InitStandalone(initial_command_line, + /* icu_data_path= */ "", + /* application_library_path= */ "", bundle_path); + shell::Shell::InitStandalone(initial_command_line); // Note that this task observer must be added after the observer that drains