update_packages.dart 2.17 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
    argParser.addFlag(
      'upgrade',
21
      help: 'Ignores pubspec.lock and retrieves newer versions of packages.',
22 23 24 25
      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 36 37 38 39 40 41 42 43 44
  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);
Devon Carew's avatar
Devon Carew committed
45
    status.stop();
46 47
  }

48
  @override
49
  Future<int> runCommand() async {
50
    try {
51
      final Stopwatch timer = new Stopwatch()..start();
52
      int count = 0;
53
      final bool upgrade = argResults['upgrade'];
54

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

62
      await _downloadCoverageData();
63

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