2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2015-10-10 06:41:40 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-07-10 18:51:47 +00:00
|
|
|
import 'package:meta/meta.dart';
|
|
|
|
|
2017-11-10 05:45:31 +00:00
|
|
|
import 'runner.dart' as runner;
|
2019-02-15 07:17:16 +00:00
|
|
|
import 'src/base/context.dart';
|
2020-11-05 23:21:05 +00:00
|
|
|
import 'src/base/file_system.dart';
|
2020-07-10 18:51:47 +00:00
|
|
|
import 'src/base/io.dart';
|
2020-06-04 23:35:36 +00:00
|
|
|
import 'src/base/logger.dart';
|
2020-11-05 23:21:05 +00:00
|
|
|
import 'src/base/platform.dart';
|
2020-02-27 17:17:42 +00:00
|
|
|
import 'src/base/template.dart';
|
2020-07-10 18:51:47 +00:00
|
|
|
import 'src/base/terminal.dart';
|
2020-11-05 23:21:05 +00:00
|
|
|
import 'src/base/user_messages.dart';
|
|
|
|
import 'src/cache.dart';
|
2015-11-11 18:29:05 +00:00
|
|
|
import 'src/commands/analyze.dart';
|
2019-07-11 23:53:17 +00:00
|
|
|
import 'src/commands/assemble.dart';
|
2018-06-25 13:33:42 +00:00
|
|
|
import 'src/commands/attach.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
import 'src/commands/build.dart';
|
2016-08-25 19:16:21 +00:00
|
|
|
import 'src/commands/channel.dart';
|
2017-10-19 18:23:42 +00:00
|
|
|
import 'src/commands/clean.dart';
|
2016-04-26 23:25:11 +00:00
|
|
|
import 'src/commands/config.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';
|
2020-02-13 19:56:45 +00:00
|
|
|
import 'src/commands/downgrade.dart';
|
2016-02-20 00:31:34 +00:00
|
|
|
import 'src/commands/drive.dart';
|
2018-04-18 09:48:39 +00:00
|
|
|
import 'src/commands/emulators.dart';
|
2016-08-31 13:40:17 +00:00
|
|
|
import 'src/commands/format.dart';
|
2019-02-15 07:17:16 +00:00
|
|
|
import 'src/commands/generate.dart';
|
2020-09-03 16:26:58 +00:00
|
|
|
import 'src/commands/generate_localizations.dart';
|
2017-11-13 18:55:22 +00:00
|
|
|
import 'src/commands/ide_config.dart';
|
2015-10-10 06:41:40 +00:00
|
|
|
import 'src/commands/install.dart';
|
|
|
|
import 'src/commands/logs.dart';
|
2018-09-19 00:58:20 +00:00
|
|
|
import 'src/commands/make_host_app_editable.dart';
|
2016-08-26 02:37:48 +00:00
|
|
|
import 'src/commands/packages.dart';
|
2016-04-08 15:51:44 +00:00
|
|
|
import 'src/commands/precache.dart';
|
2016-02-14 07:50:20 +00:00
|
|
|
import 'src/commands/run.dart';
|
2016-03-25 23:04:22 +00:00
|
|
|
import 'src/commands/screenshot.dart';
|
2018-07-14 04:24:36 +00:00
|
|
|
import 'src/commands/shell_completion.dart';
|
2020-02-10 22:18:03 +00:00
|
|
|
import 'src/commands/symbolize.dart';
|
2015-11-05 07:43:15 +00:00
|
|
|
import 'src/commands/test.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';
|
2020-07-08 02:33:25 +00:00
|
|
|
import 'src/features.dart';
|
2020-02-10 22:18:03 +00:00
|
|
|
import 'src/globals.dart' as globals;
|
2020-09-30 01:15:56 +00:00
|
|
|
// Files in `isolated` are intentionally excluded from google3 tooling.
|
|
|
|
import 'src/isolated/devtools_launcher.dart';
|
|
|
|
import 'src/isolated/mustache_template.dart';
|
|
|
|
import 'src/isolated/resident_web_runner.dart';
|
|
|
|
import 'src/isolated/web_compilation_delegate.dart';
|
|
|
|
import 'src/resident_runner.dart';
|
2017-03-04 00:54:47 +00:00
|
|
|
import 'src/runner/flutter_command.dart';
|
2019-05-30 05:46:28 +00:00
|
|
|
import 'src/web/compile.dart';
|
2019-08-08 23:36:27 +00:00
|
|
|
import 'src/web/web_runner.dart';
|
2016-11-29 19:22:48 +00:00
|
|
|
|
2015-10-10 06:41:40 +00:00
|
|
|
/// Main entry point for commands.
|
|
|
|
///
|
2016-05-19 17:21:38 +00:00
|
|
|
/// This function is intended to be used from the `flutter` command line tool.
|
2018-10-05 05:54:56 +00:00
|
|
|
Future<void> main(List<String> args) async {
|
2020-07-10 00:55:53 +00:00
|
|
|
final bool veryVerbose = args.contains('-vv');
|
|
|
|
final bool verbose = args.contains('-v') || args.contains('--verbose') || veryVerbose;
|
2020-10-08 21:06:58 +00:00
|
|
|
// Support the -? Powershell help idiom.
|
|
|
|
final int powershellHelpIndex = args.indexOf('-?');
|
|
|
|
if (powershellHelpIndex != -1) {
|
|
|
|
args[powershellHelpIndex] = '-h';
|
|
|
|
}
|
2018-02-01 18:27:55 +00:00
|
|
|
|
|
|
|
final bool doctor = (args.isNotEmpty && args.first == 'doctor') ||
|
|
|
|
(args.length == 2 && verbose && args.last == 'doctor');
|
2017-03-04 01:50:46 +00:00
|
|
|
final bool help = args.contains('-h') || args.contains('--help') ||
|
2016-09-22 09:58:45 +00:00
|
|
|
(args.isNotEmpty && args.first == 'help') || (args.length == 1 && verbose);
|
2020-07-10 00:55:53 +00:00
|
|
|
final bool muteCommandLogging = (help || doctor) && !veryVerbose;
|
2017-03-04 01:50:46 +00:00
|
|
|
final bool verboseHelp = help && verbose;
|
2020-07-09 01:21:46 +00:00
|
|
|
final bool daemon = args.contains('daemon');
|
|
|
|
final bool runMachine = (args.contains('--machine') && args.contains('run')) ||
|
|
|
|
(args.contains('--machine') && args.contains('attach'));
|
2016-01-29 22:32:12 +00:00
|
|
|
|
2020-11-05 23:21:05 +00:00
|
|
|
// Cache.flutterRoot must be set early because other features use it (e.g.
|
|
|
|
// enginePath's initializer uses it). This can only work with the real
|
|
|
|
// instances of the platform or filesystem, so just use those.
|
|
|
|
Cache.flutterRoot = Cache.defaultFlutterRoot(
|
|
|
|
platform: const LocalPlatform(),
|
|
|
|
fileSystem: LocalFileSystem.instance,
|
|
|
|
userMessages: UserMessages(),
|
|
|
|
);
|
|
|
|
|
2020-06-04 23:35:36 +00:00
|
|
|
await runner.run(args, () => <FlutterCommand>[
|
2020-03-06 01:20:54 +00:00
|
|
|
AnalyzeCommand(
|
|
|
|
verboseHelp: verboseHelp,
|
|
|
|
fileSystem: globals.fs,
|
|
|
|
platform: globals.platform,
|
|
|
|
processManager: globals.processManager,
|
|
|
|
logger: globals.logger,
|
|
|
|
terminal: globals.terminal,
|
2020-06-09 17:47:21 +00:00
|
|
|
artifacts: globals.artifacts,
|
2020-03-06 01:20:54 +00:00
|
|
|
),
|
2019-07-11 23:53:17 +00:00
|
|
|
AssembleCommand(),
|
2018-09-12 06:29:29 +00:00
|
|
|
AttachCommand(verboseHelp: verboseHelp),
|
|
|
|
BuildCommand(verboseHelp: verboseHelp),
|
|
|
|
ChannelCommand(verboseHelp: verboseHelp),
|
2020-03-19 16:51:01 +00:00
|
|
|
CleanCommand(verbose: verbose),
|
2018-09-12 06:29:29 +00:00
|
|
|
ConfigCommand(verboseHelp: verboseHelp),
|
2018-10-10 18:01:40 +00:00
|
|
|
CreateCommand(),
|
2018-09-12 06:29:29 +00:00
|
|
|
DaemonCommand(hidden: !verboseHelp),
|
|
|
|
DevicesCommand(),
|
|
|
|
DoctorCommand(verbose: verbose),
|
2020-02-13 19:56:45 +00:00
|
|
|
DowngradeCommand(),
|
2020-10-26 17:11:30 +00:00
|
|
|
DriveCommand(verboseHelp: verboseHelp,
|
|
|
|
fileSystem: globals.fs,
|
|
|
|
logger: globals.logger,
|
|
|
|
),
|
2018-09-12 06:29:29 +00:00
|
|
|
EmulatorsCommand(),
|
|
|
|
FormatCommand(),
|
2019-02-15 07:17:16 +00:00
|
|
|
GenerateCommand(),
|
2020-09-03 16:26:58 +00:00
|
|
|
GenerateLocalizationsCommand(
|
|
|
|
fileSystem: globals.fs,
|
|
|
|
),
|
2018-09-12 06:29:29 +00:00
|
|
|
InstallCommand(),
|
|
|
|
LogsCommand(),
|
2018-09-19 00:58:20 +00:00
|
|
|
MakeHostAppEditableCommand(),
|
2018-09-12 06:29:29 +00:00
|
|
|
PackagesCommand(),
|
2020-07-08 02:33:25 +00:00
|
|
|
PrecacheCommand(
|
|
|
|
verboseHelp: verboseHelp,
|
|
|
|
cache: globals.cache,
|
|
|
|
logger: globals.logger,
|
|
|
|
platform: globals.platform,
|
|
|
|
featureFlags: featureFlags,
|
|
|
|
),
|
2018-09-12 06:29:29 +00:00
|
|
|
RunCommand(verboseHelp: verboseHelp),
|
|
|
|
ScreenshotCommand(),
|
|
|
|
ShellCompletionCommand(),
|
|
|
|
TestCommand(verboseHelp: verboseHelp),
|
|
|
|
UpgradeCommand(),
|
2020-02-10 22:18:03 +00:00
|
|
|
SymbolizeCommand(
|
|
|
|
stdio: globals.stdio,
|
|
|
|
fileSystem: globals.fs,
|
|
|
|
),
|
2020-05-27 17:10:19 +00:00
|
|
|
// Development-only commands. These are always hidden,
|
|
|
|
IdeConfigCommand(),
|
|
|
|
UpdatePackagesCommand(),
|
2018-02-01 18:27:55 +00:00
|
|
|
], verbose: verbose,
|
|
|
|
muteCommandLogging: muteCommandLogging,
|
2019-02-15 07:17:16 +00:00
|
|
|
verboseHelp: verboseHelp,
|
|
|
|
overrides: <Type, Generator>{
|
2019-05-30 05:46:28 +00:00
|
|
|
WebCompilationProxy: () => BuildRunnerWebCompilationProxy(),
|
2020-02-27 17:17:42 +00:00
|
|
|
// The web runner is not supported in google3 because it depends
|
2019-08-08 23:36:27 +00:00
|
|
|
// on dwds.
|
|
|
|
WebRunnerFactory: () => DwdsWebRunnerFactory(),
|
2020-02-27 17:17:42 +00:00
|
|
|
// The mustache dependency is different in google3
|
|
|
|
TemplateRenderer: () => const MustacheTemplateRenderer(),
|
2020-09-30 01:15:56 +00:00
|
|
|
// The devtools launcher is not supported in google3 because it depends on
|
|
|
|
// devtools source code.
|
|
|
|
DevtoolsLauncher: () => DevtoolsServerLauncher(logger: globals.logger),
|
2020-07-10 18:51:47 +00:00
|
|
|
Logger: () {
|
|
|
|
final LoggerFactory loggerFactory = LoggerFactory(
|
2020-06-04 23:35:36 +00:00
|
|
|
outputPreferences: globals.outputPreferences,
|
2020-07-10 01:04:37 +00:00
|
|
|
terminal: globals.terminal,
|
2020-07-09 01:21:46 +00:00
|
|
|
stdio: globals.stdio,
|
2020-07-10 18:51:47 +00:00
|
|
|
);
|
|
|
|
return loggerFactory.createLogger(
|
|
|
|
daemon: daemon,
|
|
|
|
machine: runMachine,
|
|
|
|
verbose: verbose && !muteCommandLogging,
|
|
|
|
windows: globals.platform.isWindows,
|
|
|
|
);
|
|
|
|
}
|
2019-02-15 07:17:16 +00:00
|
|
|
});
|
2017-03-04 00:54:47 +00:00
|
|
|
}
|
2020-07-10 18:51:47 +00:00
|
|
|
|
|
|
|
/// An abstraction for instantiation of the correct logger type.
|
|
|
|
///
|
|
|
|
/// Our logger class hierarchy and runtime requirements are overly complicated.
|
|
|
|
class LoggerFactory {
|
|
|
|
LoggerFactory({
|
|
|
|
@required Terminal terminal,
|
|
|
|
@required Stdio stdio,
|
|
|
|
@required OutputPreferences outputPreferences,
|
|
|
|
StopwatchFactory stopwatchFactory = const StopwatchFactory(),
|
|
|
|
}) : _terminal = terminal,
|
|
|
|
_stdio = stdio,
|
|
|
|
_stopwatchFactory = stopwatchFactory,
|
|
|
|
_outputPreferences = outputPreferences;
|
|
|
|
|
|
|
|
final Terminal _terminal;
|
|
|
|
final Stdio _stdio;
|
|
|
|
final StopwatchFactory _stopwatchFactory;
|
|
|
|
final OutputPreferences _outputPreferences;
|
|
|
|
|
|
|
|
/// Create the appropriate logger for the current platform and configuration.
|
|
|
|
Logger createLogger({
|
|
|
|
@required bool verbose,
|
|
|
|
@required bool machine,
|
|
|
|
@required bool daemon,
|
|
|
|
@required bool windows,
|
|
|
|
}) {
|
|
|
|
Logger logger;
|
|
|
|
if (windows) {
|
|
|
|
logger = WindowsStdoutLogger(
|
|
|
|
terminal: _terminal,
|
|
|
|
stdio: _stdio,
|
|
|
|
outputPreferences: _outputPreferences,
|
|
|
|
stopwatchFactory: _stopwatchFactory,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
logger = StdoutLogger(
|
|
|
|
terminal: _terminal,
|
|
|
|
stdio: _stdio,
|
|
|
|
outputPreferences: _outputPreferences,
|
|
|
|
stopwatchFactory: _stopwatchFactory
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (verbose) {
|
|
|
|
logger = VerboseLogger(logger, stopwatchFactory: _stopwatchFactory);
|
|
|
|
}
|
|
|
|
if (daemon) {
|
|
|
|
return NotifyingLogger(verbose: verbose, parent: logger);
|
|
|
|
}
|
|
|
|
if (machine) {
|
|
|
|
return AppRunLogger(parent: logger);
|
|
|
|
}
|
|
|
|
return logger;
|
|
|
|
}
|
|
|
|
}
|