upgrade.dart 3.17 KB
Newer Older
1 2 3 4 5
// Copyright 2015 The Chromium Authors. 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';
6

7 8
import 'package:meta/meta.dart';

9
import '../base/common.dart';
10
import '../base/file_system.dart';
11
import '../base/os.dart';
12
import '../base/process.dart';
13
import '../cache.dart';
Devon Carew's avatar
Devon Carew committed
14
import '../dart/pub.dart';
15
import '../globals.dart';
16
import '../runner/flutter_command.dart';
17
import '../version.dart';
18
import 'channel.dart';
19 20

class UpgradeCommand extends FlutterCommand {
21
  @override
22
  final String name = 'upgrade';
23 24

  @override
25 26
  final String description = 'Upgrade your copy of Flutter.';

27 28 29
  @override
  bool get shouldUpdateCache => false;

30
  @override
31
  Future<Null> runCommand() async {
32
    try {
33
      await runCheckedAsync(<String>[
34
        'git', 'rev-parse', '@{u}'
35
      ], workingDirectory: Cache.flutterRoot);
36
    } catch (e) {
37
      throwToolExit('Unable to upgrade Flutter: no upstream repository configured.');
38 39
    }

40
    final FlutterVersion flutterVersion = FlutterVersion.instance;
41

42
    printStatus('Upgrading Flutter from ${Cache.flutterRoot}...');
43

44 45
    await ChannelCommand.upgradeChannel();

46 47
    int code = await runCommandAndStreamOutput(
      <String>['git', 'pull', '--ff-only'],
48
      workingDirectory: Cache.flutterRoot,
49 50
      mapFunction: (String line) => matchesGitLine(line) ? null : line
    );
51 52

    if (code != 0)
53
      throwToolExit(null, exitCode: code);
54

55
    // Check for and download any engine and pkg/ updates.
56 57 58
    // We run the 'flutter' shell script re-entrantly here
    // so that it will download the updated Dart and so forth
    // if necessary.
Devon Carew's avatar
Devon Carew committed
59
    printStatus('');
60
    printStatus('Upgrading engine...');
61 62
    code = await runCommandAndStreamOutput(
      <String>[
63
        fs.path.join('bin', 'flutter'), '--no-color', '--no-version-check', 'precache',
64 65 66 67
      ],
      workingDirectory: Cache.flutterRoot,
      allowReentrantFlutter: true
    );
68

69
    printStatus('');
70
    printStatus(flutterVersion.toString());
71

72 73
    final String projectRoot = findProjectRoot();
    if (projectRoot != null) {
Devon Carew's avatar
Devon Carew committed
74
      printStatus('');
75
      await pubGet(context: PubContext.pubUpgrade, directory: projectRoot, upgrade: true, checkLastModified: false);
Devon Carew's avatar
Devon Carew committed
76
    }
77

78 79 80
    // Run a doctor check in case system requirements have changed.
    printStatus('');
    printStatus('Running flutter doctor...');
81 82
    code = await runCommandAndStreamOutput(
      <String>[
83
        fs.path.join('bin', 'flutter'), '--no-version-check', 'doctor',
84 85 86 87
      ],
      workingDirectory: Cache.flutterRoot,
      allowReentrantFlutter: true,
    );
88
  }
89 90 91 92 93 94

  //  dev/benchmarks/complex_layout/lib/main.dart        |  24 +-
  static final RegExp _gitDiffRegex = new RegExp(r' (\S+)\s+\|\s+\d+ [+-]+');

  //  rename {packages/flutter/doc => dev/docs}/styles.html (92%)
  //  delete mode 100644 doc/index.html
95
  //  create mode 100644 examples/flutter_gallery/lib/gallery/demo.dart
96 97
  static final RegExp _gitChangedRegex = new RegExp(r' (rename|delete mode|create mode) .+');

98
  @visibleForTesting
99 100 101 102 103
  static bool matchesGitLine(String line) {
    return _gitDiffRegex.hasMatch(line)
      || _gitChangedRegex.hasMatch(line)
      || line == 'Fast-forward';
  }
104
}