Unverified Commit 01e09ea8 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] add missing null-safety flags (#59773)

Some of the null-safety commands were missing - plumb them through. Ensure that verbose mode shows their output, and clean up the messaging around sound-null-safety.

Fixes #59769

Adds a test that validate each of the null safety supporting build commands has everything plumbed through.
parent 06de5678
...@@ -22,7 +22,7 @@ import 'build_web.dart'; ...@@ -22,7 +22,7 @@ import 'build_web.dart';
class BuildCommand extends FlutterCommand { class BuildCommand extends FlutterCommand {
BuildCommand({ bool verboseHelp = false }) { BuildCommand({ bool verboseHelp = false }) {
addSubcommand(BuildAarCommand()); addSubcommand(BuildAarCommand(verboseHelp: verboseHelp));
addSubcommand(BuildApkCommand(verboseHelp: verboseHelp)); addSubcommand(BuildApkCommand(verboseHelp: verboseHelp));
addSubcommand(BuildAppBundleCommand(verboseHelp: verboseHelp)); addSubcommand(BuildAppBundleCommand(verboseHelp: verboseHelp));
addSubcommand(BuildAotCommand()); addSubcommand(BuildAotCommand());
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart';
import '../android/android_builder.dart'; import '../android/android_builder.dart';
import '../android/gradle_utils.dart'; import '../android/gradle_utils.dart';
import '../base/common.dart'; import '../base/common.dart';
...@@ -17,7 +19,7 @@ import '../runner/flutter_command.dart' show FlutterCommandResult; ...@@ -17,7 +19,7 @@ import '../runner/flutter_command.dart' show FlutterCommandResult;
import 'build.dart'; import 'build.dart';
class BuildAarCommand extends BuildSubCommand { class BuildAarCommand extends BuildSubCommand {
BuildAarCommand() { BuildAarCommand({ @required bool verboseHelp }) {
argParser argParser
..addFlag( ..addFlag(
'debug', 'debug',
...@@ -41,7 +43,8 @@ class BuildAarCommand extends BuildSubCommand { ...@@ -41,7 +43,8 @@ class BuildAarCommand extends BuildSubCommand {
addSplitDebugInfoOption(); addSplitDebugInfoOption();
addDartObfuscationOption(); addDartObfuscationOption();
usesTrackWidgetCreation(verboseHelp: false); usesTrackWidgetCreation(verboseHelp: false);
addNullSafetyModeOptions(); addNullSafetyModeOptions(hide: !verboseHelp);
addEnableExperimentation(hide: !verboseHelp);
argParser argParser
..addMultiOption( ..addMultiOption(
'target-platform', 'target-platform',
......
...@@ -33,7 +33,7 @@ class BuildApkCommand extends BuildSubCommand { ...@@ -33,7 +33,7 @@ class BuildApkCommand extends BuildSubCommand {
addBundleSkSLPathOption(hide: !verboseHelp); addBundleSkSLPathOption(hide: !verboseHelp);
addEnableExperimentation(hide: !verboseHelp); addEnableExperimentation(hide: !verboseHelp);
addBuildPerformanceFile(hide: !verboseHelp); addBuildPerformanceFile(hide: !verboseHelp);
addNullSafetyModeOptions(); addNullSafetyModeOptions(hide: !verboseHelp);
argParser argParser
..addFlag('split-per-abi', ..addFlag('split-per-abi',
negatable: false, negatable: false,
......
...@@ -32,6 +32,8 @@ class BuildAppBundleCommand extends BuildSubCommand { ...@@ -32,6 +32,8 @@ class BuildAppBundleCommand extends BuildSubCommand {
addBundleSkSLPathOption(hide: !verboseHelp); addBundleSkSLPathOption(hide: !verboseHelp);
addBuildPerformanceFile(hide: !verboseHelp); addBuildPerformanceFile(hide: !verboseHelp);
usesTrackWidgetCreation(verboseHelp: verboseHelp); usesTrackWidgetCreation(verboseHelp: verboseHelp);
addNullSafetyModeOptions(hide: !verboseHelp);
addEnableExperimentation(hide: !verboseHelp);
argParser.addMultiOption('target-platform', argParser.addMultiOption('target-platform',
splitCommas: true, splitCommas: true,
defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'], defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'],
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../cache.dart'; import '../cache.dart';
...@@ -16,12 +18,13 @@ import 'build.dart'; ...@@ -16,12 +18,13 @@ import 'build.dart';
/// A command to build a Fuchsia target. /// A command to build a Fuchsia target.
class BuildFuchsiaCommand extends BuildSubCommand { class BuildFuchsiaCommand extends BuildSubCommand {
BuildFuchsiaCommand({bool verboseHelp = false}) { BuildFuchsiaCommand({ @required bool verboseHelp }) {
addTreeShakeIconsFlag(); addTreeShakeIconsFlag();
usesTargetOption(); usesTargetOption();
usesDartDefineOption(); usesDartDefineOption();
addBuildModeFlags(verboseHelp: verboseHelp); addBuildModeFlags(verboseHelp: verboseHelp);
addNullSafetyModeOptions(); addNullSafetyModeOptions(hide: !verboseHelp);
addEnableExperimentation(hide: !verboseHelp);
argParser.addOption( argParser.addOption(
'runner-source', 'runner-source',
help: 'The package source to use for the flutter_runner. ' help: 'The package source to use for the flutter_runner. '
......
...@@ -34,7 +34,7 @@ class BuildIOSCommand extends BuildSubCommand { ...@@ -34,7 +34,7 @@ class BuildIOSCommand extends BuildSubCommand {
addEnableExperimentation(hide: !verboseHelp); addEnableExperimentation(hide: !verboseHelp);
addBuildPerformanceFile(hide: !verboseHelp); addBuildPerformanceFile(hide: !verboseHelp);
addBundleSkSLPathOption(hide: !verboseHelp); addBundleSkSLPathOption(hide: !verboseHelp);
addNullSafetyModeOptions(); addNullSafetyModeOptions(hide: !verboseHelp);
argParser argParser
..addFlag('simulator', ..addFlag('simulator',
help: 'Build for the iOS simulator instead of the device. This changes ' help: 'Build for the iOS simulator instead of the device. This changes '
......
...@@ -29,7 +29,7 @@ class BuildLinuxCommand extends BuildSubCommand { ...@@ -29,7 +29,7 @@ class BuildLinuxCommand extends BuildSubCommand {
usesTrackWidgetCreation(verboseHelp: verboseHelp); usesTrackWidgetCreation(verboseHelp: verboseHelp);
addBuildPerformanceFile(hide: !verboseHelp); addBuildPerformanceFile(hide: !verboseHelp);
addBundleSkSLPathOption(hide: !verboseHelp); addBundleSkSLPathOption(hide: !verboseHelp);
addNullSafetyModeOptions(); addNullSafetyModeOptions(hide: !verboseHelp);
} }
@override @override
......
...@@ -30,7 +30,7 @@ class BuildMacosCommand extends BuildSubCommand { ...@@ -30,7 +30,7 @@ class BuildMacosCommand extends BuildSubCommand {
addEnableExperimentation(hide: !verboseHelp); addEnableExperimentation(hide: !verboseHelp);
addBuildPerformanceFile(hide: !verboseHelp); addBuildPerformanceFile(hide: !verboseHelp);
addBundleSkSLPathOption(hide: !verboseHelp); addBundleSkSLPathOption(hide: !verboseHelp);
addNullSafetyModeOptions(); addNullSafetyModeOptions(hide: !verboseHelp);
} }
@override @override
......
...@@ -25,7 +25,7 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -25,7 +25,7 @@ class BuildWebCommand extends BuildSubCommand {
addBuildModeFlags(excludeDebug: true); addBuildModeFlags(excludeDebug: true);
usesDartDefineOption(); usesDartDefineOption();
addEnableExperimentation(hide: !verboseHelp); addEnableExperimentation(hide: !verboseHelp);
addNullSafetyModeOptions(); addNullSafetyModeOptions(hide: !verboseHelp);
argParser.addFlag('web-initialize-platform', argParser.addFlag('web-initialize-platform',
defaultsTo: true, defaultsTo: true,
negatable: true, negatable: true,
......
...@@ -32,6 +32,7 @@ class BuildWindowsCommand extends BuildSubCommand { ...@@ -32,6 +32,7 @@ class BuildWindowsCommand extends BuildSubCommand {
usesTrackWidgetCreation(verboseHelp: verboseHelp); usesTrackWidgetCreation(verboseHelp: verboseHelp);
addBuildPerformanceFile(hide: !verboseHelp); addBuildPerformanceFile(hide: !verboseHelp);
addBundleSkSLPathOption(hide: !verboseHelp); addBundleSkSLPathOption(hide: !verboseHelp);
addNullSafetyModeOptions(hide: !verboseHelp);
} }
@override @override
......
...@@ -66,7 +66,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment ...@@ -66,7 +66,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
usesPubOption(); usesPubOption();
usesTrackWidgetCreation(verboseHelp: verboseHelp); usesTrackWidgetCreation(verboseHelp: verboseHelp);
usesIsolateFilterOption(hide: !verboseHelp); usesIsolateFilterOption(hide: !verboseHelp);
addNullSafetyModeOptions(); addNullSafetyModeOptions(hide: !verboseHelp);
usesDeviceUserOption(); usesDeviceUserOption();
} }
......
...@@ -31,7 +31,7 @@ class TestCommand extends FlutterCommand { ...@@ -31,7 +31,7 @@ class TestCommand extends FlutterCommand {
}) : assert(testWrapper != null) { }) : assert(testWrapper != null) {
requiresPubspecYaml(); requiresPubspecYaml();
usesPubOption(); usesPubOption();
addNullSafetyModeOptions(); addNullSafetyModeOptions(hide: !verboseHelp);
usesTrackWidgetCreation(verboseHelp: verboseHelp); usesTrackWidgetCreation(verboseHelp: verboseHelp);
addEnableExperimentation(hide: !verboseHelp); addEnableExperimentation(hide: !verboseHelp);
argParser argParser
......
...@@ -474,11 +474,15 @@ abstract class FlutterCommand extends Command<void> { ...@@ -474,11 +474,15 @@ abstract class FlutterCommand extends Command<void> {
); );
} }
void addNullSafetyModeOptions() { void addNullSafetyModeOptions({ @required bool hide }) {
argParser.addFlag(FlutterOptions.kNullSafety, argParser.addFlag(FlutterOptions.kNullSafety,
help: 'Whether to override the default null safety setting.', help:
'Whether to override the inferred null safety mode. This allows null-safe '
'libraries to depend on un-migrated (non-null safe) libraries. By default, '
'Flutter applications will attempt to run at the null safety level of their '
'entrypoint library (usually lib/main.dart).',
defaultsTo: null, defaultsTo: null,
hide: true, hide: hide,
); );
} }
...@@ -506,7 +510,7 @@ abstract class FlutterCommand extends Command<void> { ...@@ -506,7 +510,7 @@ abstract class FlutterCommand extends Command<void> {
); );
} }
void addEnableExperimentation({ bool hide = false }) { void addEnableExperimentation({ @required bool hide }) {
argParser.addMultiOption( argParser.addMultiOption(
FlutterOptions.kEnableExperiment, FlutterOptions.kEnableExperiment,
help: help:
......
...@@ -26,7 +26,7 @@ void main() { ...@@ -26,7 +26,7 @@ void main() {
Cache.disableLocking(); Cache.disableLocking();
Future<BuildAarCommand> runCommandIn(String target, { List<String> arguments }) async { Future<BuildAarCommand> runCommandIn(String target, { List<String> arguments }) async {
final BuildAarCommand command = BuildAarCommand(); final BuildAarCommand command = BuildAarCommand(verboseHelp: false);
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>[ await runner.run(<String>[
'aar', 'aar',
...@@ -282,7 +282,7 @@ Future<BuildAarCommand> runBuildAarCommand( ...@@ -282,7 +282,7 @@ Future<BuildAarCommand> runBuildAarCommand(
String target, { String target, {
List<String> arguments, List<String> arguments,
}) async { }) async {
final BuildAarCommand command = BuildAarCommand(); final BuildAarCommand command = BuildAarCommand(verboseHelp: false);
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>[ await runner.run(<String>[
'aar', 'aar',
......
// Copyright 2014 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:args/args.dart';
import 'package:flutter_tools/src/commands/build.dart';
import 'package:flutter_tools/src/commands/build_aar.dart';
import 'package:flutter_tools/src/commands/build_apk.dart';
import 'package:flutter_tools/src/commands/build_appbundle.dart';
import 'package:flutter_tools/src/commands/build_fuchsia.dart';
import 'package:flutter_tools/src/commands/build_ios.dart';
import 'package:flutter_tools/src/commands/build_linux.dart';
import 'package:flutter_tools/src/commands/build_macos.dart';
import 'package:flutter_tools/src/commands/build_web.dart';
import 'package:flutter_tools/src/commands/build_windows.dart';
import '../../src/common.dart';
import '../../src/context.dart';
void main() {
testUsingContext('All build commands support null safety options', () {
final List<BuildSubCommand> commands = <BuildSubCommand>[
BuildWindowsCommand(verboseHelp: false),
BuildLinuxCommand(verboseHelp: false),
BuildMacosCommand(verboseHelp: false),
BuildWebCommand(verboseHelp: false),
BuildApkCommand(verboseHelp: false),
BuildIOSCommand(verboseHelp: false),
BuildAppBundleCommand(verboseHelp: false),
BuildFuchsiaCommand(verboseHelp: false),
BuildAarCommand(verboseHelp: false),
];
for (final BuildSubCommand command in commands) {
final ArgResults results = command.argParser.parse(<String>[
'--sound-null-safety',
'--enable-experiment=non-nullable',
]);
expect(results.wasParsed('sound-null-safety'), true);
expect(results.wasParsed('enable-experiment'), true);
}
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment