2015-10-10 06:41:40 +00:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2015-10-13 20:36:39 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:args/command_runner.dart';
|
2016-03-25 18:49:07 +00:00
|
|
|
import 'package:path/path.dart' as path;
|
2015-11-02 08:20:22 +00:00
|
|
|
import 'package:stack_trace/stack_trace.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
|
2016-02-07 03:19:50 +00:00
|
|
|
import 'src/base/context.dart';
|
|
|
|
import 'src/base/logger.dart';
|
2015-11-29 05:07:16 +00:00
|
|
|
import 'src/base/process.dart';
|
2016-03-25 23:04:22 +00:00
|
|
|
import 'src/base/utils.dart';
|
2015-11-11 18:29:05 +00:00
|
|
|
import 'src/commands/analyze.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
import 'src/commands/build.dart';
|
2016-01-27 22:37:29 +00:00
|
|
|
import 'src/commands/create.dart';
|
2015-11-02 21:05:05 +00:00
|
|
|
import 'src/commands/daemon.dart';
|
2016-02-14 07:50:20 +00:00
|
|
|
import 'src/commands/devices.dart';
|
2016-02-17 02:23:43 +00:00
|
|
|
import 'src/commands/doctor.dart';
|
2016-02-20 00:31:34 +00:00
|
|
|
import 'src/commands/drive.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
import 'src/commands/install.dart';
|
|
|
|
import 'src/commands/listen.dart';
|
|
|
|
import 'src/commands/logs.dart';
|
2016-02-09 18:40:21 +00:00
|
|
|
import 'src/commands/refresh.dart';
|
2016-02-14 07:50:20 +00:00
|
|
|
import 'src/commands/run.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
import 'src/commands/run_mojo.dart';
|
2016-03-25 23:04:22 +00:00
|
|
|
import 'src/commands/screenshot.dart';
|
2016-04-07 19:33:11 +00:00
|
|
|
import 'src/commands/skia.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
import 'src/commands/stop.dart';
|
2015-11-05 07:43:15 +00:00
|
|
|
import 'src/commands/test.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
import 'src/commands/trace.dart';
|
2016-02-25 23:29:58 +00:00
|
|
|
import 'src/commands/update_packages.dart';
|
2015-11-12 18:13:40 +00:00
|
|
|
import 'src/commands/upgrade.dart';
|
2016-02-07 03:19:50 +00:00
|
|
|
import 'src/device.dart';
|
2016-02-17 02:23:43 +00:00
|
|
|
import 'src/doctor.dart';
|
2016-03-25 18:49:07 +00:00
|
|
|
import 'src/globals.dart';
|
2015-11-29 05:07:16 +00:00
|
|
|
import 'src/runner/flutter_command_runner.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
|
|
|
|
/// Main entry point for commands.
|
|
|
|
///
|
|
|
|
/// This function is intended to be used from the [flutter] command line tool.
|
2016-03-10 02:05:05 +00:00
|
|
|
Future<Null> main(List<String> args) async {
|
2016-01-29 22:32:12 +00:00
|
|
|
bool help = args.contains('-h') || args.contains('--help');
|
|
|
|
bool verbose = args.contains('-v') || args.contains('--verbose');
|
2016-02-14 07:50:20 +00:00
|
|
|
bool verboseHelp = help && verbose;
|
2016-01-29 22:32:12 +00:00
|
|
|
|
2016-03-14 16:41:00 +00:00
|
|
|
if (verboseHelp) {
|
|
|
|
// Remove the verbose option; for help, users don't need to see verbose logs.
|
|
|
|
args = new List<String>.from(args);
|
|
|
|
args.removeWhere((String option) => option == '-v' || option == '--verbose');
|
|
|
|
}
|
|
|
|
|
2016-02-14 07:50:20 +00:00
|
|
|
FlutterCommandRunner runner = new FlutterCommandRunner(verboseHelp: verboseHelp)
|
2015-11-11 18:29:05 +00:00
|
|
|
..addCommand(new AnalyzeCommand())
|
2015-10-10 06:41:40 +00:00
|
|
|
..addCommand(new BuildCommand())
|
2016-01-27 22:37:29 +00:00
|
|
|
..addCommand(new CreateCommand())
|
2016-03-15 16:27:58 +00:00
|
|
|
..addCommand(new DaemonCommand(hidden: !verboseHelp))
|
2016-02-14 07:50:20 +00:00
|
|
|
..addCommand(new DevicesCommand())
|
2016-02-17 02:23:43 +00:00
|
|
|
..addCommand(new DoctorCommand())
|
2016-02-20 00:31:34 +00:00
|
|
|
..addCommand(new DriveCommand())
|
2015-10-10 06:41:40 +00:00
|
|
|
..addCommand(new InstallCommand())
|
|
|
|
..addCommand(new ListenCommand())
|
|
|
|
..addCommand(new LogsCommand())
|
2016-02-09 18:40:21 +00:00
|
|
|
..addCommand(new RefreshCommand())
|
2016-02-14 07:50:20 +00:00
|
|
|
..addCommand(new RunCommand())
|
2016-03-15 16:27:58 +00:00
|
|
|
..addCommand(new RunMojoCommand(hidden: !verboseHelp))
|
2016-03-25 23:04:22 +00:00
|
|
|
..addCommand(new ScreenshotCommand())
|
2016-04-07 19:33:11 +00:00
|
|
|
..addCommand(new SkiaCommand())
|
2015-10-10 06:41:40 +00:00
|
|
|
..addCommand(new StopCommand())
|
2015-11-05 07:43:15 +00:00
|
|
|
..addCommand(new TestCommand())
|
2015-11-12 18:13:40 +00:00
|
|
|
..addCommand(new TraceCommand())
|
2016-03-15 16:27:58 +00:00
|
|
|
..addCommand(new UpdatePackagesCommand(hidden: !verboseHelp))
|
2015-11-12 18:13:40 +00:00
|
|
|
..addCommand(new UpgradeCommand());
|
2015-10-13 20:36:39 +00:00
|
|
|
|
2015-11-02 08:20:22 +00:00
|
|
|
return Chain.capture(() async {
|
2016-02-07 03:19:50 +00:00
|
|
|
// Initialize globals.
|
|
|
|
context[Logger] = new StdoutLogger();
|
|
|
|
context[DeviceManager] = new DeviceManager();
|
2016-02-17 02:23:43 +00:00
|
|
|
Doctor.initGlobal();
|
2016-02-07 03:19:50 +00:00
|
|
|
|
2015-10-17 18:50:23 +00:00
|
|
|
dynamic result = await runner.run(args);
|
2016-02-07 03:19:50 +00:00
|
|
|
|
2015-10-17 18:50:23 +00:00
|
|
|
if (result is int)
|
|
|
|
exit(result);
|
2016-03-10 02:05:05 +00:00
|
|
|
}, onError: (dynamic error, Chain chain) {
|
2015-11-02 08:20:22 +00:00
|
|
|
if (error is UsageException) {
|
2016-03-14 16:41:00 +00:00
|
|
|
stderr.writeln(error.message);
|
|
|
|
stderr.writeln();
|
|
|
|
stderr.writeln("Run 'flutter -h' (or 'flutter <command> -h') for available "
|
|
|
|
"flutter commands and options.");
|
2015-11-02 08:20:22 +00:00
|
|
|
// Argument error exit code.
|
|
|
|
exit(64);
|
|
|
|
} else if (error is ProcessExit) {
|
2015-10-29 03:57:51 +00:00
|
|
|
// We've caught an exit code.
|
2015-11-02 08:20:22 +00:00
|
|
|
exit(error.exitCode);
|
|
|
|
} else {
|
2016-03-25 18:49:07 +00:00
|
|
|
// We've crashed; emit a log report.
|
|
|
|
stderr.writeln();
|
2016-04-06 22:11:54 +00:00
|
|
|
if (error is String)
|
|
|
|
stderr.writeln('Oops; flutter has exited unexpectedly: "$error".');
|
|
|
|
else
|
|
|
|
stderr.writeln('Oops; flutter has exited unexpectedly.');
|
2016-04-01 15:33:22 +00:00
|
|
|
|
|
|
|
if (Platform.environment.containsKey('FLUTTER_DEV')) {
|
|
|
|
// If we're working in the tools themselves, just print the stack trace.
|
|
|
|
stderr.writeln(chain.terse.toString());
|
|
|
|
} else {
|
|
|
|
File file = _createCrashReport(args, error, chain);
|
|
|
|
|
2016-04-06 22:11:54 +00:00
|
|
|
stderr.writeln(
|
|
|
|
'Crash report written to ${path.relative(file.path)}; '
|
|
|
|
'please let us know at https://github.com/flutter/flutter/issues.');
|
2016-04-01 15:33:22 +00:00
|
|
|
}
|
|
|
|
|
2015-11-02 08:20:22 +00:00
|
|
|
exit(1);
|
2015-10-29 03:57:51 +00:00
|
|
|
}
|
2015-11-02 08:20:22 +00:00
|
|
|
});
|
2015-10-10 06:41:40 +00:00
|
|
|
}
|
2016-03-25 18:49:07 +00:00
|
|
|
|
|
|
|
File _createCrashReport(List<String> args, dynamic error, Chain chain) {
|
2016-03-25 23:04:22 +00:00
|
|
|
File crashFile = getUniqueFile(Directory.current, 'flutter', 'log');
|
2016-03-25 18:49:07 +00:00
|
|
|
|
|
|
|
StringBuffer buf = new StringBuffer();
|
|
|
|
|
|
|
|
buf.writeln('Flutter crash report; please file at https://github.com/flutter/flutter/issues.\n');
|
|
|
|
|
|
|
|
buf.writeln('## command\n');
|
|
|
|
buf.writeln('flutter ${args.join(' ')}\n');
|
|
|
|
|
|
|
|
buf.writeln('## exception\n');
|
|
|
|
buf.writeln('$error\n');
|
2016-04-06 22:11:54 +00:00
|
|
|
buf.writeln('```\n${chain.terse}```\n');
|
2016-03-25 18:49:07 +00:00
|
|
|
|
|
|
|
buf.writeln('## flutter doctor\n');
|
2016-04-06 22:11:54 +00:00
|
|
|
buf.writeln('```\n${_doctorText()}```');
|
2016-03-25 18:49:07 +00:00
|
|
|
|
|
|
|
crashFile.writeAsStringSync(buf.toString());
|
|
|
|
|
|
|
|
return crashFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
String _doctorText() {
|
|
|
|
try {
|
|
|
|
BufferLogger logger = new BufferLogger();
|
|
|
|
AppContext appContext = new AppContext();
|
|
|
|
|
|
|
|
appContext[Logger] = logger;
|
|
|
|
|
|
|
|
appContext.runInZone(() => doctor.diagnose());
|
|
|
|
|
|
|
|
return logger.statusText;
|
2016-03-28 23:20:43 +00:00
|
|
|
} catch (error, trace) {
|
2016-04-06 22:11:54 +00:00
|
|
|
return 'encountered exception: $error\n\n${trace.toString().trim()}\n';
|
2016-03-25 18:49:07 +00:00
|
|
|
}
|
|
|
|
}
|