81af7ebbf4
This CL adds a `--native-assets-only` CLI option to the frontend_server startup for single shot compilation. This CL adds a `native-assets-only` instruction to the frontend_server protocol. TEST=pkg/frontend_server/test/native_assets_test.dart Unit test producing kernel file. Closes: https://github.com/dart-lang/sdk/issues/55503 Change-Id: Ice6281162460032e669d2dda2a128b357e81bc50 Cq-Include-Trybots: dart/try:pkg-linux-debug-try,pkg-linux-release-arm64-try,pkg-mac-release-try,pkg-mac-release-arm64-try,pkg-win-release-try,pkg-win-release-arm64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363567 Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
124 lines
4.0 KiB
Dart
124 lines
4.0 KiB
Dart
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:async';
|
|
import 'dart:io' show Directory, File, InternetAddress, Socket, stdin;
|
|
|
|
import 'package:args/args.dart';
|
|
import 'package:path/path.dart' as path;
|
|
import 'package:vm/incremental_compiler.dart' show IncrementalCompiler;
|
|
|
|
import 'frontend_server.dart';
|
|
import 'src/binary_protocol.dart';
|
|
import 'src/resident_frontend_server.dart';
|
|
|
|
/// Entry point for this module, that creates either a `_FrontendCompiler`
|
|
/// instance or a `ResidentFrontendServer` instance and
|
|
/// processes user input.
|
|
/// `compiler` is an optional parameter so it can be replaced with mocked
|
|
/// version for testing.
|
|
Future<int> starter(
|
|
List<String> args, {
|
|
CompilerInterface? compiler,
|
|
Stream<List<int>>? input,
|
|
StringSink? output,
|
|
IncrementalCompiler? generator,
|
|
BinaryPrinterFactory? binaryPrinterFactory,
|
|
}) async {
|
|
ArgResults options;
|
|
try {
|
|
options = argParser.parse(args);
|
|
} catch (error) {
|
|
print('ERROR: $error\n');
|
|
print(usage);
|
|
return 1;
|
|
}
|
|
if (options['resident-info-file-name'] != null) {
|
|
StreamSubscription<Socket>? serverSubscription =
|
|
await residentListenAndCompile(InternetAddress.loopbackIPv4, 0,
|
|
new File(options['resident-info-file-name']));
|
|
return serverSubscription == null ? 1 : 0;
|
|
}
|
|
|
|
if (options['train']) {
|
|
if (options.rest.isEmpty) {
|
|
throw new Exception('Must specify input.dart');
|
|
}
|
|
|
|
final String input = options.rest[0];
|
|
final String sdkRoot = options['sdk-root'];
|
|
final String? platform = options['platform'];
|
|
final Directory temp =
|
|
Directory.systemTemp.createTempSync('train_frontend_server');
|
|
try {
|
|
final String outputTrainingDill = path.join(temp.path, 'app.dill');
|
|
final List<String> args = <String>[
|
|
'--incremental',
|
|
'--sdk-root=$sdkRoot',
|
|
'--output-dill=$outputTrainingDill',
|
|
];
|
|
if (platform != null) {
|
|
args.add('--platform=${new Uri.file(platform)}');
|
|
}
|
|
options = argParser.parse(args);
|
|
compiler ??=
|
|
new FrontendCompiler(output, printerFactory: binaryPrinterFactory);
|
|
|
|
await compiler.compile(input, options, generator: generator);
|
|
compiler.acceptLastDelta();
|
|
await compiler.recompileDelta();
|
|
compiler.acceptLastDelta();
|
|
compiler.resetIncrementalCompiler();
|
|
await compiler.recompileDelta();
|
|
compiler.acceptLastDelta();
|
|
await compiler.recompileDelta();
|
|
compiler.acceptLastDelta();
|
|
return 0;
|
|
} finally {
|
|
temp.deleteSync(recursive: true);
|
|
}
|
|
}
|
|
|
|
final String? binaryProtocolAddressStr = options['binary-protocol-address'];
|
|
if (binaryProtocolAddressStr != null) {
|
|
await runBinaryProtocol(binaryProtocolAddressStr);
|
|
return 0;
|
|
}
|
|
|
|
compiler ??= new FrontendCompiler(
|
|
output,
|
|
printerFactory: binaryPrinterFactory,
|
|
unsafePackageSerialization: options["unsafe-package-serialization"],
|
|
incrementalSerialization: options["incremental-serialization"],
|
|
useDebuggerModuleNames: options['debugger-module-names'],
|
|
emitDebugMetadata: options['experimental-emit-debug-metadata'],
|
|
emitDebugSymbols: options['emit-debug-symbols'],
|
|
canaryFeatures: options['dartdevc-canary'],
|
|
);
|
|
|
|
if (options['native-assets-only']) {
|
|
final bool compileResult = await compiler.compileNativeAssetsOnly(
|
|
options,
|
|
generator: generator,
|
|
);
|
|
return compileResult ? 0 : 254;
|
|
}
|
|
|
|
if (options.rest.isNotEmpty) {
|
|
return await compiler.compile(options.rest[0], options,
|
|
generator: generator)
|
|
? 0
|
|
: 254;
|
|
}
|
|
|
|
Completer<int> completer = new Completer<int>();
|
|
StreamSubscription<String> subscription = listenAndCompile(
|
|
compiler, input ?? stdin, options, completer,
|
|
generator: generator);
|
|
return completer.future.then((value) {
|
|
subscription.cancel();
|
|
return value;
|
|
});
|
|
}
|