diff --git a/bin/flutter b/bin/flutter index 53e8dc09d9..96930cf22e 100755 --- a/bin/flutter +++ b/bin/flutter @@ -37,14 +37,6 @@ if [ ! -f "$SNAPSHOT_PATH" ] || [ ! -f "$STAMP_PATH" ] || [ `cat "$STAMP_PATH"` echo $REVISION > "$STAMP_PATH" fi -# Add our internalized version of the Dart SDK to the path ahead of any other -# versions that might be installed on this machine. -# -# TODO(abarth): We should teach flutter_tools to our version of the Dart SDK -# explicitly instead of relying upon the PATH. -# -export PATH="$DART_SDK_PATH/bin:$PATH" - set +e if [ $FLUTTER_DEV ]; then diff --git a/packages/flutter_tools/lib/src/base/process.dart b/packages/flutter_tools/lib/src/base/process.dart index 7c478f70b4..c25919a706 100644 --- a/packages/flutter_tools/lib/src/base/process.dart +++ b/packages/flutter_tools/lib/src/base/process.dart @@ -6,9 +6,6 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; -import 'package:path/path.dart' as path; - -import '../dart/sdk.dart'; import '../globals.dart'; typedef String StringConverter(String string); @@ -91,13 +88,6 @@ String runSync(List cmd, { String workingDirectory }) { return _runWithLoggingSync(cmd, workingDirectory: workingDirectory); } -/// Return the platform specific name for the given Dart SDK binary. So, `pub` -/// ==> `pub.bat`. The default SDK location can be overridden with a specified -/// [sdkLocation]. -String sdkBinaryName(String name, { String sdkLocation }) { - return path.absolute(path.join(sdkLocation ?? dartSdkPath, 'bin', Platform.isWindows ? '$name.bat' : name)); -} - bool exitsHappy(List cli) { printTrace(cli.join(' ')); diff --git a/packages/flutter_tools/lib/src/commands/upgrade.dart b/packages/flutter_tools/lib/src/commands/upgrade.dart index 7f8dc73686..8bfbff5a25 100644 --- a/packages/flutter_tools/lib/src/commands/upgrade.dart +++ b/packages/flutter_tools/lib/src/commands/upgrade.dart @@ -33,7 +33,7 @@ class UpgradeCommand extends FlutterCommand { return 1; } - printStatus('Upgrading Flutter...'); + printStatus('Upgrading Flutter from ${ArtifactStore.flutterRoot}...'); int code = await runCommandAndStreamOutput( ['git', 'pull', '--ff-only'], diff --git a/packages/flutter_tools/lib/src/dart/pub.dart b/packages/flutter_tools/lib/src/dart/pub.dart index c0d4b4fae1..5372bd82b4 100644 --- a/packages/flutter_tools/lib/src/dart/pub.dart +++ b/packages/flutter_tools/lib/src/dart/pub.dart @@ -11,6 +11,7 @@ import '../base/logger.dart'; import '../base/process.dart'; import '../cache.dart'; import '../globals.dart'; +import 'sdk.dart'; bool _shouldRunPubGet({ File pubSpecYaml, File dotPackages }) { if (!dotPackages.existsSync()) diff --git a/packages/flutter_tools/lib/src/dart/sdk.dart b/packages/flutter_tools/lib/src/dart/sdk.dart index 0c7fcfff0d..f3b1c57a27 100644 --- a/packages/flutter_tools/lib/src/dart/sdk.dart +++ b/packages/flutter_tools/lib/src/dart/sdk.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:io'; + import 'package:path/path.dart' as path; import '../artifacts.dart'; @@ -10,3 +12,10 @@ import '../artifacts.dart'; String get dartSdkPath { return path.join(ArtifactStore.flutterRoot, 'bin', 'cache', 'dart-sdk'); } + +/// Return the platform specific name for the given Dart SDK binary. So, `pub` +/// ==> `pub.bat`. The default SDK location can be overridden with a specified +/// [sdkLocation]. +String sdkBinaryName(String name, { String sdkLocation }) { + return path.absolute(path.join(sdkLocation ?? dartSdkPath, 'bin', Platform.isWindows ? '$name.bat' : name)); +} diff --git a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart index 28bb5777f1..c905c57343 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart @@ -207,6 +207,9 @@ class FlutterCommandRunner extends CommandRunner { // we must set ArtifactStore.flutterRoot early because other features use it // (e.g. enginePath's initialiser uses it) ArtifactStore.flutterRoot = path.normalize(path.absolute(globalResults['flutter-root'])); + + _checkFlutterCopy(); + PackageMap.instance = new PackageMap(path.normalize(path.absolute( globalResults.wasParsed('packages') ? globalResults['packages'] : '.packages' ))); @@ -428,4 +431,36 @@ class FlutterCommandRunner extends CommandRunner { }) .toList(); } + + /// Check that the Flutter being run is the one we're expecting. + void _checkFlutterCopy() { + String directory = path.normalize(path.absolute(Directory.current.path)); + + // Check if the cwd is a flutter dir. + while (directory.isNotEmpty) { + if (_isDirectoryFlutterRepo(directory)) { + if (directory != ArtifactStore.flutterRoot) { + printError( + 'Warning: the active Flutter is not the one from the current directory.\n' + ' Active Flutter : ${ArtifactStore.flutterRoot}\n' + ' Current directory: $directory\n' + ); + } + + break; + } + + String parent = path.dirname(directory); + if (parent == directory) + break; + directory = parent; + } + } + + // Check if `bin/flutter` and `bin/cache/engine.stamp` exist. + bool _isDirectoryFlutterRepo(String directory) { + return + FileSystemEntity.isFileSync(path.join(directory, 'bin/flutter')) && + FileSystemEntity.isFileSync(path.join(directory, 'bin/cache/engine.stamp')); + } } diff --git a/packages/flutter_tools/test/create_test.dart b/packages/flutter_tools/test/create_test.dart index 31c68a069f..4e11487664 100644 --- a/packages/flutter_tools/test/create_test.dart +++ b/packages/flutter_tools/test/create_test.dart @@ -8,6 +8,7 @@ import 'dart:io'; import 'package:args/command_runner.dart'; import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/commands/create.dart'; +import 'package:flutter_tools/src/dart/sdk.dart'; import 'package:path/path.dart' as path; import 'package:test/test.dart'; @@ -76,7 +77,7 @@ Future _createAndAnalyzeProject(Directory dir, List createArgs) as expect(new File(mainPath).existsSync(), true); String flutterToolsPath = path.absolute(path.join('bin', 'flutter_tools.dart')); ProcessResult exec = Process.runSync( - 'dart', [flutterToolsPath, 'analyze'], + '$dartSdkPath/bin/dart', [flutterToolsPath, 'analyze'], workingDirectory: dir.path ); if (exec.exitCode != 0) {