Commit 682c7992 authored by xster's avatar xster Committed by GitHub

Fix a crash (#7597) when the flutter sdk moves after getting packages (#7601)

* Add a check in case the flutter directory in .packages no longer exists. Clean up and prompt user

* Update documentation to use flutter packages get for end-users instead of flutter update-packages.

* Merge missing sdk error with the multiple sdk error. They're really the same thing.

* Use flutterPath in both checks.

* Change file_system’s copy folder to copy director which takes into account the file system

* Test support files

* Add test and split into 2 messages again.

* Move tests to run in memory file system's copy. Tested with dev/bots/test.sh
parent bc04c532
......@@ -352,14 +352,28 @@ class FlutterCommandRunner extends CommandRunner<Null> {
Uri rootUri = flutterUri.resolve('../../..');
String flutterPath = path.normalize(fs.file(rootUri).absolute.path);
if (!_compareResolvedPaths(flutterPath, Cache.flutterRoot)) {
if (!fs.isDirectorySync(flutterPath)) {
printError(
'Warning: the \'flutter\' tool you are currently running is different from the one referenced in your pubspec.yaml:\n'
' running Flutter : ${Cache.flutterRoot}\n'
' pubspec reference: $flutterPath\n'
'This can happen when you have multiple copies of flutter installed. Please check your system path to verify\n'
'that you\'re running the expected version (run \'flutter --version\' to see which flutter is on your path). You\n'
'can also change which flutter your project points to by editing the \'flutter:\' path in your pubspec.yaml file.\n'
'Warning! This package referenced a Flutter repository via the .packages file that is\n'
'no longer available. The repository from which the \'flutter\' tool is currently\n'
'executing will be used instead.\n'
' running Flutter tool: ${Cache.flutterRoot}\n'
' previous reference : $flutterPath\n'
'This can happen if you deleted or moved your copy of the Flutter repository, or\n'
'if it was on a volume that is no longer mounted or has been mounted at a\n'
'different location. Please check your system path to verify that you are running\n'
'the expected version (run \'flutter --version\' to see which flutter is on your path).\n'
);
} else if (!_compareResolvedPaths(flutterPath, Cache.flutterRoot)) {
printError(
'Warning! The \'flutter\' tool you are currently running is from a different Flutter\n'
'repository than the one last used by this package. The repository from which the\n'
'\'flutter\' tool is currently executing will be used instead.\n'
' running Flutter tool: ${Cache.flutterRoot}\n'
' previous reference : $flutterPath\n'
'This can happen when you have multiple copies of flutter installed. Please check\n'
'your system path to verify that you are running the expected version (run\n'
'\'flutter --version\' to see which flutter is on your path).\n'
);
}
}
......
flutter:file:///a/wild/non-existent/directory/has/appeared
sdk-move-test:lib/
// 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.
// No content
......@@ -2,7 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/devices.dart';
import 'package:flutter_tools/src/dart/dependencies.dart';
import 'package:flutter_tools/src/dependency_checker.dart';
import 'package:path/path.dart' as path;
......@@ -14,6 +18,13 @@ void main() {
group('DependencyChecker', () {
final String basePath = path.dirname(platform.script.path);
final String dataPath = path.join(basePath, 'data', 'dart_dependencies_test');
MemoryFileSystem testFileSystem;
setUp(() {
Cache.disableLocking();
testFileSystem = new MemoryFileSystem();
});
testUsingContext('good', () {
final String testPath = path.join(dataPath, 'good');
final String mainPath = path.join(testPath, 'main.dart');
......@@ -67,5 +78,24 @@ void main() {
// the .dart file.
expect(dependencyChecker.check(baseTime), isTrue);
});
/// Test a flutter tool move.
///
/// Tests that the flutter tool doesn't crash and displays a warning when its own location
/// changed since it was last referenced to in a package's .packages file.
testUsingContext('moved flutter sdk', () async {
String destinationPath = '/some/test/location';
// Copy the golden input and let the test run in an isolated temporary in-memory file system.
copyDirectorySync(
new LocalFileSystem().directory(path.join(dataPath, 'changed_sdk_location')),
fs.directory(destinationPath));
fs.currentDirectory = destinationPath;
// Doesn't matter what commands we run. Arbitrarily list devices here.
await createTestCommandRunner(new DevicesCommand()).run(<String>['devices']);
expect(testLogger.errorText, contains('.packages'));
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
});
});
}
......@@ -25,7 +25,7 @@ void main() {
String targetPath = '/some/non-existent/target';
Directory targetDirectory = targetMemoryFs.directory(targetPath);
copyDirectorySync(sourceDirectory, targetDirectory);
expect(targetDirectory.existsSync(), true);
targetMemoryFs.currentDirectory = targetPath;
expect(targetMemoryFs.directory('empty_directory').existsSync(), true);
......
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