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

35 36 37 38 39 40 41 42
    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']);
    }

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

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

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

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

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

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

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

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