Add an option to specify file byte store location (flutter/engine#4201)

This commit is contained in:
Alexander Aprelev 2017-10-11 17:33:22 -07:00 committed by GitHub
parent eac6438ce8
commit cf981ae074
2 changed files with 66 additions and 2 deletions

View File

@ -26,7 +26,11 @@ ArgParser _argParser = new ArgParser(allowTrailingOptions: true)
help: 'Run compiler in incremental mode', defaultsTo: false)
..addOption('sdk-root',
help: 'Path to sdk root',
defaultsTo: '../../out/android_debug/flutter_patched_sdk');
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);
String _usage = '''
Usage: server [options] [input.dart]
@ -120,8 +124,11 @@ 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 = new MemoryByteStore()
..byteStore = byteStorePath != null
? new FileByteStore(byteStorePath)
: new MemoryByteStore()
..sdkRoot = sdkRoot
..strongMode = false
..target = new FlutterTarget(new TargetFlags())

View File

@ -47,6 +47,63 @@ Future<int> main() async {
).captured;
expect(capturedArgs.single['sdk-root'], equals('sdkroot'));
});
test('compile from command line with file byte store', () async {
final List<String> args = <String>[
'server.dart',
'--sdk-root',
'sdkroot',
'--byte-store',
'path/to/bytestore'
];
final int exitcode = await starter(args, compiler: compiler);
expect(exitcode, equals(0));
final List<ArgResults> 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'));
});
});
group('interactive file store compile with mocked compiler', () {
final CompilerInterface compiler = new _MockedCompiler();
final List<String> args = <String>[
'--sdk-root',
'sdkroot',
'--byte-store',
'path/to/bytestore',
];
test('compile one file', () async {
final StreamController<List<int>> inputStreamController =
new StreamController<List<int>>();
final ReceivePort compileCalled = new ReceivePort();
when(compiler.compile(any, any, generator: any)).thenAnswer(
(Invocation invocation) {
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'));
compileCalled.sendPort.send(true);
}
);
final int exitcode = await starter(args, compiler: compiler,
input: inputStreamController.stream,
);
expect(exitcode, equals(0));
inputStreamController.add('compile server.dart\n'.codeUnits);
await compileCalled.first;
inputStreamController.close();
});
});
group('interactive compile with mocked compiler', () {