precache.dart 2.74 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
  PrecacheCommand() {
    argParser.addFlag('all-platforms', abbr: 'a', negatable: false,
15
        help: 'Precache artifacts for all host platforms.');
16 17
    argParser.addFlag('force', abbr: 'f', negatable: false,
        help: 'Force downloading of artifacts.');
18
    argParser.addFlag('android', negatable: true, defaultsTo: true,
19
        help: 'Precache artifacts for Android development.');
20
    argParser.addFlag('ios', negatable: true, defaultsTo: true,
21
        help: 'Precache artifacts for iOS development.');
22
    argParser.addFlag('web', negatable: true, defaultsTo: false,
23
        help: 'Precache artifacts for web development.');
24
    argParser.addFlag('linux', negatable: true, defaultsTo: false,
25
        help: 'Precache artifacts for Linux desktop development.');
26
    argParser.addFlag('windows', negatable: true, defaultsTo: false,
27
        help: 'Precache artifacts for Windows desktop development.');
28
    argParser.addFlag('macos', negatable: true, defaultsTo: false,
29
        help: 'Precache artifacts for macOS desktop development.');
30
    argParser.addFlag('fuchsia', negatable: true, defaultsTo: false,
31
        help: 'Precache artifacts for Fuchsia development.');
32
    argParser.addFlag('universal', negatable: true, defaultsTo: true,
33
        help: 'Precache artifacts required for any development platform.');
34 35
    argParser.addFlag('flutter_runner', negatable: true, defaultsTo: false,
        help: 'Precache the flutter runner artifacts.', hide: true);
36 37
  }

38 39 40 41 42 43
  @override
  final String name = 'precache';

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

44 45 46
  @override
  bool get shouldUpdateCache => false;

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