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

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

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

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

34 35 36 37 38 39 40 41
    FlutterVersion version = new FlutterVersion(Cache.flutterRoot);
    if (version.channel == 'alpha') {
      // The alpha branch is deprecated. Rather than trying to pull the alpha
      // branch, we should switch upstream to master.
      printStatus('Switching to from alpha to master...');
      runSync(<String>['git', 'branch', '--set-upstream-to=origin/master']);
    }

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

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

    if (code != 0)
51
      throwToolExit(null, exitCode: code);
52

53 54
    await buildUnlinkedForPackages(Cache.flutterRoot);

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 63 64 65 66 67
    code = await runCommandAndStreamOutput(
      <String>[
        'bin/flutter', '--no-color', 'precache'
      ],
      workingDirectory: Cache.flutterRoot,
      allowReentrantFlutter: true
    );
68

69
    printStatus('');
70
    printStatus(FlutterVersion.getVersion(Cache.flutterRoot).toString());
71

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

78 79 80 81
    // Run a doctor check in case system requirements have changed.
    printStatus('');
    printStatus('Running flutter doctor...');
    await doctor.diagnose();
82
  }
83 84 85 86 87 88

  //  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
89
  //  create mode 100644 examples/flutter_gallery/lib/gallery/demo.dart
90 91 92 93 94 95 96 97
  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';
  }
98
}