run method

Future<ProjectOperationOutcome> run(
  1. ProjectOperationKind kind, {
  2. Directory? candidate,
  3. Map<String, String> extraEnvironment = const <String, String>{},
})

Runs the declared operation of kind.

candidate is the staged tree under verification; it is the target of a ProjectDirectoryKind.candidate working directory. The command is never assembled into a command string: the executable and its arguments reach the process spawn exactly as declared, so an argument containing spaces stays one argument.

Implementation

Future<ProjectOperationOutcome> run(
  ProjectOperationKind kind, {
  Directory? candidate,
  Map<String, String> extraEnvironment = const <String, String>{},
}) async {
  final operation = profile.operation(kind);
  if (operation == null) {
    return ProjectOperationOutcome(
      ok: false,
      kind: kind,
      operationId: kind.name,
      argv: const <String>[],
      workingDirectory: workspace.path,
      duration: Duration.zero,
      error: 'project_operation_unavailable',
      detail:
          'the profile "${profile.id}" declares no ${kind.name} operation',
    );
  }
  final Directory directory;
  try {
    directory = resolveDirectory(
      operation.command.workingDirectory,
      candidate,
    );
  } on FormatException catch (error) {
    return ProjectOperationOutcome(
      ok: false,
      kind: kind,
      operationId: operation.id,
      argv: operation.command.argv,
      workingDirectory: workspace.path,
      duration: Duration.zero,
      error: 'project_operation_directory_unavailable',
      detail: error.message,
    );
  }
  try {
    _referenceExternalPackageRoots(directory, candidate);
  } on FileSystemException catch (error) {
    return ProjectOperationOutcome(
      ok: false,
      kind: kind,
      operationId: operation.id,
      argv: operation.command.argv,
      workingDirectory: directory.path,
      duration: Duration.zero,
      error: 'project_operation_dependency_reference_refused',
      detail: error.message,
    );
  }
  final overrides = <String, String>{
    ...environment,
    ...operation.command.environment,
    ...extraEnvironment,
  };
  final cancellation = _activeCancellation = ProcessRunCancellation();
  late final BoundedRunResult result;
  try {
    result = await _runner(
      operation.command.executable,
      operation.command.arguments,
      timeout: operation.timeout ?? operation.command.timeout,
      workingDirectory: directory.path,
      environment: overrides.isEmpty ? null : overrides,
      cancellation: cancellation,
    );
  } finally {
    _activeCancellation = null;
  }
  return _outcomeOf(operation, result, directory);
}