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:
Michael Goderbauer 2017-03-20 17:09:59 -07:00 committed by GitHub
parent 269538df58
commit d35a9db6fe
4 changed files with 73 additions and 1 deletions

View file

@ -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'])

View file

@ -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 {

View file

@ -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,7 +136,8 @@ 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.
await cache.updateAll();
if (shouldUpdateCache)
await cache.updateAll();
if (shouldRunPub)
await pubGet();

View file

@ -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 {}