Skip to content

Commit

Permalink
Add an option to specify file byte store location (flutter#4201)
Browse files Browse the repository at this point in the history
  • Loading branch information
aam authored Oct 12, 2017
1 parent a55aa23 commit f737d49
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
11 changes: 9 additions & 2 deletions frontend_server/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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())
Expand Down
57 changes: 57 additions & 0 deletions frontend_server/test/server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down

0 comments on commit f737d49

Please sign in to comment.