Commit d35a9db6 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

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
parent 269538df
......@@ -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,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();
......
// 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 {}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment