mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
Avoid downloading artifacts twice (#8872)
* Avoid downloading artifacts twice * Don't update cache before `flutter upgrade` is executed (`flutter upgrade` might bump the engine version) * Don't update cache twice during `flutter precache` Fixes #8249. * add test
This commit is contained in:
parent
269538df58
commit
d35a9db6fe
|
@ -19,6 +19,9 @@ class PrecacheCommand extends FlutterCommand {
|
|||
@override
|
||||
final String description = 'Populates the Flutter tool\'s cache of binary artifacts.';
|
||||
|
||||
@override
|
||||
bool get shouldUpdateCache => false;
|
||||
|
||||
@override
|
||||
Future<Null> runCommand() async {
|
||||
if (argResults['all-platforms'])
|
||||
|
|
|
@ -22,6 +22,9 @@ class UpgradeCommand extends FlutterCommand {
|
|||
@override
|
||||
final String description = 'Upgrade your copy of Flutter.';
|
||||
|
||||
@override
|
||||
bool get shouldUpdateCache => false;
|
||||
|
||||
@override
|
||||
Future<Null> runCommand() async {
|
||||
try {
|
||||
|
|
|
@ -37,6 +37,8 @@ abstract class FlutterCommand extends Command<Null> {
|
|||
|
||||
bool get shouldRunPub => _usesPubOption && argResults['pub'];
|
||||
|
||||
bool get shouldUpdateCache => true;
|
||||
|
||||
BuildMode _defaultBuildMode;
|
||||
|
||||
void usesTargetOption() {
|
||||
|
@ -134,6 +136,7 @@ abstract class FlutterCommand extends Command<Null> {
|
|||
Future<Null> verifyThenRunCommand() async {
|
||||
// Populate the cache. We call this before pub get below so that the sky_engine
|
||||
// package is available in the flutter cache for pub to find.
|
||||
if (shouldUpdateCache)
|
||||
await cache.updateAll();
|
||||
|
||||
if (shouldRunPub)
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
// Copyright 2017 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 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/runner/flutter_command.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../context.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
group('Flutter Command', () {
|
||||
|
||||
MockCache cache;
|
||||
|
||||
setUp(() {
|
||||
cache = new MockCache();
|
||||
});
|
||||
|
||||
testUsingContext('honors shouldUpdateCache false', () async {
|
||||
final DummyFlutterCommand flutterCommand = new DummyFlutterCommand(shouldUpdateCache: false);
|
||||
await flutterCommand.run();
|
||||
verifyZeroInteractions(cache);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Cache: () => cache,
|
||||
});
|
||||
|
||||
testUsingContext('honors shouldUpdateCache true', () async {
|
||||
final DummyFlutterCommand flutterCommand = new DummyFlutterCommand(shouldUpdateCache: true);
|
||||
await flutterCommand.run();
|
||||
verify(cache.updateAll()).called(1);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Cache: () => cache,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class DummyFlutterCommand extends FlutterCommand {
|
||||
|
||||
DummyFlutterCommand({this.shouldUpdateCache});
|
||||
|
||||
@override
|
||||
final bool shouldUpdateCache;
|
||||
|
||||
@override
|
||||
String get description => 'does nothing';
|
||||
|
||||
@override
|
||||
String get name => 'dummy';
|
||||
|
||||
@override
|
||||
Future<Null> runCommand() async {
|
||||
// does nothing.
|
||||
}
|
||||
}
|
||||
|
||||
class MockCache extends Mock implements Cache {}
|
Loading…
Reference in a new issue