update_packages.dart 2.23 KB
Newer Older
1 2 3 4 5 6 7
// 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';
import 'dart:io';

8 9 10 11 12
import 'package:path/path.dart' as path;

import '../base/logger.dart';
import '../base/net.dart';
import '../cache.dart';
13 14 15 16 17
import '../dart/pub.dart';
import '../globals.dart';
import '../runner/flutter_command.dart';

class UpdatePackagesCommand extends FlutterCommand {
18
  UpdatePackagesCommand({ this.hidden: false }) {
19 20 21 22 23 24 25
    argParser.addFlag(
      'upgrade',
      help: 'Run "pub upgrade" rather than "pub get".',
      defaultsTo: false
    );
  }

26
  @override
27
  final String name = 'update-packages';
28 29

  @override
30 31
  final String description = 'Update the packages inside the Flutter repo.';

32
  @override
33
  final bool hidden;
34

35
  @override
36 37
  bool get requiresProjectRoot => false;

38 39 40 41 42 43 44 45 46 47 48 49 50
  Future<Null> _downloadCoverageData() async {
    Status status = logger.startProgress("Downloading lcov data for package:flutter...");
    final List<int> data = await fetchUrl(Uri.parse('https://storage.googleapis.com/flutter_infra/flutter/coverage/lcov.info'));
    final String coverageDir = path.join(Cache.flutterRoot, 'packages/flutter/coverage');
    new File(path.join(coverageDir, 'lcov.base.info'))
      ..createSync(recursive: true)
      ..writeAsBytesSync(data, flush: true);
    new File(path.join(coverageDir, 'lcov.info'))
      ..createSync(recursive: true)
      ..writeAsBytesSync(data, flush: true);
    status.stop(showElapsedTime: true);
  }

51 52
  @override
  Future<int> runInProject() async {
53
    try {
54
      final Stopwatch timer = new Stopwatch()..start();
55
      int count = 0;
56
      final bool upgrade = argResults['upgrade'];
57

58 59 60 61 62 63
      for (Directory dir in runner.getRepoPackages()) {
        int code = await pubGet(directory: dir.path, upgrade: upgrade, checkLastModified: false);
        if (code != 0)
          throw code;
        count++;
      }
64

65
      await _downloadCoverageData();
66

67 68
      final double seconds = timer.elapsedMilliseconds / 1000.0;
      printStatus('\nRan \'pub\' $count time${count == 1 ? "" : "s"} and fetched coverage data in ${seconds.toStringAsFixed(1)}s.');
69 70 71 72
      return 0;
    } on int catch (code) {
      return code;
    }
73 74
  }
}