cli.dart 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// See: https://github.com/flutter/flutter/wiki/Release-process

import 'dart:io' as io;

import 'package:args/command_runner.dart';
10
import 'package:conductor_core/conductor_core.dart';
11 12 13 14 15
import 'package:file/file.dart';
import 'package:file/local.dart';
import 'package:platform/platform.dart';
import 'package:process/process.dart';

16 17
const String readmeUrl = 'https://github.com/flutter/flutter/tree/master/dev/conductor/README.md';

18
Future<void> main(List<String> args) async {
19 20 21 22 23 24 25 26 27 28
  const FileSystem fileSystem = LocalFileSystem();
  const ProcessManager processManager = LocalProcessManager();
  const Platform platform = LocalPlatform();
  final Stdio stdio = VerboseStdio(
    stdout: io.stdout,
    stderr: io.stderr,
    stdin: io.stdin,
  );
  final Checkouts checkouts = Checkouts(
    fileSystem: fileSystem,
29
    parentDirectory: _localFlutterRoot.parent,
30 31
    platform: platform,
    processManager: processManager,
32
    stdio: stdio,
33
  );
34

35 36
  final CommandRunner<void> runner = CommandRunner<void>(
    'conductor',
37 38
    'A tool for coordinating Flutter releases. For more documentation on '
    'usage, please see $readmeUrl.',
39 40 41
    usageLineLength: 80,
  );

42 43 44 45 46 47
  final String conductorVersion = (await const Git(processManager).getOutput(
    <String>['rev-parse'],
    'Get the revision of the current Flutter SDK',
    workingDirectory: _localFlutterRoot.path,
  )).trim();

48
  <Command<void>>[
49 50 51 52 53
    StatusCommand(
      checkouts: checkouts,
    ),
    StartCommand(
      checkouts: checkouts,
54
      conductorVersion: conductorVersion,
55 56 57 58
    ),
    CleanCommand(
      checkouts: checkouts,
    ),
59 60
    CandidatesCommand(
      checkouts: checkouts,
61
      flutterRoot: _localFlutterRoot,
62
    ),
63 64 65
    NextCommand(
      checkouts: checkouts,
    ),
66 67 68 69 70 71 72 73
  ].forEach(runner.addCommand);

  if (!assertsEnabled()) {
    stdio.printError('The conductor tool must be run with --enable-asserts.');
    io.exit(1);
  }

  try {
74
    await runner.run(args);
75 76
  } on Exception catch (e, stacktrace) {
    stdio.printError('$e\n\n$stacktrace');
77 78 79
    io.exit(1);
  }
}
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

Directory get _localFlutterRoot {
  String filePath;
  const FileSystem fileSystem = LocalFileSystem();
  const Platform platform = LocalPlatform();

  filePath = platform.script.toFilePath();
  final String checkoutsDirname = fileSystem.path.normalize(
    fileSystem.path.join(
      fileSystem.path.dirname(filePath), // flutter/dev/conductor/core/bin
      '..', // flutter/dev/conductor/core
      '..', // flutter/dev/conductor
      '..', // flutter/dev
      '..', // flutter
    ),
  );
  return fileSystem.directory(checkoutsDirname);
}