mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Migrate doctor, format, and a few other commands to null safety (#92952)
This commit is contained in:
parent
cdbd0a92e3
commit
5be462f550
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.8
|
|
||||||
|
|
||||||
import '../android/android_workflow.dart';
|
import '../android/android_workflow.dart';
|
||||||
import '../base/common.dart';
|
import '../base/common.dart';
|
||||||
import '../globals.dart' as globals;
|
import '../globals.dart' as globals;
|
||||||
@ -12,7 +10,6 @@ import '../runner/flutter_command.dart';
|
|||||||
class DoctorCommand extends FlutterCommand {
|
class DoctorCommand extends FlutterCommand {
|
||||||
DoctorCommand({this.verbose = false}) {
|
DoctorCommand({this.verbose = false}) {
|
||||||
argParser.addFlag('android-licenses',
|
argParser.addFlag('android-licenses',
|
||||||
defaultsTo: false,
|
|
||||||
negatable: false,
|
negatable: false,
|
||||||
help: "Run the Android SDK manager tool to accept the SDK's licenses.",
|
help: "Run the Android SDK manager tool to accept the SDK's licenses.",
|
||||||
);
|
);
|
||||||
@ -37,11 +34,11 @@ class DoctorCommand extends FlutterCommand {
|
|||||||
@override
|
@override
|
||||||
Future<FlutterCommandResult> runCommand() async {
|
Future<FlutterCommandResult> runCommand() async {
|
||||||
globals.flutterVersion.fetchTagsAndUpdate();
|
globals.flutterVersion.fetchTagsAndUpdate();
|
||||||
if (argResults.wasParsed('check-for-remote-artifacts')) {
|
if (argResults?.wasParsed('check-for-remote-artifacts') == true) {
|
||||||
final String engineRevision = stringArg('check-for-remote-artifacts');
|
final String engineRevision = stringArg('check-for-remote-artifacts')!;
|
||||||
if (engineRevision.startsWith(RegExp(r'[a-f0-9]{1,40}'))) {
|
if (engineRevision.startsWith(RegExp(r'[a-f0-9]{1,40}'))) {
|
||||||
final bool success = await globals.doctor.checkRemoteArtifacts(engineRevision);
|
final bool success = await globals.doctor?.checkRemoteArtifacts(engineRevision) ?? false;
|
||||||
if (!success) {
|
if (success) {
|
||||||
throwToolExit('Artifacts for engine $engineRevision are missing or are '
|
throwToolExit('Artifacts for engine $engineRevision are missing or are '
|
||||||
'not yet available.', exitCode: 1);
|
'not yet available.', exitCode: 1);
|
||||||
}
|
}
|
||||||
@ -50,11 +47,11 @@ class DoctorCommand extends FlutterCommand {
|
|||||||
'git hash.');
|
'git hash.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final bool success = await globals.doctor.diagnose(
|
final bool success = await globals.doctor?.diagnose(
|
||||||
androidLicenses: boolArg('android-licenses'),
|
androidLicenses: boolArg('android-licenses'),
|
||||||
verbose: verbose,
|
verbose: verbose,
|
||||||
androidLicenseValidator: androidLicenseValidator,
|
androidLicenseValidator: androidLicenseValidator,
|
||||||
);
|
) ?? false;
|
||||||
return FlutterCommandResult(success ? ExitStatus.success : ExitStatus.warning);
|
return FlutterCommandResult(success ? ExitStatus.success : ExitStatus.warning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.8
|
|
||||||
|
|
||||||
import 'package:args/args.dart';
|
import 'package:args/args.dart';
|
||||||
import 'package:meta/meta.dart';
|
|
||||||
|
|
||||||
import '../artifacts.dart';
|
import '../artifacts.dart';
|
||||||
import '../base/common.dart';
|
import '../base/common.dart';
|
||||||
@ -13,7 +10,7 @@ import '../globals.dart' as globals;
|
|||||||
import '../runner/flutter_command.dart';
|
import '../runner/flutter_command.dart';
|
||||||
|
|
||||||
class FormatCommand extends FlutterCommand {
|
class FormatCommand extends FlutterCommand {
|
||||||
FormatCommand({@required this.verboseHelp});
|
FormatCommand({required this.verboseHelp});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ArgParser argParser = ArgParser.allowAnything();
|
ArgParser argParser = ArgParser.allowAnything();
|
||||||
@ -33,23 +30,24 @@ class FormatCommand extends FlutterCommand {
|
|||||||
String get category => FlutterCommandCategory.project;
|
String get category => FlutterCommandCategory.project;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get invocation => '${runner.executableName} $name <one or more paths>';
|
String get invocation => '${runner?.executableName} $name <one or more paths>';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<FlutterCommandResult> runCommand() async {
|
Future<FlutterCommandResult> runCommand() async {
|
||||||
final String dartBinary = globals.artifacts.getHostArtifact(HostArtifact.engineDartBinary).path;
|
final String dartBinary = globals.artifacts!.getHostArtifact(HostArtifact.engineDartBinary).path;
|
||||||
final List<String> command = <String>[
|
final List<String> command = <String>[
|
||||||
dartBinary,
|
dartBinary,
|
||||||
'format',
|
'format',
|
||||||
];
|
];
|
||||||
if (argResults.rest.isEmpty) {
|
final List<String> rest = argResults?.rest ?? <String>[];
|
||||||
|
if (rest.isEmpty) {
|
||||||
globals.printError(
|
globals.printError(
|
||||||
'No files specified to be formatted.'
|
'No files specified to be formatted.'
|
||||||
);
|
);
|
||||||
command.add('-h');
|
command.add('-h');
|
||||||
} else {
|
} else {
|
||||||
command.addAll(<String>[
|
command.addAll(<String>[
|
||||||
for (String arg in argResults.rest)
|
for (String arg in rest)
|
||||||
if (arg == '--dry-run' || arg == '-n')
|
if (arg == '--dry-run' || arg == '-n')
|
||||||
'--output=none'
|
'--output=none'
|
||||||
else
|
else
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.8
|
|
||||||
|
|
||||||
import '../globals.dart' as globals;
|
import '../globals.dart' as globals;
|
||||||
import '../runner/flutter_command.dart';
|
import '../runner/flutter_command.dart';
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.8
|
|
||||||
|
|
||||||
import '../base/common.dart';
|
import '../base/common.dart';
|
||||||
import '../base/file_system.dart';
|
import '../base/file_system.dart';
|
||||||
import '../base/logger.dart';
|
import '../base/logger.dart';
|
||||||
@ -21,8 +19,8 @@ import '../runner/flutter_command.dart';
|
|||||||
/// [internationalization user guide](flutter.dev/go/i18n-user-guide).
|
/// [internationalization user guide](flutter.dev/go/i18n-user-guide).
|
||||||
class GenerateLocalizationsCommand extends FlutterCommand {
|
class GenerateLocalizationsCommand extends FlutterCommand {
|
||||||
GenerateLocalizationsCommand({
|
GenerateLocalizationsCommand({
|
||||||
FileSystem fileSystem,
|
required FileSystem fileSystem,
|
||||||
Logger logger,
|
required Logger logger,
|
||||||
}) :
|
}) :
|
||||||
_fileSystem = fileSystem,
|
_fileSystem = fileSystem,
|
||||||
_logger = logger {
|
_logger = logger {
|
||||||
@ -108,7 +106,6 @@ class GenerateLocalizationsCommand extends FlutterCommand {
|
|||||||
);
|
);
|
||||||
argParser.addFlag(
|
argParser.addFlag(
|
||||||
'use-deferred-loading',
|
'use-deferred-loading',
|
||||||
defaultsTo: false,
|
|
||||||
help: 'Whether to generate the Dart localization file with locales imported '
|
help: 'Whether to generate the Dart localization file with locales imported '
|
||||||
'as deferred, allowing for lazy loading of each locale in Flutter web.\n'
|
'as deferred, allowing for lazy loading of each locale in Flutter web.\n'
|
||||||
'\n'
|
'\n'
|
||||||
@ -214,25 +211,24 @@ class GenerateLocalizationsCommand extends FlutterCommand {
|
|||||||
logger: _logger,
|
logger: _logger,
|
||||||
options: options,
|
options: options,
|
||||||
projectDir: _fileSystem.currentDirectory,
|
projectDir: _fileSystem.currentDirectory,
|
||||||
dependenciesDir: null,
|
|
||||||
fileSystem: _fileSystem,
|
fileSystem: _fileSystem,
|
||||||
);
|
);
|
||||||
return FlutterCommandResult.success();
|
return FlutterCommandResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String inputPathString = stringArg('arb-dir');
|
final String inputPathString = stringArg('arb-dir')!; // Has default value, cannot be null.
|
||||||
final String outputPathString = stringArg('output-dir');
|
final String? outputPathString = stringArg('output-dir');
|
||||||
final String outputFileString = stringArg('output-localization-file');
|
final String outputFileString = stringArg('output-localization-file')!; // Has default value, cannot be null.
|
||||||
final String templateArbFileName = stringArg('template-arb-file');
|
final String templateArbFileName = stringArg('template-arb-file')!; // Has default value, cannot be null.
|
||||||
final String untranslatedMessagesFile = stringArg('untranslated-messages-file');
|
final String? untranslatedMessagesFile = stringArg('untranslated-messages-file');
|
||||||
final String classNameString = stringArg('output-class');
|
final String classNameString = stringArg('output-class')!; // Has default value, cannot be null.
|
||||||
final List<String> preferredSupportedLocales = stringsArg('preferred-supported-locales');
|
final List<String> preferredSupportedLocales = stringsArg('preferred-supported-locales');
|
||||||
final String headerString = stringArg('header');
|
final String? headerString = stringArg('header');
|
||||||
final String headerFile = stringArg('header-file');
|
final String? headerFile = stringArg('header-file');
|
||||||
final bool useDeferredLoading = boolArg('use-deferred-loading');
|
final bool useDeferredLoading = boolArg('use-deferred-loading');
|
||||||
final String inputsAndOutputsListPath = stringArg('gen-inputs-and-outputs-list');
|
final String? inputsAndOutputsListPath = stringArg('gen-inputs-and-outputs-list');
|
||||||
final bool useSyntheticPackage = boolArg('synthetic-package');
|
final bool useSyntheticPackage = boolArg('synthetic-package');
|
||||||
final String projectPathString = stringArg('project-dir');
|
final String? projectPathString = stringArg('project-dir');
|
||||||
final bool areResourceAttributesRequired = boolArg('required-resource-attributes');
|
final bool areResourceAttributesRequired = boolArg('required-resource-attributes');
|
||||||
final bool usesNullableGetter = boolArg('nullable-getter');
|
final bool usesNullableGetter = boolArg('nullable-getter');
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.8
|
|
||||||
|
|
||||||
import '../base/common.dart';
|
import '../base/common.dart';
|
||||||
import '../base/file_system.dart';
|
import '../base/file_system.dart';
|
||||||
import '../cache.dart';
|
import '../cache.dart';
|
||||||
@ -15,8 +13,6 @@ class IdeConfigCommand extends FlutterCommand {
|
|||||||
IdeConfigCommand() {
|
IdeConfigCommand() {
|
||||||
argParser.addFlag(
|
argParser.addFlag(
|
||||||
'overwrite',
|
'overwrite',
|
||||||
negatable: true,
|
|
||||||
defaultsTo: false,
|
|
||||||
help: 'When performing operations, overwrite existing files.',
|
help: 'When performing operations, overwrite existing files.',
|
||||||
);
|
);
|
||||||
argParser.addFlag(
|
argParser.addFlag(
|
||||||
@ -31,7 +27,6 @@ class IdeConfigCommand extends FlutterCommand {
|
|||||||
);
|
);
|
||||||
argParser.addFlag(
|
argParser.addFlag(
|
||||||
'with-root-module',
|
'with-root-module',
|
||||||
negatable: true,
|
|
||||||
defaultsTo: true,
|
defaultsTo: true,
|
||||||
help: 'Also create module that corresponds to the root of Flutter tree. '
|
help: 'Also create module that corresponds to the root of Flutter tree. '
|
||||||
'This makes the entire Flutter tree browsable and searchable in IDE. '
|
'This makes the entire Flutter tree browsable and searchable in IDE. '
|
||||||
@ -60,12 +55,12 @@ class IdeConfigCommand extends FlutterCommand {
|
|||||||
final bool hidden = true;
|
final bool hidden = true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get invocation => '${runner.executableName} $name';
|
String get invocation => '${runner?.executableName} $name';
|
||||||
|
|
||||||
static const String _ideName = 'intellij';
|
static const String _ideName = 'intellij';
|
||||||
Directory get _templateDirectory {
|
Directory get _templateDirectory {
|
||||||
return globals.fs.directory(globals.fs.path.join(
|
return globals.fs.directory(globals.fs.path.join(
|
||||||
Cache.flutterRoot,
|
Cache.flutterRoot!,
|
||||||
'packages',
|
'packages',
|
||||||
'flutter_tools',
|
'flutter_tools',
|
||||||
'ide_templates',
|
'ide_templates',
|
||||||
@ -75,14 +70,14 @@ class IdeConfigCommand extends FlutterCommand {
|
|||||||
|
|
||||||
Directory get _createTemplatesDirectory {
|
Directory get _createTemplatesDirectory {
|
||||||
return globals.fs.directory(globals.fs.path.join(
|
return globals.fs.directory(globals.fs.path.join(
|
||||||
Cache.flutterRoot,
|
Cache.flutterRoot!,
|
||||||
'packages',
|
'packages',
|
||||||
'flutter_tools',
|
'flutter_tools',
|
||||||
'templates',
|
'templates',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory get _flutterRoot => globals.fs.directory(globals.fs.path.absolute(Cache.flutterRoot));
|
Directory get _flutterRoot => globals.fs.directory(globals.fs.path.absolute(Cache.flutterRoot!));
|
||||||
|
|
||||||
// Returns true if any entire path element is equal to dir.
|
// Returns true if any entire path element is equal to dir.
|
||||||
bool _hasDirectoryInPath(FileSystemEntity entity, String dir) {
|
bool _hasDirectoryInPath(FileSystemEntity entity, String dir) {
|
||||||
@ -213,7 +208,8 @@ class IdeConfigCommand extends FlutterCommand {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<FlutterCommandResult> runCommand() async {
|
Future<FlutterCommandResult> runCommand() async {
|
||||||
if (argResults.rest.isNotEmpty) {
|
final List<String> rest = argResults?.rest ?? <String>[];
|
||||||
|
if (rest.isNotEmpty) {
|
||||||
throwToolExit('Currently, the only supported IDE is IntelliJ\n$usage', exitCode: 2);
|
throwToolExit('Currently, the only supported IDE is IntelliJ\n$usage', exitCode: 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,12 +218,12 @@ class IdeConfigCommand extends FlutterCommand {
|
|||||||
return FlutterCommandResult.success();
|
return FlutterCommandResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String flutterRoot = globals.fs.path.absolute(Cache.flutterRoot);
|
final String flutterRoot = globals.fs.path.absolute(Cache.flutterRoot!);
|
||||||
final String dirPath = globals.fs.path.normalize(
|
final String dirPath = globals.fs.path.normalize(
|
||||||
globals.fs.directory(globals.fs.path.absolute(Cache.flutterRoot)).absolute.path,
|
globals.fs.directory(globals.fs.path.absolute(Cache.flutterRoot!)).absolute.path,
|
||||||
);
|
);
|
||||||
|
|
||||||
final String error = _validateFlutterDir(dirPath, flutterRoot: flutterRoot);
|
final String? error = _validateFlutterDir(dirPath, flutterRoot: flutterRoot);
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throwToolExit(error);
|
throwToolExit(error);
|
||||||
}
|
}
|
||||||
@ -265,7 +261,7 @@ class IdeConfigCommand extends FlutterCommand {
|
|||||||
|
|
||||||
/// Return null if the flutter root directory is a valid destination. Return a
|
/// Return null if the flutter root directory is a valid destination. Return a
|
||||||
/// validation message if we should disallow the directory.
|
/// validation message if we should disallow the directory.
|
||||||
String _validateFlutterDir(String dirPath, { String flutterRoot }) {
|
String? _validateFlutterDir(String dirPath, { String? flutterRoot }) {
|
||||||
final FileSystemEntityType type = globals.fs.typeSync(dirPath);
|
final FileSystemEntityType type = globals.fs.typeSync(dirPath);
|
||||||
|
|
||||||
switch (type) { // ignore: exhaustive_cases, https://github.com/dart-lang/linter/issues/3017
|
switch (type) { // ignore: exhaustive_cases, https://github.com/dart-lang/linter/issues/3017
|
||||||
@ -277,5 +273,4 @@ String _validateFlutterDir(String dirPath, { String flutterRoot }) {
|
|||||||
case FileSystemEntityType.notFound:
|
case FileSystemEntityType.notFound:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return null; // dead code, remove after null safety migration
|
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.8
|
|
||||||
|
|
||||||
import 'package:vm_service/vm_service.dart' as vm_service;
|
import 'package:vm_service/vm_service.dart' as vm_service;
|
||||||
|
|
||||||
import '../base/common.dart';
|
import '../base/common.dart';
|
||||||
@ -67,9 +65,9 @@ class ScreenshotCommand extends FlutterCommand {
|
|||||||
@override
|
@override
|
||||||
final List<String> aliases = <String>['pic'];
|
final List<String> aliases = <String>['pic'];
|
||||||
|
|
||||||
Device device;
|
Device? device;
|
||||||
|
|
||||||
Future<void> _validateOptions(String screenshotType, String observatoryUrl) async {
|
Future<void> _validateOptions(String? screenshotType, String? observatoryUrl) async {
|
||||||
switch (screenshotType) {
|
switch (screenshotType) {
|
||||||
case _kDeviceType:
|
case _kDeviceType:
|
||||||
if (observatoryUrl != null) {
|
if (observatoryUrl != null) {
|
||||||
@ -79,8 +77,8 @@ class ScreenshotCommand extends FlutterCommand {
|
|||||||
if (device == null) {
|
if (device == null) {
|
||||||
throwToolExit('Must have a connected device for screenshot type $screenshotType');
|
throwToolExit('Must have a connected device for screenshot type $screenshotType');
|
||||||
}
|
}
|
||||||
if (!device.supportsScreenshot) {
|
if (!device!.supportsScreenshot) {
|
||||||
throwToolExit('Screenshot not supported for ${device.name}.');
|
throwToolExit('Screenshot not supported for ${device!.name}.');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -94,15 +92,15 @@ class ScreenshotCommand extends FlutterCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<FlutterCommandResult> verifyThenRunCommand(String commandPath) async {
|
Future<FlutterCommandResult> verifyThenRunCommand(String? commandPath) async {
|
||||||
await _validateOptions(stringArg(_kType), stringArg(_kObservatoryUrl));
|
await _validateOptions(stringArg(_kType), stringArg(_kObservatoryUrl));
|
||||||
return super.verifyThenRunCommand(commandPath);
|
return super.verifyThenRunCommand(commandPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<FlutterCommandResult> runCommand() async {
|
Future<FlutterCommandResult> runCommand() async {
|
||||||
File outputFile;
|
File? outputFile;
|
||||||
if (argResults.wasParsed(_kOut)) {
|
if (argResults?.wasParsed(_kOut) == true) {
|
||||||
outputFile = globals.fs.file(stringArg(_kOut));
|
outputFile = globals.fs.file(stringArg(_kOut));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,24 +121,24 @@ class ScreenshotCommand extends FlutterCommand {
|
|||||||
: FlutterCommandResult.fail();
|
: FlutterCommandResult.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> runScreenshot(File outputFile) async {
|
Future<void> runScreenshot(File? outputFile) async {
|
||||||
outputFile ??= globals.fsUtils.getUniqueFile(
|
outputFile ??= globals.fsUtils.getUniqueFile(
|
||||||
globals.fs.currentDirectory,
|
globals.fs.currentDirectory,
|
||||||
'flutter',
|
'flutter',
|
||||||
'png',
|
'png',
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
await device.takeScreenshot(outputFile);
|
await device!.takeScreenshot(outputFile);
|
||||||
} on Exception catch (error) {
|
} on Exception catch (error) {
|
||||||
throwToolExit('Error taking screenshot: $error');
|
throwToolExit('Error taking screenshot: $error');
|
||||||
}
|
}
|
||||||
_showOutputFileInfo(outputFile);
|
_showOutputFileInfo(outputFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> runSkia(File outputFile) async {
|
Future<bool> runSkia(File? outputFile) async {
|
||||||
final Uri observatoryUrl = Uri.parse(stringArg(_kObservatoryUrl));
|
final Uri observatoryUrl = Uri.parse(stringArg(_kObservatoryUrl)!);
|
||||||
final FlutterVmService vmService = await connectToVmService(observatoryUrl, logger: globals.logger);
|
final FlutterVmService vmService = await connectToVmService(observatoryUrl, logger: globals.logger);
|
||||||
final vm_service.Response skp = await vmService.screenshotSkp();
|
final vm_service.Response? skp = await vmService.screenshotSkp();
|
||||||
if (skp == null) {
|
if (skp == null) {
|
||||||
globals.printError(
|
globals.printError(
|
||||||
'The Skia picture request failed, probably because the device was '
|
'The Skia picture request failed, probably because the device was '
|
||||||
@ -154,17 +152,17 @@ class ScreenshotCommand extends FlutterCommand {
|
|||||||
'skp',
|
'skp',
|
||||||
);
|
);
|
||||||
final IOSink sink = outputFile.openWrite();
|
final IOSink sink = outputFile.openWrite();
|
||||||
sink.add(base64.decode(skp.json['skp'] as String));
|
sink.add(base64.decode(skp.json?['skp'] as String));
|
||||||
await sink.close();
|
await sink.close();
|
||||||
_showOutputFileInfo(outputFile);
|
_showOutputFileInfo(outputFile);
|
||||||
_ensureOutputIsNotJsonRpcError(outputFile);
|
_ensureOutputIsNotJsonRpcError(outputFile);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> runRasterizer(File outputFile) async {
|
Future<bool> runRasterizer(File? outputFile) async {
|
||||||
final Uri observatoryUrl = Uri.parse(stringArg(_kObservatoryUrl));
|
final Uri observatoryUrl = Uri.parse(stringArg(_kObservatoryUrl)!);
|
||||||
final FlutterVmService vmService = await connectToVmService(observatoryUrl, logger: globals.logger);
|
final FlutterVmService vmService = await connectToVmService(observatoryUrl, logger: globals.logger);
|
||||||
final vm_service.Response response = await vmService.screenshot();
|
final vm_service.Response? response = await vmService.screenshot();
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
globals.printError(
|
globals.printError(
|
||||||
'The screenshot request failed, probably because the device was '
|
'The screenshot request failed, probably because the device was '
|
||||||
@ -178,7 +176,7 @@ class ScreenshotCommand extends FlutterCommand {
|
|||||||
'png',
|
'png',
|
||||||
);
|
);
|
||||||
final IOSink sink = outputFile.openWrite();
|
final IOSink sink = outputFile.openWrite();
|
||||||
sink.add(base64.decode(response.json['screenshot'] as String));
|
sink.add(base64.decode(response.json?['screenshot'] as String));
|
||||||
await sink.close();
|
await sink.close();
|
||||||
_showOutputFileInfo(outputFile);
|
_showOutputFileInfo(outputFile);
|
||||||
_ensureOutputIsNotJsonRpcError(outputFile);
|
_ensureOutputIsNotJsonRpcError(outputFile);
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.8
|
|
||||||
|
|
||||||
import 'package:completion/completion.dart';
|
import 'package:completion/completion.dart';
|
||||||
|
|
||||||
import '../base/common.dart';
|
import '../base/common.dart';
|
||||||
@ -15,8 +13,6 @@ class ShellCompletionCommand extends FlutterCommand {
|
|||||||
ShellCompletionCommand() {
|
ShellCompletionCommand() {
|
||||||
argParser.addFlag(
|
argParser.addFlag(
|
||||||
'overwrite',
|
'overwrite',
|
||||||
defaultsTo: false,
|
|
||||||
negatable: true,
|
|
||||||
help: 'Causes the given shell completion setup script to be overwritten if it already exists.',
|
help: 'Causes the given shell completion setup script to be overwritten if it already exists.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -42,21 +38,22 @@ class ShellCompletionCommand extends FlutterCommand {
|
|||||||
|
|
||||||
/// Return null to disable analytics recording of the `bash-completion` command.
|
/// Return null to disable analytics recording of the `bash-completion` command.
|
||||||
@override
|
@override
|
||||||
Future<String> get usagePath async => null;
|
Future<String?> get usagePath async => null;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<FlutterCommandResult> runCommand() async {
|
Future<FlutterCommandResult> runCommand() async {
|
||||||
if (argResults.rest.length > 1) {
|
final List<String> rest = argResults?.rest ?? <String>[];
|
||||||
|
if (rest.length > 1) {
|
||||||
throwToolExit('Too many arguments given to bash-completion command.', exitCode: 1);
|
throwToolExit('Too many arguments given to bash-completion command.', exitCode: 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argResults.rest.isEmpty || argResults.rest.first == '-') {
|
if (rest.isEmpty || rest.first == '-') {
|
||||||
final String script = generateCompletionScript(<String>['flutter']);
|
final String script = generateCompletionScript(<String>['flutter']);
|
||||||
globals.stdio.stdoutWrite(script);
|
globals.stdio.stdoutWrite(script);
|
||||||
return FlutterCommandResult.warning();
|
return FlutterCommandResult.warning();
|
||||||
}
|
}
|
||||||
|
|
||||||
final File outputFile = globals.fs.file(argResults.rest.first);
|
final File outputFile = globals.fs.file(rest.first);
|
||||||
if (outputFile.existsSync() && !boolArg('overwrite')) {
|
if (outputFile.existsSync() && !boolArg('overwrite')) {
|
||||||
throwToolExit(
|
throwToolExit(
|
||||||
'Output file ${outputFile.path} already exists, will not overwrite. '
|
'Output file ${outputFile.path} already exists, will not overwrite. '
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// @dart = 2.8
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
@ -24,8 +22,8 @@ import '../runner/flutter_command.dart';
|
|||||||
/// over stdout.
|
/// over stdout.
|
||||||
class SymbolizeCommand extends FlutterCommand {
|
class SymbolizeCommand extends FlutterCommand {
|
||||||
SymbolizeCommand({
|
SymbolizeCommand({
|
||||||
@required Stdio stdio,
|
required Stdio stdio,
|
||||||
@required FileSystem fileSystem,
|
required FileSystem fileSystem,
|
||||||
DwarfSymbolizationService dwarfSymbolizationService = const DwarfSymbolizationService(),
|
DwarfSymbolizationService dwarfSymbolizationService = const DwarfSymbolizationService(),
|
||||||
}) : _stdio = stdio,
|
}) : _stdio = stdio,
|
||||||
_fileSystem = fileSystem,
|
_fileSystem = fileSystem,
|
||||||
@ -67,13 +65,13 @@ class SymbolizeCommand extends FlutterCommand {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> validateCommand() {
|
Future<void> validateCommand() {
|
||||||
if (!argResults.wasParsed('debug-info')) {
|
if (argResults?.wasParsed('debug-info') != true) {
|
||||||
throwToolExit('"--debug-info" is required to symbolize stack traces.');
|
throwToolExit('"--debug-info" is required to symbolize stack traces.');
|
||||||
}
|
}
|
||||||
if (!_fileSystem.isFileSync(stringArg('debug-info'))) {
|
if (!_fileSystem.isFileSync(stringArg('debug-info')!)) {
|
||||||
throwToolExit('${stringArg('debug-info')} does not exist.');
|
throwToolExit('${stringArg('debug-info')} does not exist.');
|
||||||
}
|
}
|
||||||
if (argResults.wasParsed('input') && !_fileSystem.isFileSync(stringArg('input'))) {
|
if (argResults?.wasParsed('input') == true && !_fileSystem.isFileSync(stringArg('input')!)) {
|
||||||
throwToolExit('${stringArg('input')} does not exist.');
|
throwToolExit('${stringArg('input')} does not exist.');
|
||||||
}
|
}
|
||||||
return super.validateCommand();
|
return super.validateCommand();
|
||||||
@ -85,7 +83,7 @@ class SymbolizeCommand extends FlutterCommand {
|
|||||||
IOSink output;
|
IOSink output;
|
||||||
|
|
||||||
// Configure output to either specified file or stdout.
|
// Configure output to either specified file or stdout.
|
||||||
if (argResults.wasParsed('output')) {
|
if (argResults?.wasParsed('output') == true) {
|
||||||
final File outputFile = _fileSystem.file(stringArg('output'));
|
final File outputFile = _fileSystem.file(stringArg('output'));
|
||||||
if (!outputFile.parent.existsSync()) {
|
if (!outputFile.parent.existsSync()) {
|
||||||
outputFile.parent.createSync(recursive: true);
|
outputFile.parent.createSync(recursive: true);
|
||||||
@ -101,7 +99,7 @@ class SymbolizeCommand extends FlutterCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Configure input from either specified file or stdin.
|
// Configure input from either specified file or stdin.
|
||||||
if (argResults.wasParsed('input')) {
|
if (argResults?.wasParsed('input') == true) {
|
||||||
input = _fileSystem.file(stringArg('input')).openRead();
|
input = _fileSystem.file(stringArg('input')).openRead();
|
||||||
} else {
|
} else {
|
||||||
input = _stdio.stdin;
|
input = _stdio.stdin;
|
||||||
@ -121,7 +119,7 @@ class SymbolizeCommand extends FlutterCommand {
|
|||||||
typedef SymbolsTransformer = StreamTransformer<String, String> Function(Uint8List);
|
typedef SymbolsTransformer = StreamTransformer<String, String> Function(Uint8List);
|
||||||
|
|
||||||
StreamTransformer<String, String> _defaultTransformer(Uint8List symbols) {
|
StreamTransformer<String, String> _defaultTransformer(Uint8List symbols) {
|
||||||
final Dwarf dwarf = Dwarf.fromBytes(symbols);
|
final Dwarf? dwarf = Dwarf.fromBytes(symbols);
|
||||||
if (dwarf == null) {
|
if (dwarf == null) {
|
||||||
throwToolExit('Failed to decode symbols file');
|
throwToolExit('Failed to decode symbols file');
|
||||||
}
|
}
|
||||||
@ -137,7 +135,7 @@ StreamTransformer<String, String> _testTransformer(Uint8List buffer) {
|
|||||||
handleDone: (EventSink<String> sink) {
|
handleDone: (EventSink<String> sink) {
|
||||||
sink.close();
|
sink.close();
|
||||||
},
|
},
|
||||||
handleError: (dynamic error, StackTrace stackTrace, EventSink<String> sink) {
|
handleError: (Object error, StackTrace stackTrace, EventSink<String> sink) {
|
||||||
sink.addError(error, stackTrace);
|
sink.addError(error, stackTrace);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -167,12 +165,12 @@ class DwarfSymbolizationService {
|
|||||||
/// Throws a [ToolExit] if the symbols cannot be parsed or the stack trace
|
/// Throws a [ToolExit] if the symbols cannot be parsed or the stack trace
|
||||||
/// cannot be decoded.
|
/// cannot be decoded.
|
||||||
Future<void> decode({
|
Future<void> decode({
|
||||||
@required Stream<List<int>> input,
|
required Stream<List<int>> input,
|
||||||
@required IOSink output,
|
required IOSink output,
|
||||||
@required Uint8List symbols,
|
required Uint8List symbols,
|
||||||
}) async {
|
}) async {
|
||||||
final Completer<void> onDone = Completer<void>();
|
final Completer<void> onDone = Completer<void>();
|
||||||
StreamSubscription<void> subscription;
|
StreamSubscription<void>? subscription;
|
||||||
subscription = input
|
subscription = input
|
||||||
.cast<List<int>>()
|
.cast<List<int>>()
|
||||||
.transform(const Utf8Decoder())
|
.transform(const Utf8Decoder())
|
||||||
@ -182,7 +180,7 @@ class DwarfSymbolizationService {
|
|||||||
try {
|
try {
|
||||||
output.writeln(line);
|
output.writeln(line);
|
||||||
} on Exception catch(e, s) {
|
} on Exception catch(e, s) {
|
||||||
subscription.cancel().whenComplete(() {
|
subscription?.cancel().whenComplete(() {
|
||||||
if (!onDone.isCompleted) {
|
if (!onDone.isCompleted) {
|
||||||
onDone.completeError(e, s);
|
onDone.completeError(e, s);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ const List<String> kReservedKotlinKeywords = <String>['when', 'in'];
|
|||||||
/// Files in the destination will contain none of the '.tmpl', '.copy.tmpl',
|
/// Files in the destination will contain none of the '.tmpl', '.copy.tmpl',
|
||||||
/// 'img.tmpl', or '-<language>.tmpl' extensions.
|
/// 'img.tmpl', or '-<language>.tmpl' extensions.
|
||||||
class Template {
|
class Template {
|
||||||
factory Template(Directory templateSource, Directory imageSourceDir, {
|
factory Template(Directory templateSource, Directory? imageSourceDir, {
|
||||||
required FileSystem fileSystem,
|
required FileSystem fileSystem,
|
||||||
required Logger logger,
|
required Logger logger,
|
||||||
required TemplateRenderer templateRenderer,
|
required TemplateRenderer templateRenderer,
|
||||||
@ -46,7 +46,7 @@ class Template {
|
|||||||
}) {
|
}) {
|
||||||
return Template._(
|
return Template._(
|
||||||
<Directory>[templateSource],
|
<Directory>[templateSource],
|
||||||
<Directory>[imageSourceDir],
|
imageSourceDir != null ? <Directory>[imageSourceDir] : <Directory>[],
|
||||||
fileSystem: fileSystem,
|
fileSystem: fileSystem,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
templateRenderer: templateRenderer,
|
templateRenderer: templateRenderer,
|
||||||
|
Loading…
Reference in New Issue
Block a user