Auto-format Framework (#160545)

This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
Michael Goderbauer
2024-12-19 12:06:21 -08:00
committed by GitHub
parent 8e0993eda8
commit 5491c8c146
4411 changed files with 455108 additions and 415991 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -50,74 +50,107 @@ abstract final class FlutterGlobalOptions {
}
class FlutterCommandRunner extends CommandRunner<void> {
FlutterCommandRunner({ bool verboseHelp = false }) : super(
'flutter',
'Manage your Flutter app development.\n'
'\n'
'Common commands:\n'
'\n'
' flutter create <output directory>\n'
' Create a new Flutter project in the specified directory.\n'
'\n'
' flutter run [options]\n'
' Run your Flutter application on an attached device or in an emulator.',
) {
argParser.addFlag(FlutterGlobalOptions.kVerboseFlag,
abbr: 'v',
negatable: false,
help: 'Noisy logging, including all shell commands executed.\n'
'If used with "--help", shows hidden options. '
'If used with "flutter doctor", shows additional diagnostic information. '
'(Use "-vv" to force verbose logging in those cases.)');
argParser.addFlag(FlutterGlobalOptions.kPrefixedErrorsFlag,
negatable: false,
help: 'Causes lines sent to stderr to be prefixed with "ERROR:".',
hide: !verboseHelp);
argParser.addFlag(FlutterGlobalOptions.kQuietFlag,
negatable: false,
hide: !verboseHelp,
help: 'Reduce the amount of output from some commands.');
argParser.addFlag(FlutterGlobalOptions.kWrapFlag,
hide: !verboseHelp,
help: 'Toggles output word wrapping, regardless of whether or not the output is a terminal.',
defaultsTo: true);
argParser.addOption(FlutterGlobalOptions.kWrapColumnOption,
hide: !verboseHelp,
help: 'Sets the output wrap column. If not set, uses the width of the terminal. No '
'wrapping occurs if not writing to a terminal. Use "--no-wrap" to turn off wrapping '
'when connected to a terminal.');
argParser.addOption(FlutterGlobalOptions.kDeviceIdOption,
abbr: 'd',
help: 'Target device id or name (prefixes allowed).');
argParser.addFlag(FlutterGlobalOptions.kVersionFlag,
negatable: false,
help: 'Reports the version of this tool.');
argParser.addFlag(FlutterGlobalOptions.kMachineFlag,
negatable: false,
hide: !verboseHelp,
help: 'When used with the "--version" flag, outputs the information using JSON.');
argParser.addFlag(FlutterGlobalOptions.kColorFlag,
hide: !verboseHelp,
help: 'Whether to use terminal colors (requires support for ANSI escape sequences).',
defaultsTo: true);
argParser.addFlag(FlutterGlobalOptions.kVersionCheckFlag,
defaultsTo: true,
hide: !verboseHelp,
help: 'Allow Flutter to check for updates when this command runs.');
argParser.addFlag(FlutterGlobalOptions.kEnableAnalyticsFlag,
negatable: false,
help: 'Enable telemetry reporting each time a flutter or dart '
'command runs.');
argParser.addFlag(FlutterGlobalOptions.kDisableAnalyticsFlag,
negatable: false,
help: 'Disable telemetry reporting each time a flutter or dart '
'command runs, until it is re-enabled.');
argParser.addFlag(FlutterGlobalOptions.kSuppressAnalyticsFlag,
negatable: false,
help: 'Suppress analytics reporting for the current CLI invocation.');
argParser.addOption(FlutterGlobalOptions.kPackagesOption,
hide: !verboseHelp,
help: 'Path to your "package_config.json" file.');
FlutterCommandRunner({bool verboseHelp = false})
: super(
'flutter',
'Manage your Flutter app development.\n'
'\n'
'Common commands:\n'
'\n'
' flutter create <output directory>\n'
' Create a new Flutter project in the specified directory.\n'
'\n'
' flutter run [options]\n'
' Run your Flutter application on an attached device or in an emulator.',
) {
argParser.addFlag(
FlutterGlobalOptions.kVerboseFlag,
abbr: 'v',
negatable: false,
help:
'Noisy logging, including all shell commands executed.\n'
'If used with "--help", shows hidden options. '
'If used with "flutter doctor", shows additional diagnostic information. '
'(Use "-vv" to force verbose logging in those cases.)',
);
argParser.addFlag(
FlutterGlobalOptions.kPrefixedErrorsFlag,
negatable: false,
help: 'Causes lines sent to stderr to be prefixed with "ERROR:".',
hide: !verboseHelp,
);
argParser.addFlag(
FlutterGlobalOptions.kQuietFlag,
negatable: false,
hide: !verboseHelp,
help: 'Reduce the amount of output from some commands.',
);
argParser.addFlag(
FlutterGlobalOptions.kWrapFlag,
hide: !verboseHelp,
help: 'Toggles output word wrapping, regardless of whether or not the output is a terminal.',
defaultsTo: true,
);
argParser.addOption(
FlutterGlobalOptions.kWrapColumnOption,
hide: !verboseHelp,
help:
'Sets the output wrap column. If not set, uses the width of the terminal. No '
'wrapping occurs if not writing to a terminal. Use "--no-wrap" to turn off wrapping '
'when connected to a terminal.',
);
argParser.addOption(
FlutterGlobalOptions.kDeviceIdOption,
abbr: 'd',
help: 'Target device id or name (prefixes allowed).',
);
argParser.addFlag(
FlutterGlobalOptions.kVersionFlag,
negatable: false,
help: 'Reports the version of this tool.',
);
argParser.addFlag(
FlutterGlobalOptions.kMachineFlag,
negatable: false,
hide: !verboseHelp,
help: 'When used with the "--version" flag, outputs the information using JSON.',
);
argParser.addFlag(
FlutterGlobalOptions.kColorFlag,
hide: !verboseHelp,
help: 'Whether to use terminal colors (requires support for ANSI escape sequences).',
defaultsTo: true,
);
argParser.addFlag(
FlutterGlobalOptions.kVersionCheckFlag,
defaultsTo: true,
hide: !verboseHelp,
help: 'Allow Flutter to check for updates when this command runs.',
);
argParser.addFlag(
FlutterGlobalOptions.kEnableAnalyticsFlag,
negatable: false,
help:
'Enable telemetry reporting each time a flutter or dart '
'command runs.',
);
argParser.addFlag(
FlutterGlobalOptions.kDisableAnalyticsFlag,
negatable: false,
help:
'Disable telemetry reporting each time a flutter or dart '
'command runs, until it is re-enabled.',
);
argParser.addFlag(
FlutterGlobalOptions.kSuppressAnalyticsFlag,
negatable: false,
help: 'Suppress analytics reporting for the current CLI invocation.',
);
argParser.addOption(
FlutterGlobalOptions.kPackagesOption,
hide: !verboseHelp,
help: 'Path to your "package_config.json" file.',
);
argParser.addFlag(
FlutterGlobalOptions.kPrintDtd,
negatable: false,
@@ -129,44 +162,60 @@ class FlutterCommandRunner extends CommandRunner<void> {
argParser.addSeparator('Local build selection options (not normally required):');
}
argParser.addOption(FlutterGlobalOptions.kLocalEngineSrcPathOption,
hide: !verboseHelp,
help: 'Path to your engine src directory, if you are building Flutter locally.\n'
'Defaults to \$$kFlutterEngineEnvironmentVariableName if set, otherwise defaults to '
'the path given in your pubspec.yaml dependency_overrides for $kFlutterEnginePackageName, '
'if any.');
argParser.addOption(
FlutterGlobalOptions.kLocalEngineSrcPathOption,
hide: !verboseHelp,
help:
'Path to your engine src directory, if you are building Flutter locally.\n'
'Defaults to \$$kFlutterEngineEnvironmentVariableName if set, otherwise defaults to '
'the path given in your pubspec.yaml dependency_overrides for $kFlutterEnginePackageName, '
'if any.',
);
argParser.addOption(FlutterGlobalOptions.kLocalEngineOption,
hide: !verboseHelp,
help: 'Name of a build output within the engine out directory, if you are building Flutter locally.\n'
'Use this to select a specific version of the engine if you have built multiple engine targets.\n'
'This path is relative to "--local-engine-src-path" (see above).');
argParser.addOption(
FlutterGlobalOptions.kLocalEngineOption,
hide: !verboseHelp,
help:
'Name of a build output within the engine out directory, if you are building Flutter locally.\n'
'Use this to select a specific version of the engine if you have built multiple engine targets.\n'
'This path is relative to "--local-engine-src-path" (see above).',
);
argParser.addOption(FlutterGlobalOptions.kLocalEngineHostOption,
hide: !verboseHelp,
help: 'The host operating system for which engine artifacts should be selected, if you are building Flutter locally.\n'
'This is only used when "--local-engine" is also specified.\n'
'By default, the host is determined automatically, but you may need to specify this if you are building on one '
'platform (e.g. MacOS ARM64) but intend to run Flutter on another (e.g. Android).');
argParser.addOption(
FlutterGlobalOptions.kLocalEngineHostOption,
hide: !verboseHelp,
help:
'The host operating system for which engine artifacts should be selected, if you are building Flutter locally.\n'
'This is only used when "--local-engine" is also specified.\n'
'By default, the host is determined automatically, but you may need to specify this if you are building on one '
'platform (e.g. MacOS ARM64) but intend to run Flutter on another (e.g. Android).',
);
argParser.addOption(FlutterGlobalOptions.kLocalWebSDKOption,
hide: !verboseHelp,
help: 'Name of a build output within the engine out directory, if you are building Flutter locally.\n'
'Use this to select a specific version of the web sdk if you have built multiple engine targets.\n'
'This path is relative to "--local-engine-src-path" (see above).');
argParser.addOption(
FlutterGlobalOptions.kLocalWebSDKOption,
hide: !verboseHelp,
help:
'Name of a build output within the engine out directory, if you are building Flutter locally.\n'
'Use this to select a specific version of the web sdk if you have built multiple engine targets.\n'
'This path is relative to "--local-engine-src-path" (see above).',
);
if (verboseHelp) {
argParser.addSeparator('Options for testing the "flutter" tool itself:');
}
argParser.addFlag(FlutterGlobalOptions.kShowTestDeviceFlag,
negatable: false,
hide: !verboseHelp,
help: 'List the special "flutter-tester" device in device listings. '
'This headless device is used to test Flutter tooling.');
argParser.addFlag(FlutterGlobalOptions.kShowWebServerDeviceFlag,
negatable: false,
hide: !verboseHelp,
help: 'List the special "web-server" device in device listings.',
argParser.addFlag(
FlutterGlobalOptions.kShowTestDeviceFlag,
negatable: false,
hide: !verboseHelp,
help:
'List the special "flutter-tester" device in device listings. '
'This headless device is used to test Flutter tooling.',
);
argParser.addFlag(
FlutterGlobalOptions.kShowWebServerDeviceFlag,
negatable: false,
hide: !verboseHelp,
help: 'List the special "web-server" device in device listings.',
);
argParser.addFlag(
FlutterGlobalOptions.kContinuousIntegrationFlag,
@@ -185,12 +234,14 @@ class FlutterCommandRunner extends CommandRunner<void> {
ArgParser get argParser => _argParser;
final ArgParser _argParser = ArgParser(
allowTrailingOptions: false,
usageLineLength: globals.outputPreferences.wrapText ? globals.outputPreferences.wrapColumn : null,
usageLineLength:
globals.outputPreferences.wrapText ? globals.outputPreferences.wrapColumn : null,
);
@override
String get usageFooter {
return wrapText('Run "flutter help -v" for verbose help output, including less commonly used options.',
return wrapText(
'Run "flutter help -v" for verbose help output, including less commonly used options.',
columnWidth: globals.outputPreferences.wrapColumn,
shouldWrap: globals.outputPreferences.wrapText,
);
@@ -199,7 +250,8 @@ class FlutterCommandRunner extends CommandRunner<void> {
@override
String get usage {
final String usageWithoutDescription = super.usage.substring(description.length + 2);
final String prefix = wrapText(description,
final String prefix = wrapText(
description,
shouldWrap: globals.outputPreferences.wrapText,
columnWidth: globals.outputPreferences.wrapColumn,
);
@@ -264,13 +316,14 @@ class FlutterCommandRunner extends CommandRunner<void> {
required bool topLevelMachineFlag,
}) async {
// Check if the user has explicitly requested a version check.
final bool versionCheckFlag = topLevelResults[FlutterGlobalOptions.kVersionCheckFlag] as bool? ?? false;
final bool explicitVersionCheckPassed = topLevelResults.wasParsed(FlutterGlobalOptions.kVersionCheckFlag) && versionCheckFlag;
final bool versionCheckFlag =
topLevelResults[FlutterGlobalOptions.kVersionCheckFlag] as bool? ?? false;
final bool explicitVersionCheckPassed =
topLevelResults.wasParsed(FlutterGlobalOptions.kVersionCheckFlag) && versionCheckFlag;
if (explicitVersionCheckPassed) {
return true;
}
// If the top level --machine flag is set, we don't want to check for updates.
if (topLevelMachineFlag) {
return false;
@@ -293,7 +346,8 @@ class FlutterCommandRunner extends CommandRunner<void> {
}
// e.g. `flutter bash-completion` or `flutter zsh-completion`
final bool isShellCompletionCommand = !globals.stdio.hasTerminal && (topLevelResults.command?.name ?? '').endsWith('-completion');
final bool isShellCompletionCommand =
!globals.stdio.hasTerminal && (topLevelResults.command?.name ?? '').endsWith('-completion');
if (isShellCompletionCommand || await globals.botDetector.isRunningOnBot) {
return false;
}
@@ -321,30 +375,42 @@ class FlutterCommandRunner extends CommandRunner<void> {
try {
wrapColumn = int.parse(topLevelResults[FlutterGlobalOptions.kWrapColumnOption] as String);
if (wrapColumn < 0) {
throwToolExit(globals.userMessages.runnerWrapColumnInvalid(topLevelResults[FlutterGlobalOptions.kWrapColumnOption]));
throwToolExit(
globals.userMessages.runnerWrapColumnInvalid(
topLevelResults[FlutterGlobalOptions.kWrapColumnOption],
),
);
}
} on FormatException {
throwToolExit(globals.userMessages.runnerWrapColumnParseError(topLevelResults[FlutterGlobalOptions.kWrapColumnOption]));
throwToolExit(
globals.userMessages.runnerWrapColumnParseError(
topLevelResults[FlutterGlobalOptions.kWrapColumnOption],
),
);
}
}
// If we're not writing to a terminal with a defined width, then don't wrap
// anything, unless the user explicitly said to.
final bool useWrapping = topLevelResults.wasParsed(FlutterGlobalOptions.kWrapFlag)
? topLevelResults[FlutterGlobalOptions.kWrapFlag] as bool
: globals.stdio.terminalColumns != null && topLevelResults[FlutterGlobalOptions.kWrapFlag] as bool;
final bool useWrapping =
topLevelResults.wasParsed(FlutterGlobalOptions.kWrapFlag)
? topLevelResults[FlutterGlobalOptions.kWrapFlag] as bool
: globals.stdio.terminalColumns != null &&
topLevelResults[FlutterGlobalOptions.kWrapFlag] as bool;
contextOverrides[OutputPreferences] = OutputPreferences(
wrapText: useWrapping,
showColor: topLevelResults[FlutterGlobalOptions.kColorFlag] as bool?,
wrapColumn: wrapColumn,
);
if (((topLevelResults[FlutterGlobalOptions.kShowTestDeviceFlag] as bool?) ?? false)
|| topLevelResults[FlutterGlobalOptions.kDeviceIdOption] == FlutterTesterDevices.kTesterDeviceId) {
if (((topLevelResults[FlutterGlobalOptions.kShowTestDeviceFlag] as bool?) ?? false) ||
topLevelResults[FlutterGlobalOptions.kDeviceIdOption] ==
FlutterTesterDevices.kTesterDeviceId) {
FlutterTesterDevices.showFlutterTesterDevice = true;
}
if (((topLevelResults[FlutterGlobalOptions.kShowWebServerDeviceFlag] as bool?) ?? false)
|| topLevelResults[FlutterGlobalOptions.kDeviceIdOption] == WebServerDevice.kWebServerDeviceId) {
if (((topLevelResults[FlutterGlobalOptions.kShowWebServerDeviceFlag] as bool?) ?? false) ||
topLevelResults[FlutterGlobalOptions.kDeviceIdOption] ==
WebServerDevice.kWebServerDeviceId) {
WebServerDevice.showWebServerDevice = true;
}
@@ -379,24 +445,28 @@ class FlutterCommandRunner extends CommandRunner<void> {
}
globals.flutterVersion.ensureVersionFile();
final bool machineFlag = topLevelResults[FlutterGlobalOptions.kMachineFlag] as bool? ?? false;
final bool machineFlag =
topLevelResults[FlutterGlobalOptions.kMachineFlag] as bool? ?? false;
if (await _shouldCheckForUpdates(topLevelResults, topLevelMachineFlag: machineFlag)) {
await globals.flutterVersion.checkFlutterVersionFreshness();
}
// See if the user specified a specific device.
final String? specifiedDeviceId = topLevelResults[FlutterGlobalOptions.kDeviceIdOption] as String?;
final String? specifiedDeviceId =
topLevelResults[FlutterGlobalOptions.kDeviceIdOption] as String?;
if (specifiedDeviceId != null) {
globals.deviceManager?.specifiedDeviceId = specifiedDeviceId;
}
if ((topLevelResults[FlutterGlobalOptions.kVersionFlag] as bool?) ?? false) {
globals.flutterUsage.sendCommand(FlutterGlobalOptions.kVersionFlag);
globals.analytics.send(Event.flutterCommandResult(
commandPath: 'version',
result: 'success',
commandHasTerminal: globals.stdio.hasTerminal,
));
globals.analytics.send(
Event.flutterCommandResult(
commandPath: 'version',
result: 'success',
commandHasTerminal: globals.stdio.hasTerminal,
),
);
final FlutterVersion version = globals.flutterVersion.fetchTagsAndGetVersion(
clock: globals.systemClock,
);
@@ -412,11 +482,15 @@ class FlutterCommandRunner extends CommandRunner<void> {
return;
}
if (machineFlag && topLevelResults.command?.name != 'analyze') {
throwToolExit('The "--machine" flag is only valid with the "--version" flag or the "analyze --suggestions" command.', exitCode: 2);
throwToolExit(
'The "--machine" flag is only valid with the "--version" flag or the "analyze --suggestions" command.',
exitCode: 2,
);
}
// TODO(bkonyi): can this be removed and passed solely via DebuggingOptions?
final bool shouldPrintDtdUri = topLevelResults[FlutterGlobalOptions.kPrintDtd] as bool? ?? false;
final bool shouldPrintDtdUri =
topLevelResults[FlutterGlobalOptions.kPrintDtd] as bool? ?? false;
DevtoolsLauncher.instance!.printDtdUri = shouldPrintDtdUri;
await super.runCommand(topLevelResults);
@@ -436,9 +510,9 @@ class FlutterCommandRunner extends CommandRunner<void> {
/// Get all pub packages in the Flutter repo.
List<Directory> getRepoPackages() {
return getRepoRoots()
.expand<String>((String root) => _gatherProjectPaths(root))
.map<Directory>((String dir) => globals.fs.directory(dir))
.toList();
.expand<String>((String root) => _gatherProjectPaths(root))
.map<Directory>((String dir) => globals.fs.directory(dir))
.toList();
}
static List<String> _gatherProjectPaths(String rootPath) {
@@ -446,15 +520,15 @@ class FlutterCommandRunner extends CommandRunner<void> {
return <String>[];
}
final List<String> projectPaths = globals.fs.directory(rootPath)
.listSync(followLinks: false)
.expand((FileSystemEntity entity) {
if (entity is Directory && !globals.fs.path.split(entity.path).contains('.dart_tool')) {
return _gatherProjectPaths(entity.path);
}
return <String>[];
})
.toList();
final List<String> projectPaths =
globals.fs.directory(rootPath).listSync(followLinks: false).expand((
FileSystemEntity entity,
) {
if (entity is Directory && !globals.fs.path.split(entity.path).contains('.dart_tool')) {
return _gatherProjectPaths(entity.path);
}
return <String>[];
}).toList();
if (globals.fs.isFileSync(globals.fs.path.join(rootPath, 'pubspec.yaml'))) {
projectPaths.add(rootPath);

View File

@@ -37,7 +37,7 @@ class LocalEngineLocator {
_logger = logger,
_fileSystem = fileSystem,
_flutterRoot = flutterRoot,
_userMessages = userMessages;
_userMessages = userMessages;
final Platform _platform;
final Logger _logger;
@@ -54,7 +54,10 @@ class LocalEngineLocator {
String? packagePath,
}) async {
engineSourcePath ??= _platform.environment[kFlutterEngineEnvironmentVariableName];
if (engineSourcePath == null && localEngine == null && localWebSdk == null && packagePath == null) {
if (engineSourcePath == null &&
localEngine == null &&
localWebSdk == null &&
packagePath == null) {
return null;
}
@@ -79,10 +82,7 @@ class LocalEngineLocator {
}
if (engineSourcePath != null && _tryEnginePath(engineSourcePath) == null) {
throwToolExit(
_userMessages.runnerNoEngineBuildDirInPath(engineSourcePath),
exitCode: 2,
);
throwToolExit(_userMessages.runnerNoEngineBuildDirInPath(engineSourcePath), exitCode: 2);
}
if (engineSourcePath != null) {
@@ -114,7 +114,9 @@ class LocalEngineLocator {
final Directory buildDirectory = _fileSystem.directory(buildPath);
final Directory outDirectory = buildDirectory.parent;
final Directory srcDirectory = outDirectory.parent;
if (buildDirectory.existsSync() && outDirectory.basename == 'out' && srcDirectory.basename == 'src') {
if (buildDirectory.existsSync() &&
outDirectory.basename == 'out' &&
srcDirectory.basename == 'src') {
_logger.printTrace('Parsed engine source from local engine as ${srcDirectory.path}.');
return srcDirectory.path;
}
@@ -124,17 +126,24 @@ class LocalEngineLocator {
Future<String?> _findEngineSourceByPackageConfig(String? packagePath) async {
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
_fileSystem.file(
packagePath ?? findPackageConfigFileOrDefault(_fileSystem.currentDirectory),
),
_fileSystem.file(packagePath ?? findPackageConfigFileOrDefault(_fileSystem.currentDirectory)),
logger: _logger,
throwOnError: false,
);
// Skip if sky_engine is the version in bin/cache.
Uri? engineUri = packageConfig[kFlutterEnginePackageName]?.packageUriRoot;
final String cachedPath = _fileSystem.path.join(_flutterRoot, 'bin', 'cache', 'pkg', kFlutterEnginePackageName, 'lib');
final String cachedPath = _fileSystem.path.join(
_flutterRoot,
'bin',
'cache',
'pkg',
kFlutterEnginePackageName,
'lib',
);
if (engineUri != null && _fileSystem.identicalSync(cachedPath, engineUri.path)) {
_logger.printTrace('Local engine auto-detection sky_engine in $packagePath is the same version in bin/cache.');
_logger.printTrace(
'Local engine auto-detection sky_engine in $packagePath is the same version in bin/cache.',
);
engineUri = null;
}
// If sky_engine is specified and the engineSourcePath not set, try to
@@ -144,15 +153,10 @@ class LocalEngineLocator {
String? engineSourcePath;
final String? engineUriPath = engineUri?.path;
if (engineUriPath != null) {
engineSourcePath = _fileSystem.directory(engineUriPath)
.parent
.parent
.parent
.parent
.parent
.parent
.path;
if (engineSourcePath == _fileSystem.path.dirname(engineSourcePath) || engineSourcePath.isEmpty) {
engineSourcePath =
_fileSystem.directory(engineUriPath).parent.parent.parent.parent.parent.parent.path;
if (engineSourcePath == _fileSystem.path.dirname(engineSourcePath) ||
engineSourcePath.isEmpty) {
engineSourcePath = null;
throwToolExit(
_userMessages.runnerNoEngineSrcDir(
@@ -179,7 +183,9 @@ class LocalEngineLocator {
String? engineBuildPath;
String? engineHostBuildPath;
if (localEngine != null) {
engineBuildPath = _fileSystem.path.normalize(_fileSystem.path.join(engineSourcePath, 'out', localEngine));
engineBuildPath = _fileSystem.path.normalize(
_fileSystem.path.join(engineSourcePath, 'out', localEngine),
);
if (!_fileSystem.isDirectorySync(engineBuildPath)) {
throwToolExit(_userMessages.runnerNoEngineBuild(engineBuildPath), exitCode: 2);
}
@@ -197,13 +203,19 @@ class LocalEngineLocator {
String? webSdkPath;
if (localWebSdk != null) {
webSdkPath = _fileSystem.path.normalize(_fileSystem.path.join(engineSourcePath, 'out', localWebSdk));
webSdkPath = _fileSystem.path.normalize(
_fileSystem.path.join(engineSourcePath, 'out', localWebSdk),
);
if (!_fileSystem.isDirectorySync(webSdkPath)) {
throwToolExit(_userMessages.runnerNoWebSdk(webSdkPath), exitCode: 2);
}
}
return EngineBuildPaths(targetEngine: engineBuildPath, webSdk: webSdkPath, hostEngine: engineHostBuildPath);
return EngineBuildPaths(
targetEngine: engineBuildPath,
webSdk: webSdkPath,
hostEngine: engineHostBuildPath,
);
}
String? _tryEnginePath(String enginePath) {

View File

@@ -15,24 +15,30 @@ import '../ios/devices.dart';
const String _checkingForWirelessDevicesMessage = 'Checking for wireless devices...';
const String _chooseOneMessage = 'Please choose one (or "q" to quit)';
const String _connectedDevicesMessage = 'Connected devices:';
const String _foundButUnsupportedDevicesMessage = 'The following devices were found, but are not supported by this project:';
const String _noAttachedCheckForWirelessMessage = 'No devices found yet. Checking for wireless devices...';
const String _foundButUnsupportedDevicesMessage =
'The following devices were found, but are not supported by this project:';
const String _noAttachedCheckForWirelessMessage =
'No devices found yet. Checking for wireless devices...';
const String _noDevicesFoundMessage = 'No devices found.';
const String _noWirelessDevicesFoundMessage = 'No wireless devices were found.';
const String _wirelesslyConnectedDevicesMessage = 'Wirelessly connected devices:';
String _chooseDeviceOptionMessage(int option, String name, String deviceId) => '[$option]: $name ($deviceId)';
String _chooseDeviceOptionMessage(int option, String name, String deviceId) =>
'[$option]: $name ($deviceId)';
String _foundMultipleSpecifiedDevicesMessage(String deviceId) =>
'Found multiple devices with name or id matching $deviceId:';
String _foundSpecifiedDevicesMessage(int count, String deviceId) =>
'Found $count devices with name or id matching $deviceId:';
String _noMatchingDeviceMessage(String deviceId) => 'No supported devices found with name or id '
String _noMatchingDeviceMessage(String deviceId) =>
'No supported devices found with name or id '
"matching '$deviceId'.";
String flutterSpecifiedDeviceDevModeDisabled(String deviceName) => 'To use '
String flutterSpecifiedDeviceDevModeDisabled(String deviceName) =>
'To use '
"'$deviceName' for development, enable Developer Mode in Settings → Privacy & Security on the device. "
'If this does not work, open Xcode, reconnect the device, and look for a '
'popup on the device asking you to trust this computer.';
String flutterSpecifiedDeviceUnpaired(String deviceName) => "'$deviceName' is not paired. "
String flutterSpecifiedDeviceUnpaired(String deviceName) =>
"'$deviceName' is not paired. "
'Open Xcode and trust this computer when prompted.';
/// This class handles functionality of finding and selecting target devices.
@@ -64,8 +70,8 @@ class TargetDevices {
required DeviceManager deviceManager,
required Logger logger,
required this.deviceConnectionInterface,
}) : _deviceManager = deviceManager,
_logger = logger;
}) : _deviceManager = deviceManager,
_logger = logger;
final DeviceManager _deviceManager;
final Logger _logger;
@@ -78,9 +84,7 @@ class TargetDevices {
deviceConnectionInterface == null ||
deviceConnectionInterface == DeviceConnectionInterface.wireless;
Future<List<Device>> _getAttachedDevices({
DeviceDiscoverySupportFilter? supportFilter,
}) async {
Future<List<Device>> _getAttachedDevices({DeviceDiscoverySupportFilter? supportFilter}) async {
if (!_includeAttachedDevices) {
return <Device>[];
}
@@ -92,9 +96,7 @@ class TargetDevices {
);
}
Future<List<Device>> _getWirelessDevices({
DeviceDiscoverySupportFilter? supportFilter,
}) async {
Future<List<Device>> _getWirelessDevices({DeviceDiscoverySupportFilter? supportFilter}) async {
if (!_includeWirelessDevices) {
return <Device>[];
}
@@ -121,17 +123,13 @@ class TargetDevices {
);
}
DeviceDiscoverySupportFilter _defaultSupportFilter(
bool includeDevicesUnsupportedByProject,
) {
DeviceDiscoverySupportFilter _defaultSupportFilter(bool includeDevicesUnsupportedByProject) {
return _deviceManager.deviceSupportFilter(
includeDevicesUnsupportedByProject: includeDevicesUnsupportedByProject,
);
}
void startExtendedWirelessDeviceDiscovery({
Duration? deviceDiscoveryTimeout,
}) {}
void startExtendedWirelessDeviceDiscovery({Duration? deviceDiscoveryTimeout}) {}
/// Find and return all target [Device]s based upon criteria entered by the
/// user on the command line.
@@ -199,15 +197,11 @@ class TargetDevices {
Future<List<Device>?> _handleNoDevices() async {
// Get connected devices from cache, including unsupported ones.
final List<Device> unsupportedDevices = await _deviceManager.getAllDevices(
filter: DeviceDiscoveryFilter(
deviceConnectionInterface: deviceConnectionInterface,
)
filter: DeviceDiscoveryFilter(deviceConnectionInterface: deviceConnectionInterface),
);
if (_deviceManager.hasSpecifiedDeviceId) {
_logger.printStatus(
_noMatchingDeviceMessage(_deviceManager.specifiedDeviceId!),
);
_logger.printStatus(_noMatchingDeviceMessage(_deviceManager.specifiedDeviceId!));
if (unsupportedDevices.isNotEmpty) {
_logger.printStatus('');
_logger.printStatus('The following devices were found:');
@@ -216,9 +210,11 @@ class TargetDevices {
return null;
}
_logger.printStatus(_deviceManager.hasSpecifiedAllDevices
? _noDevicesFoundMessage
: globals.userMessages.flutterNoSupportedDevices);
_logger.printStatus(
_deviceManager.hasSpecifiedAllDevices
? _noDevicesFoundMessage
: globals.userMessages.flutterNoSupportedDevices,
);
await _printUnsupportedDevice(unsupportedDevices);
return null;
}
@@ -261,10 +257,9 @@ class TargetDevices {
List<Device> supportedWirelessDevices = wirelessDevices;
if (_deviceManager.hasSpecifiedDeviceId) {
final int allDeviceLength = supportedAttachedDevices.length + supportedWirelessDevices.length;
_logger.printStatus(_foundSpecifiedDevicesMessage(
allDeviceLength,
_deviceManager.specifiedDeviceId!,
));
_logger.printStatus(
_foundSpecifiedDevicesMessage(allDeviceLength, _deviceManager.specifiedDeviceId!),
);
} else {
// Get connected devices from cache, including ones unsupported for the
// project but still supported by Flutter.
@@ -301,10 +296,9 @@ class TargetDevices {
final List<Device> allDevices = attachedDevices + wirelessDevices;
if (_deviceManager.hasSpecifiedDeviceId) {
_logger.printStatus(_foundSpecifiedDevicesMessage(
allDevices.length,
_deviceManager.specifiedDeviceId!,
));
_logger.printStatus(
_foundSpecifiedDevicesMessage(allDevices.length, _deviceManager.specifiedDeviceId!),
);
} else {
_logger.printStatus(_connectedDevicesMessage);
}
@@ -333,22 +327,22 @@ class TargetDevices {
result.writeln();
result.writeln(_foundButUnsupportedDevicesMessage);
result.writeAll(
(await Device.descriptions(unsupportedDevices))
.map((String desc) => desc)
.toList(),
(await Device.descriptions(unsupportedDevices)).map((String desc) => desc).toList(),
'\n',
);
result.writeln();
result.writeln(globals.userMessages.flutterMissPlatformProjects(
Device.devicesPlatformTypes(unsupportedDevices),
));
result.writeln(
globals.userMessages.flutterMissPlatformProjects(
Device.devicesPlatformTypes(unsupportedDevices),
),
);
_logger.printStatus(result.toString(), newline: false);
}
}
Future<Device> _chooseOneOfAvailableDevices(List<Device> devices) async {
_displayDeviceOptions(devices);
final String userInput = await _readUserInput(devices.length);
final String userInput = await _readUserInput(devices.length);
if (userInput.toLowerCase() == 'q') {
throwToolExit('');
}
@@ -366,7 +360,7 @@ class TargetDevices {
Future<String> _readUserInput(int deviceCount) async {
globals.terminal.usesTerminalUi = true;
final String result = await globals.terminal.promptForCharInput(
<String>[ for (int i = 0; i < deviceCount; i++) '${i + 1}', 'q', 'Q'],
<String>[for (int i = 0; i < deviceCount; i++) '${i + 1}', 'q', 'Q'],
displayAcceptedCharacters: false,
logger: _logger,
prompt: _chooseOneMessage,
@@ -381,7 +375,7 @@ class TargetDevicesWithExtendedWirelessDeviceDiscovery extends TargetDevices {
required super.deviceManager,
required super.logger,
super.deviceConnectionInterface,
}) : super._private();
}) : super._private();
Future<void>? _wirelessDevicesRefresh;
@@ -392,9 +386,7 @@ class TargetDevicesWithExtendedWirelessDeviceDiscovery extends TargetDevices {
late final TargetDeviceSelection deviceSelection = TargetDeviceSelection(_logger);
@override
void startExtendedWirelessDeviceDiscovery({
Duration? deviceDiscoveryTimeout,
}) {
void startExtendedWirelessDeviceDiscovery({Duration? deviceDiscoveryTimeout}) {
if (deviceDiscoveryTimeout == null && _includeWirelessDevices) {
_wirelessDevicesRefresh ??= _deviceManager.refreshExtendedWirelessDeviceDiscoverers(
timeout: DeviceManager.minimumWirelessDeviceDiscoveryTimeout,
@@ -471,7 +463,8 @@ class TargetDevicesWithExtendedWirelessDeviceDiscovery extends TargetDevices {
// When a user defines the timeout or filters to only attached devices,
// use the super function that does not do longer wireless device
// discovery and does not wait for devices to connect.
if (deviceDiscoveryTimeout != null || deviceConnectionInterface == DeviceConnectionInterface.attached) {
if (deviceDiscoveryTimeout != null ||
deviceConnectionInterface == DeviceConnectionInterface.attached) {
return super.findAllTargetDevices(
deviceDiscoveryTimeout: deviceDiscoveryTimeout,
includeDevicesUnsupportedByProject: includeDevicesUnsupportedByProject,
@@ -507,9 +500,7 @@ class TargetDevicesWithExtendedWirelessDeviceDiscovery extends TargetDevices {
// If the only matching device does not have Developer Mode enabled,
// print a warning
if (!matchedDevice.devModeEnabled) {
_logger.printStatus(
flutterSpecifiedDeviceDevModeDisabled(matchedDevice.name)
);
_logger.printStatus(flutterSpecifiedDeviceDevModeDisabled(matchedDevice.name));
return null;
}
@@ -521,7 +512,6 @@ class TargetDevicesWithExtendedWirelessDeviceDiscovery extends TargetDevices {
if (matchedDevice != null && matchedDevice.isConnected) {
return <Device>[matchedDevice];
}
} else {
for (final IOSDevice device in specifiedDevices.whereType<IOSDevice>()) {
// Print warning for every matching unpaired device.
@@ -531,9 +521,7 @@ class TargetDevicesWithExtendedWirelessDeviceDiscovery extends TargetDevices {
// Print warning for every matching device that does not have Developer Mode enabled.
if (!device.devModeEnabled) {
_logger.printStatus(
flutterSpecifiedDeviceDevModeDisabled(device.name)
);
_logger.printStatus(flutterSpecifiedDeviceDevModeDisabled(device.name));
}
}
}
@@ -637,10 +625,7 @@ class TargetDevicesWithExtendedWirelessDeviceDiscovery extends TargetDevices {
return _printMultipleDevices(attachedDevices, wirelessDevices);
}
return _selectFromDevicesAndCheckForWireless(
attachedDevices,
futureWirelessDevices,
);
return _selectFromDevicesAndCheckForWireless(attachedDevices, futureWirelessDevices);
}
/// Display a list of selectable attached devices and prompt the user to
@@ -659,9 +644,7 @@ class TargetDevicesWithExtendedWirelessDeviceDiscovery extends TargetDevices {
_logger.printStatus(_connectedDevicesMessage);
} else if (_deviceManager.hasSpecifiedDeviceId) {
// Multiple devices were found with part of the name/id provided.
_logger.printStatus(_foundMultipleSpecifiedDevicesMessage(
_deviceManager.specifiedDeviceId!,
));
_logger.printStatus(_foundMultipleSpecifiedDevicesMessage(_deviceManager.specifiedDeviceId!));
}
// Display list of attached devices.
@@ -705,11 +688,7 @@ class TargetDevicesWithExtendedWirelessDeviceDiscovery extends TargetDevices {
_displayDeviceOptions(allDevices);
deviceSelection.devices = allDevices;
// Reprint device option prompt.
_logger.printStatus(
'$_chooseOneMessage: ',
emphasis: true,
newline: false,
);
_logger.printStatus('$_chooseOneMessage: ', emphasis: true, newline: false);
return wirelessDevices;
});
@@ -750,14 +729,8 @@ class TargetDevicesWithExtendedWirelessDeviceDiscovery extends TargetDevices {
/// Clear [numLinesToClear] lines from terminal. Print message and list of
/// wireless devices.
Future<void> _printWirelessDevices(
List<Device> wirelessDevices,
int numLinesToClear,
) async {
_logger.printStatus(
globals.terminal.clearLines(numLinesToClear),
newline: false,
);
Future<void> _printWirelessDevices(List<Device> wirelessDevices, int numLinesToClear) async {
_logger.printStatus(globals.terminal.clearLines(numLinesToClear), newline: false);
_logger.printStatus('');
if (wirelessDevices.isEmpty) {
_logger.printStatus(_noWirelessDevicesFoundMessage);