-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flutter_migrate] Start command and executables (#2735)
* [flutter_migrate] Start command * Sync with upstream changes * Integrate with compute and add E2E tests * E2E tests passing * Resolve hangs, add help messages * Use CommandRunner * Cleanup hooks to prevent hang * Formatting * Softer requirements on test matching to ignore order * Null safety, address minor comments * Address comments * Cleanup and logging improvements * format, normalize * Kick tests * Fix tests * Improve win test robustness * Windows perms copyall * Fix directory typo bug * takeown command in CI * Add logging for windows * windows command debug logging * Skip running on unsupported flutter versions * Add main.dart * Bots memory, dynamic flutter executable * Different temp dir * Takeown of main.dart * test adjustments * Analyzer * Increase resources to dart_unit_tests * Remove logging
- Loading branch information
Showing
15 changed files
with
1,109 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter_migrate/executable.dart' as executable; | ||
|
||
void main(List<String> args) { | ||
executable.main(args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:io' as io; | ||
|
||
import 'package:args/args.dart'; | ||
import 'package:args/command_runner.dart'; | ||
|
||
import 'src/base/command.dart'; | ||
import 'src/base/file_system.dart'; | ||
import 'src/base_dependencies.dart'; | ||
|
||
import 'src/commands/abandon.dart'; | ||
import 'src/commands/apply.dart'; | ||
import 'src/commands/start.dart'; | ||
import 'src/commands/status.dart'; | ||
|
||
Future<void> main(List<String> args) async { | ||
final bool veryVerbose = args.contains('-vv'); | ||
final bool verbose = | ||
args.contains('-v') || args.contains('--verbose') || veryVerbose; | ||
|
||
final MigrateBaseDependencies baseDependencies = MigrateBaseDependencies(); | ||
|
||
final List<MigrateCommand> commands = <MigrateCommand>[ | ||
MigrateStartCommand( | ||
verbose: verbose, | ||
logger: baseDependencies.logger, | ||
fileSystem: baseDependencies.fileSystem, | ||
processManager: baseDependencies.processManager, | ||
), | ||
MigrateStatusCommand( | ||
verbose: verbose, | ||
logger: baseDependencies.logger, | ||
fileSystem: baseDependencies.fileSystem, | ||
processManager: baseDependencies.processManager, | ||
), | ||
MigrateAbandonCommand( | ||
logger: baseDependencies.logger, | ||
fileSystem: baseDependencies.fileSystem, | ||
terminal: baseDependencies.terminal, | ||
processManager: baseDependencies.processManager), | ||
MigrateApplyCommand( | ||
verbose: verbose, | ||
logger: baseDependencies.logger, | ||
fileSystem: baseDependencies.fileSystem, | ||
terminal: baseDependencies.terminal, | ||
processManager: baseDependencies.processManager), | ||
]; | ||
|
||
final MigrateCommandRunner runner = MigrateCommandRunner(); | ||
|
||
commands.forEach(runner.addCommand); | ||
await runner.run(args); | ||
|
||
await _exit(0, baseDependencies, | ||
shutdownHooks: baseDependencies.fileSystem.shutdownHooks); | ||
await baseDependencies.fileSystem.dispose(); | ||
} | ||
|
||
/// Simple extension of a CommandRunner to provide migrate specific global flags. | ||
class MigrateCommandRunner extends CommandRunner<void> { | ||
MigrateCommandRunner() | ||
: super( | ||
'flutter', | ||
'Migrates legacy flutter projects to modern versions.', | ||
) { | ||
argParser.addFlag('verbose', | ||
abbr: 'v', | ||
negatable: false, | ||
help: 'Noisy logging, including all shell commands executed.'); | ||
} | ||
|
||
@override | ||
ArgParser get argParser => _argParser; | ||
final ArgParser _argParser = ArgParser(); | ||
} | ||
|
||
Future<int> _exit(int code, MigrateBaseDependencies baseDependencies, | ||
{required ShutdownHooks shutdownHooks}) async { | ||
// Run shutdown hooks before flushing logs | ||
await shutdownHooks.runShutdownHooks(baseDependencies.logger); | ||
|
||
final Completer<void> completer = Completer<void>(); | ||
|
||
// Give the task / timer queue one cycle through before we hard exit. | ||
Timer.run(() { | ||
io.exit(code); | ||
}); | ||
|
||
await completer.future; | ||
return code; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// 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:process/process.dart'; | ||
|
||
import 'base/common.dart'; | ||
import 'base/file_system.dart'; | ||
import 'base/io.dart'; | ||
import 'base/logger.dart'; | ||
import 'base/signals.dart'; | ||
import 'base/terminal.dart'; | ||
|
||
/// Initializes the boilerplate dependencies needed by the migrate tool. | ||
class MigrateBaseDependencies { | ||
MigrateBaseDependencies() { | ||
processManager = const LocalProcessManager(); | ||
fileSystem = LocalFileSystem( | ||
LocalSignals.instance, Signals.defaultExitSignals, ShutdownHooks()); | ||
|
||
stdio = Stdio(); | ||
terminal = AnsiTerminal(stdio: stdio); | ||
|
||
final LoggerFactory loggerFactory = LoggerFactory( | ||
outputPreferences: OutputPreferences( | ||
wrapText: stdio.hasTerminal, | ||
showColor: stdout.supportsAnsiEscapes, | ||
stdio: stdio, | ||
), | ||
terminal: terminal, | ||
stdio: stdio, | ||
); | ||
logger = loggerFactory.createLogger( | ||
windows: isWindows, | ||
); | ||
} | ||
|
||
late final ProcessManager processManager; | ||
late final LocalFileSystem fileSystem; | ||
late final Stdio stdio; | ||
late final Terminal terminal; | ||
late final Logger logger; | ||
} | ||
|
||
/// 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 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); | ||
} | ||
return logger; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.