• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'dart:async';
6
7import '../cache.dart';
8import '../globals.dart';
9import '../runner/flutter_command.dart';
10import '../version.dart';
11
12class PrecacheCommand extends FlutterCommand {
13  PrecacheCommand() {
14    argParser.addFlag('all-platforms', abbr: 'a', negatable: false,
15        help: 'Precache artifacts for all host platforms.');
16    argParser.addFlag('force', abbr: 'f', negatable: false,
17        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    argParser.addFlag('flutter_runner', negatable: true, defaultsTo: false,
35        help: 'Precache the flutter runner artifacts.', hide: true);
36  }
37
38  @override
39  final String name = 'precache';
40
41  @override
42  final String description = 'Populates the Flutter tool\'s cache of binary artifacts.';
43
44  @override
45  bool get shouldUpdateCache => false;
46
47  @override
48  Future<FlutterCommandResult> runCommand() async {
49    if (argResults['all-platforms']) {
50      cache.includeAllPlatforms = true;
51    }
52    final Set<DevelopmentArtifact> requiredArtifacts = <DevelopmentArtifact>{};
53    for (DevelopmentArtifact artifact in DevelopmentArtifact.values) {
54      // Don't include unstable artifacts on stable branches.
55      if (!FlutterVersion.instance.isMaster && artifact.unstable) {
56        continue;
57      }
58      if (argResults[artifact.name]) {
59        requiredArtifacts.add(artifact);
60      }
61    }
62    final bool forceUpdate = argResults['force'];
63    if (forceUpdate || !cache.isUpToDate()) {
64      await cache.updateAll(requiredArtifacts);
65    } else {
66      printStatus('Already up-to-date.');
67    }
68    return null;
69  }
70}
71