start static method
- String entrypoint,
- String outputDillPath,
- String platformKernel, {
- String dartdevcModuleFormat = 'amd',
- bool debug = false,
- List<
String> ? enabledExperiments, - bool enableHttpUris = false,
- List<
String> fileSystemRoots = const [], - String fileSystemScheme = 'org-dartlang-root',
- String? frontendServerPath,
- String packagesJson = '.dart_tool/package_config.json',
- String? sdkRoot,
- String target = 'vm',
- bool verbose = false,
- bool printIncrementalDependencies = true,
- List<
String> additionalSources = const [], - String? nativeAssets,
Starts the frontend server.
Most arguments directly mirror the command line arguments for the
frontend_server (see pkg/frontend_server/lib/frontend_server.dart
in
the sdk). Options are exposed on an as-needed basis.
The entrypoint
and packagesJson
may be a relative path or any uri
supported by the frontend server.
The outputDillPath
determines where the primary output should be, and
some targets may output additional files based on that file name (by
adding file extensions for instance).
When the frontendServerPath
argument is provided, the frontend server
will be started from the specified file. The specified file can either be
a Dart source file or an AppJIT snapshot.
When the frontendServerPath
argument is provided, setting debug
to
true permits debuggers to attach to the frontend server. When the
frontendServerPath
argument is omitted, setting debug
to true will
cause an ArgumentError to be thrown.
Implementation
static Future<FrontendServerClient> start(
String entrypoint,
String outputDillPath,
String platformKernel, {
String dartdevcModuleFormat = 'amd',
bool debug = false,
List<String>? enabledExperiments,
bool enableHttpUris = false,
List<String> fileSystemRoots = const [], // For `fileSystemScheme` uris,
String fileSystemScheme =
'org-dartlang-root', // Custom scheme for virtual `fileSystemRoots`.
String? frontendServerPath, // Defaults to the snapshot in the sdk.
String packagesJson = '.dart_tool/package_config.json',
String? sdkRoot, // Defaults to the current SDK root.
String target = 'vm', // The kernel target type.
bool verbose = false, // Verbose logs, including server/client messages
bool printIncrementalDependencies = true,
List<String> additionalSources = const [],
String? nativeAssets,
}) async {
final commonArguments = <String>[
'--sdk-root',
sdkRoot ?? sdkDir,
'--platform=$platformKernel',
'--target=$target',
if (target == 'dartdevc')
'--dartdevc-module-format=$dartdevcModuleFormat',
for (var root in fileSystemRoots) '--filesystem-root=$root',
'--filesystem-scheme',
fileSystemScheme,
'--output-dill',
outputDillPath,
'--packages=$packagesJson',
if (enableHttpUris) '--enable-http-uris',
'--incremental',
if (verbose) '--verbose',
if (!printIncrementalDependencies) '--no-print-incremental-dependencies',
if (enabledExperiments != null)
for (var experiment in enabledExperiments)
'--enable-experiment=$experiment',
for (var source in additionalSources) ...[
'--source',
source,
],
if (nativeAssets != null) ...[
'--native-assets',
nativeAssets,
],
];
late final Process feServer;
if (frontendServerPath != null) {
feServer = await Process.start(
Platform.resolvedExecutable,
<String>[
if (debug) '--observe',
frontendServerPath,
...commonArguments,
],
);
} else if (File(_feServerAotSnapshotPath).existsSync()) {
if (debug) {
throw ArgumentError('The debug argument cannot be set to true when the '
'frontendServerPath argument is omitted.');
}
feServer = await Process.start(
_dartAotRuntimePath,
<String>[_feServerAotSnapshotPath, ...commonArguments],
);
} else {
// AOT snapshots cannot be generated on IA32, so we need this fallback
// branch until support for IA32 is dropped (https://dartbug.com/49969).
feServer = await Process.start(
Platform.resolvedExecutable,
<String>[
if (debug) '--observe',
_feServerAppJitSnapshotPath,
...commonArguments,
],
);
}
var feServerStdoutLines = StreamQueue(feServer.stdout
.transform(utf8.decoder)
.transform(const LineSplitter()));
// The frontend_server doesn't appear to recursively create files, so we
// need to make sure the output dir already exists.
var outputDir = Directory(p.dirname(outputDillPath));
if (!await outputDir.exists()) await outputDir.create();
return FrontendServerClient._(
entrypoint,
feServer,
feServerStdoutLines,
verbose: verbose,
);
}