precache.dart 2.58 KB
Newer Older
1 2 3 4 5 6
// Copyright 2016 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';

7
import '../cache.dart';
8
import '../globals.dart';
9
import '../runner/flutter_command.dart';
10
import '../version.dart';
11

12
class PrecacheCommand extends FlutterCommand {
13 14 15
  PrecacheCommand() {
    argParser.addFlag('all-platforms', abbr: 'a', negatable: false,
        help: 'Precache artifacts for all platforms.');
16 17
    argParser.addFlag('force', abbr: 'f', negatable: false,
        help: 'Force downloading of artifacts.');
18 19 20 21 22 23
    argParser.addFlag('android', negatable: true, defaultsTo: true,
        help: 'Precache artifacts for Android development');
    argParser.addFlag('ios', negatable: true, defaultsTo: true,
        help: 'Precache artifacts for iOS developemnt');
    argParser.addFlag('web', negatable: true, defaultsTo: false,
        help: 'Precache artifacts for web development');
24 25 26 27 28 29
    argParser.addFlag('linux', negatable: true, defaultsTo: false,
        help: 'Precache artifacts for linux desktop development');
    argParser.addFlag('windows', negatable: true, defaultsTo: false,
        help: 'Precache artifacts for windows desktop development');
    argParser.addFlag('macos', negatable: true, defaultsTo: false,
        help: 'Precache artifacts for macOS desktop development');
30 31 32 33
    argParser.addFlag('fuchsia', negatable: true, defaultsTo: false,
        help: 'Precache artifacts for Fuchsia development');
    argParser.addFlag('universal', negatable: true, defaultsTo: true,
        help: 'Precache artifacts required for all developments');
34 35
  }

36 37 38 39 40 41
  @override
  final String name = 'precache';

  @override
  final String description = 'Populates the Flutter tool\'s cache of binary artifacts.';

42 43 44
  @override
  bool get shouldUpdateCache => false;

45
  @override
46
  Future<FlutterCommandResult> runCommand() async {
47
    if (argResults['all-platforms']) {
48
      cache.includeAllPlatforms = true;
49
    }
50 51 52 53 54
    final Set<DevelopmentArtifact> requiredArtifacts = <DevelopmentArtifact>{};
    for (DevelopmentArtifact artifact in DevelopmentArtifact.values) {
      // Don't include unstable artifacts on stable branches.
      if (FlutterVersion.instance.isStable && artifact.unstable) {
        continue;
55
      }
56 57
      if (argResults[artifact.name]) {
        requiredArtifacts.add(artifact);
58
      }
59
    }
60 61
    final bool forceUpdate = argResults['force'];
    if (forceUpdate || !cache.isUpToDate()) {
62
      await cache.updateAll(requiredArtifacts);
63 64
    } else {
      printStatus('Already up-to-date.');
65
    }
66
    return null;
67 68
  }
}