upgrade.dart 2.86 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
import '../base/common.dart';
8
import '../base/file_system.dart';
9
import '../base/os.dart';
10
import '../base/process.dart';
11
import '../cache.dart';
Devon Carew's avatar
Devon Carew committed
12
import '../dart/pub.dart';
13
import '../doctor.dart';
14
import '../globals.dart';
15
import '../runner/flutter_command.dart';
16
import '../version.dart';
17 18

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

  @override
23 24
  final String description = 'Upgrade your copy of Flutter.';

25 26 27
  @override
  bool get shouldUpdateCache => false;

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

38
    final FlutterVersion flutterVersion = FlutterVersion.instance;
39

40
    printStatus('Upgrading Flutter from ${Cache.flutterRoot}...');
41

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

    if (code != 0)
49
      throwToolExit(null, exitCode: code);
50

51
    // Check for and download any engine and pkg/ updates.
52 53 54
    // 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
55
    printStatus('');
56
    printStatus('Upgrading engine...');
57 58
    code = await runCommandAndStreamOutput(
      <String>[
59
        fs.path.join(Cache.flutterRoot, 'bin', 'flutter'), '--no-color', 'precache'
60 61 62 63
      ],
      workingDirectory: Cache.flutterRoot,
      allowReentrantFlutter: true
    );
64

65
    printStatus('');
66
    printStatus(flutterVersion.toString());
67

68
    final String projRoot = findProjectRoot();
69
    if (projRoot != null) {
Devon Carew's avatar
Devon Carew committed
70
      printStatus('');
71
      await pubGet(directory: projRoot, upgrade: true, checkLastModified: false);
Devon Carew's avatar
Devon Carew committed
72
    }
73

74 75 76 77
    // Run a doctor check in case system requirements have changed.
    printStatus('');
    printStatus('Running flutter doctor...');
    await doctor.diagnose();
78
  }
79 80 81 82 83 84

  //  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
85
  //  create mode 100644 examples/flutter_gallery/lib/gallery/demo.dart
86 87 88 89 90 91 92 93
  static final RegExp _gitChangedRegex = new RegExp(r' (rename|delete mode|create mode) .+');

  // Public for testing.
  static bool matchesGitLine(String line) {
    return _gitDiffRegex.hasMatch(line)
      || _gitChangedRegex.hasMatch(line)
      || line == 'Fast-forward';
  }
94
}