Merge pull request #3375 from pq/sdk_opt

Analyze CLI option to specify a custom Dart SDK.
diff --git a/packages/flutter_tools/lib/src/base/process.dart b/packages/flutter_tools/lib/src/base/process.dart
index e8465a0..adaf504 100644
--- a/packages/flutter_tools/lib/src/base/process.dart
+++ b/packages/flutter_tools/lib/src/base/process.dart
@@ -92,9 +92,10 @@
 }
 
 /// Return the platform specific name for the given Dart SDK binary. So, `pub`
-/// ==> `pub.bat`.
-String sdkBinaryName(String name) {
-  return path.absolute(path.join(dartSdkPath, 'bin', Platform.isWindows ? '$name.bat' : name));
+/// ==> `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<String> cli) {
diff --git a/packages/flutter_tools/lib/src/commands/analyze.dart b/packages/flutter_tools/lib/src/commands/analyze.dart
index 04e37ad..4e8ad38 100644
--- a/packages/flutter_tools/lib/src/commands/analyze.dart
+++ b/packages/flutter_tools/lib/src/commands/analyze.dart
@@ -100,6 +100,8 @@
     argParser.addFlag('preamble', help: 'Display the number of files that will be analyzed.', defaultsTo: true);
     argParser.addFlag('congratulate', help: 'Show output even when there are no errors, warnings, hints, or lints.', defaultsTo: true);
     argParser.addFlag('watch', help: 'Run analysis continuously, watching the filesystem for changes.', negatable: false);
+    argParser.addOption('dart-sdk', help: 'The path to the Dart SDK.', hide: true);
+
     usesPubOption();
   }
 
@@ -293,7 +295,7 @@
     File packagesFile = new File(path.join(host.path, '.packages'))..writeAsStringSync(packagesBody.toString());
 
     List<String> cmd = <String>[
-      sdkBinaryName('dartanalyzer'),
+      sdkBinaryName('dartanalyzer', sdkLocation: argResults['dart-sdk']),
       // do not set '--warnings', since that will include the entire Dart SDK
       '--ignore-unrecognized-flags',
       '--enable_type_checks',