upgrade.dart 2.54 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';
Devon Carew's avatar
Devon Carew committed
6
import 'dart:io';
7

8
import '../base/process.dart';
Devon Carew's avatar
Devon Carew committed
9
import '../dart/pub.dart';
10
import '../cache.dart';
11
import '../globals.dart';
12
import '../runner/flutter_command.dart';
13
import '../version.dart';
14 15

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

  @override
20 21
  final String description = 'Upgrade your copy of Flutter.';

22
  @override
23
  bool get requiresProjectRoot => false;
24

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

36
    printStatus('Upgrading Flutter from ${Cache.flutterRoot}...');
37

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

    if (code != 0)
      return code;

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

61
    printStatus('');
62
    printStatus(FlutterVersion.getVersion(Cache.flutterRoot).toString());
63

Devon Carew's avatar
Devon Carew committed
64 65 66 67 68 69 70
    if (FileSystemEntity.isFileSync('pubspec.yaml')) {
      printStatus('');
      code = await pubGet(upgrade: true, checkLastModified: false);

      if (code != 0)
        return code;
    }
71 72

    return 0;
73
  }
74 75 76 77 78 79

  //  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
80
  //  create mode 100644 examples/flutter_gallery/lib/gallery/demo.dart
81 82 83 84 85 86 87 88
  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';
  }
89
}