start static method

Future<FrontendServerClient> start(
  1. String entrypoint,
  2. String outputDillPath,
  3. String platformKernel, {
  4. String dartdevcModuleFormat = 'amd',
  5. bool debug = false,
  6. List<String>? enabledExperiments,
  7. bool enableHttpUris = false,
  8. List<String> fileSystemRoots = const [],
  9. String fileSystemScheme = 'org-dartlang-root',
  10. String? frontendServerPath,
  11. String packagesJson = '.dart_tool/package_config.json',
  12. String? sdkRoot,
  13. String target = 'vm',
  14. bool verbose = false,
  15. bool printIncrementalDependencies = true,
  16. List<String> additionalSources = const [],
  17. 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,
  );
}