From 11cac67ff951fe5c5fa0a9ea1497846cbfa99bca Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Thu, 12 Oct 2017 10:11:47 -0700 Subject: [PATCH] Add an option to link platform.dill into app kernel file (#4204) --- frontend_server/lib/server.dart | 21 +++++++++++++++------ frontend_server/test/server_test.dart | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/frontend_server/lib/server.dart b/frontend_server/lib/server.dart index 29ba2b7d0db72..a5bd5f976134d 100644 --- a/frontend_server/lib/server.dart +++ b/frontend_server/lib/server.dart @@ -30,7 +30,14 @@ ArgParser _argParser = new ArgParser(allowTrailingOptions: true) ..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); + defaultsTo: null) + ..addFlag('link-platform', + help: 'When in batch mode, link platform kernel file into result kernel file.' + ' Intended use is to satisfy different loading strategies implemented' + ' by gen_snapshot(which needs platform embedded) vs' + ' Flutter engine(which does not)', + defaultsTo: true); + String _usage = ''' Usage: server [options] [input.dart] @@ -156,11 +163,13 @@ class _FrontendCompiler implements CompilerInterface { final DeltaProgram deltaProgram = await _generator.computeDelta(); program = deltaProgram.newProgram; } else { - // TODO(aam): Remove linkedDependencies once platform is directly embedded - // into VM snapshot and http://dartbug.com/30111 is fixed. - compilerOptions.linkedDependencies = [ - sdkRoot.resolve('platform.dill') - ]; + if (options['link-platform']) { + // TODO(aam): Remove linkedDependencies once platform is directly embedded + // into VM snapshot and http://dartbug.com/30111 is fixed. + compilerOptions.linkedDependencies = [ + sdkRoot.resolve('platform.dill') + ]; + } program = await kernelForProgram(Uri.base.resolve(_filename), compilerOptions); } if (program != null) { diff --git a/frontend_server/test/server_test.dart b/frontend_server/test/server_test.dart index 334f58dd80656..42a250010eebb 100644 --- a/frontend_server/test/server_test.dart +++ b/frontend_server/test/server_test.dart @@ -69,6 +69,27 @@ Future main() async { expect(capturedArgs.single['sdk-root'], equals('sdkroot')); expect(capturedArgs.single['byte-store'], equals('path/to/bytestore')); }); + + test('compile from command line with link platform', () async { + final List args = [ + 'server.dart', + '--sdk-root', + 'sdkroot', + '--link-platform', + ]; + 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['link-platform'], equals(true)); + }); }); group('interactive file store compile with mocked compiler', () {