Unverified Commit f69d1259 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Move Cache.flutterRoot initialization up sooner (#16057)

It's required to be set before we detect local engine.

Was broken by #15984
parent 8e978076
...@@ -238,6 +238,11 @@ class FlutterCommandRunner extends CommandRunner<Null> { ...@@ -238,6 +238,11 @@ class FlutterCommandRunner extends CommandRunner<Null> {
VMService.enableReplayConnection(replayFrom); VMService.enableReplayConnection(replayFrom);
} }
// We must set Cache.flutterRoot early because other features use it (e.g.
// enginePath's initializer uses it).
final String flutterRoot = topLevelResults['flutter-root'] ?? _defaultFlutterRoot;
Cache.flutterRoot = fs.path.normalize(fs.path.absolute(flutterRoot));
// Set up the tooling configuration. // Set up the tooling configuration.
final String enginePath = _findEnginePath(topLevelResults); final String enginePath = _findEnginePath(topLevelResults);
if (enginePath != null) { if (enginePath != null) {
...@@ -256,11 +261,6 @@ class FlutterCommandRunner extends CommandRunner<Null> { ...@@ -256,11 +261,6 @@ class FlutterCommandRunner extends CommandRunner<Null> {
if (topLevelResults.wasParsed('color')) if (topLevelResults.wasParsed('color'))
logger.supportsColor = topLevelResults['color']; logger.supportsColor = topLevelResults['color'];
// We must set Cache.flutterRoot early because other features use it (e.g.
// enginePath's initializer uses it).
final String flutterRoot = topLevelResults['flutter-root'] ?? _defaultFlutterRoot;
Cache.flutterRoot = fs.path.normalize(fs.path.absolute(flutterRoot));
if (platform.environment['FLUTTER_ALREADY_LOCKED'] != 'true') if (platform.environment['FLUTTER_ALREADY_LOCKED'] != 'true')
await Cache.lock(); await Cache.lock();
......
...@@ -8,14 +8,42 @@ import 'package:flutter_tools/src/runner/flutter_command_runner.dart'; ...@@ -8,14 +8,42 @@ import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/version.dart'; import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
import 'flutter_command_test.dart'; import 'flutter_command_test.dart';
const String _kFlutterRoot = '/flutter/flutter';
const String _kEngineRoot = '/flutter/engine';
const String _kProjectRoot = '/project';
const String _kDotPackages = '.packages';
void main() { void main() {
group('FlutterCommandRunner', () { group('FlutterCommandRunner', () {
MemoryFileSystem fs;
Platform platform;
FlutterCommandRunner runner;
setUpAll(() {
Cache.disableLocking();
});
setUp(() {
fs = new MemoryFileSystem();
fs.directory(_kFlutterRoot).createSync(recursive: true);
fs.directory(_kProjectRoot).createSync(recursive: true);
fs.currentDirectory = _kProjectRoot;
platform = new FakePlatform(environment: <String, String>{
'FLUTTER_ROOT': _kFlutterRoot,
});
runner = createTestCommandRunner(new DummyFlutterCommand());
});
group('run', () {
testUsingContext('checks that Flutter installation is up-to-date', () async { testUsingContext('checks that Flutter installation is up-to-date', () async {
final MockFlutterVersion version = FlutterVersion.instance; final MockFlutterVersion version = FlutterVersion.instance;
bool versionChecked = false; bool versionChecked = false;
...@@ -23,37 +51,51 @@ void main() { ...@@ -23,37 +51,51 @@ void main() {
versionChecked = true; versionChecked = true;
}); });
await createTestCommandRunner(new DummyFlutterCommand(shouldUpdateCache: false)) await runner.run(<String>['dummy']);
.run(<String>['dummy']);
expect(versionChecked, isTrue); expect(versionChecked, isTrue);
}); }, overrides: <Type, Generator>{
}); FileSystem: () => fs,
Platform: () => platform,
}, initializeFlutterRoot: false);
MemoryFileSystem fs; testUsingContext('works if --local-engine is specified', () async {
fs.file(_kDotPackages).writeAsStringSync('sky_engine:file://$_kFlutterRoot/bin/cache/pkg/sky_engine/lib/');
setUp(() { fs.directory('$_kEngineRoot/src/out/ios_debug').createSync(recursive: true);
fs = new MemoryFileSystem(); fs.directory('$_kEngineRoot/src/out/host_debug').createSync(recursive: true);
await runner.run(<String>['dummy', '--local-engine=ios_debug']);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
Platform: () => platform,
}, initializeFlutterRoot: false);
}); });
testUsingContext('getRepoPackages', () { group('getRepoPackages', () {
final FlutterCommandRunner runner = new FlutterCommandRunner(); setUp(() {
final String root = fs.path.absolute(Cache.flutterRoot); fs.directory(fs.path.join(_kFlutterRoot, 'examples'))
fs.directory(fs.path.join(root, 'examples'))
.createSync(recursive: true); .createSync(recursive: true);
fs.directory(fs.path.join(root, 'packages')) fs.directory(fs.path.join(_kFlutterRoot, 'packages'))
.createSync(recursive: true); .createSync(recursive: true);
fs.directory(fs.path.join(root, 'dev', 'tools', 'aatool')) fs.directory(fs.path.join(_kFlutterRoot, 'dev', 'tools', 'aatool'))
.createSync(recursive: true); .createSync(recursive: true);
fs.file(fs.path.join(root, 'dev', 'tools', 'pubspec.yaml')).createSync(); fs.file(fs.path.join(_kFlutterRoot, 'dev', 'tools', 'pubspec.yaml'))
fs.file(fs.path.join(root, 'dev', 'tools', 'aatool', 'pubspec.yaml')).createSync(); .createSync();
fs.file(fs.path.join(_kFlutterRoot, 'dev', 'tools', 'aatool', 'pubspec.yaml'))
.createSync();
});
testUsingContext('', () {
final List<String> packagePaths = runner.getRepoPackages() final List<String> packagePaths = runner.getRepoPackages()
.map((Directory d) => d.path).toList(); .map((Directory d) => d.path).toList();
expect(packagePaths, <String>[ expect(packagePaths, <String>[
fs.directory(fs.path.join(root, 'dev', 'tools', 'aatool')).path, fs.directory(fs.path.join(_kFlutterRoot, 'dev', 'tools', 'aatool')).path,
fs.directory(fs.path.join(root, 'dev', 'tools')).path, fs.directory(fs.path.join(_kFlutterRoot, 'dev', 'tools')).path,
]); ]);
}, overrides: <Type, Generator>{ FileSystem: () => fs }); }, overrides: <Type, Generator>{
FileSystem: () => fs,
Platform: () => platform,
}, initializeFlutterRoot: false);
});
});
} }
...@@ -40,6 +40,7 @@ typedef void ContextInitializer(AppContext testContext); ...@@ -40,6 +40,7 @@ typedef void ContextInitializer(AppContext testContext);
void testUsingContext(String description, dynamic testMethod(), { void testUsingContext(String description, dynamic testMethod(), {
Timeout timeout, Timeout timeout,
Map<Type, Generator> overrides: const <Type, Generator>{}, Map<Type, Generator> overrides: const <Type, Generator>{},
bool initializeFlutterRoot: true,
String testOn, String testOn,
bool skip, // should default to `false`, but https://github.com/dart-lang/test/issues/545 doesn't allow this bool skip, // should default to `false`, but https://github.com/dart-lang/test/issues/545 doesn't allow this
}) { }) {
...@@ -90,9 +91,11 @@ void testUsingContext(String description, dynamic testMethod(), { ...@@ -90,9 +91,11 @@ void testUsingContext(String description, dynamic testMethod(), {
overrides: overrides, overrides: overrides,
name: 'test-specific overrides', name: 'test-specific overrides',
body: () async { body: () async {
if (initializeFlutterRoot) {
// Provide a sane default for the flutterRoot directory. Individual // Provide a sane default for the flutterRoot directory. Individual
// tests can override this either in the test or during setup. // tests can override this either in the test or during setup.
Cache.flutterRoot ??= flutterRoot; Cache.flutterRoot ??= flutterRoot;
}
return await testMethod(); return await testMethod();
}, },
......
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