Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 3f2e2ac

Browse files
Switch script/tools over to the new analysis options (#3777)
Removes the legacy analysis options override and fixes all resulting issues. This is a combination of dart fix and manual changes (mostly mechanical, but some small restructuring to address warnings more cleanly, such as creating typed structs from args when they are used repeatedly to avoid repeated casting, or making things that were unnecessarily public private). One small opportunistic extra cleanup is that the handling of null-safety prerelease versions is removed, as any new plugin would be written null-safe from the start, so we no longer need to allow those versions. Part of flutter/flutter#76229
1 parent 81aad8f commit 3f2e2ac

35 files changed

+675
-652
lines changed

script/tool/analysis_options.yaml

-1
This file was deleted.

script/tool/lib/src/analyze_command.dart

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import 'package:path/path.dart' as p;
99

1010
import 'common.dart';
1111

12+
/// A command to run Dart analysis on packages.
1213
class AnalyzeCommand extends PluginCommand {
14+
/// Creates a analysis command instance.
1315
AnalyzeCommand(
1416
Directory packagesDir,
1517
FileSystem fileSystem, {
@@ -31,9 +33,7 @@ class AnalyzeCommand extends PluginCommand {
3133
'This command requires "pub" and "flutter" to be in your path.';
3234

3335
@override
34-
Future<Null> run() async {
35-
checkSharding();
36-
36+
Future<void> run() async {
3737
print('Verifying analysis settings...');
3838
final List<FileSystemEntity> files = packagesDir.listSync(recursive: true);
3939
for (final FileSystemEntity file in files) {
@@ -42,8 +42,8 @@ class AnalyzeCommand extends PluginCommand {
4242
continue;
4343
}
4444

45-
final bool allowed = argResults[_customAnalysisFlag].any(
46-
(String directory) =>
45+
final bool allowed = (argResults[_customAnalysisFlag] as List<String>)
46+
.any((String directory) =>
4747
directory != null &&
4848
directory.isNotEmpty &&
4949
p.isWithin(p.join(packagesDir.path, directory), file.path));
@@ -62,7 +62,7 @@ class AnalyzeCommand extends PluginCommand {
6262
'pub', <String>['global', 'activate', 'tuneup'],
6363
workingDir: packagesDir, exitOnError: true);
6464

65-
await for (Directory package in getPackages()) {
65+
await for (final Directory package in getPackages()) {
6666
if (isFlutterPackage(package, fileSystem)) {
6767
await processRunner.runAndStream('flutter', <String>['packages', 'get'],
6868
workingDir: package, exitOnError: true);
@@ -73,7 +73,7 @@ class AnalyzeCommand extends PluginCommand {
7373
}
7474

7575
final List<String> failingPackages = <String>[];
76-
await for (Directory package in getPlugins()) {
76+
await for (final Directory package in getPlugins()) {
7777
final int exitCode = await processRunner.runAndStream(
7878
'pub', <String>['global', 'run', 'tuneup', 'check'],
7979
workingDir: package);
@@ -85,9 +85,9 @@ class AnalyzeCommand extends PluginCommand {
8585
print('\n\n');
8686
if (failingPackages.isNotEmpty) {
8787
print('The following packages have analyzer errors (see above):');
88-
failingPackages.forEach((String package) {
88+
for (final String package in failingPackages) {
8989
print(' * $package');
90-
});
90+
}
9191
throw ToolExit(1);
9292
}
9393

script/tool/lib/src/build_examples_command.dart

+34-25
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import 'package:platform/platform.dart';
1111

1212
import 'common.dart';
1313

14+
/// A command to build the example applications for packages.
1415
class BuildExamplesCommand extends PluginCommand {
16+
/// Creates an instance of the build command.
1517
BuildExamplesCommand(
1618
Directory packagesDir,
1719
FileSystem fileSystem, {
@@ -39,33 +41,40 @@ class BuildExamplesCommand extends PluginCommand {
3941
'This command requires "flutter" to be in your path.';
4042

4143
@override
42-
Future<Null> run() async {
43-
if (!argResults[kIpa] &&
44-
!argResults[kApk] &&
45-
!argResults[kLinux] &&
46-
!argResults[kMacos] &&
47-
!argResults[kWeb] &&
48-
!argResults[kWindows]) {
49-
print('None of --linux, --macos, --web, --windows, --apk, or --ipa were '
50-
'specified, so not building anything.');
44+
Future<void> run() async {
45+
final List<String> platformSwitches = <String>[
46+
kApk,
47+
kIpa,
48+
kLinux,
49+
kMacos,
50+
kWeb,
51+
kWindows,
52+
];
53+
final Map<String, bool> platforms = <String, bool>{
54+
for (final String platform in platformSwitches)
55+
platform: argResults[platform] as bool
56+
};
57+
if (!platforms.values.any((bool enabled) => enabled)) {
58+
print(
59+
'None of ${platformSwitches.map((String platform) => '--$platform').join(', ')} '
60+
'were specified, so not building anything.');
5161
return;
5262
}
5363
final String flutterCommand =
54-
LocalPlatform().isWindows ? 'flutter.bat' : 'flutter';
64+
const LocalPlatform().isWindows ? 'flutter.bat' : 'flutter';
5565

56-
final String enableExperiment = argResults[kEnableExperiment];
66+
final String enableExperiment = argResults[kEnableExperiment] as String;
5767

58-
checkSharding();
5968
final List<String> failingPackages = <String>[];
60-
await for (Directory plugin in getPlugins()) {
61-
for (Directory example in getExamplesForPlugin(plugin)) {
69+
await for (final Directory plugin in getPlugins()) {
70+
for (final Directory example in getExamplesForPlugin(plugin)) {
6271
final String packageName =
6372
p.relative(example.path, from: packagesDir.path);
6473

65-
if (argResults[kLinux]) {
74+
if (platforms[kLinux]) {
6675
print('\nBUILDING Linux for $packageName');
6776
if (isLinuxPlugin(plugin, fileSystem)) {
68-
int buildExitCode = await processRunner.runAndStream(
77+
final int buildExitCode = await processRunner.runAndStream(
6978
flutterCommand,
7079
<String>[
7180
'build',
@@ -82,10 +91,10 @@ class BuildExamplesCommand extends PluginCommand {
8291
}
8392
}
8493

85-
if (argResults[kMacos]) {
94+
if (platforms[kMacos]) {
8695
print('\nBUILDING macOS for $packageName');
8796
if (isMacOsPlugin(plugin, fileSystem)) {
88-
int exitCode = await processRunner.runAndStream(
97+
final int exitCode = await processRunner.runAndStream(
8998
flutterCommand,
9099
<String>[
91100
'build',
@@ -102,10 +111,10 @@ class BuildExamplesCommand extends PluginCommand {
102111
}
103112
}
104113

105-
if (argResults[kWeb]) {
114+
if (platforms[kWeb]) {
106115
print('\nBUILDING web for $packageName');
107116
if (isWebPlugin(plugin, fileSystem)) {
108-
int buildExitCode = await processRunner.runAndStream(
117+
final int buildExitCode = await processRunner.runAndStream(
109118
flutterCommand,
110119
<String>[
111120
'build',
@@ -122,10 +131,10 @@ class BuildExamplesCommand extends PluginCommand {
122131
}
123132
}
124133

125-
if (argResults[kWindows]) {
134+
if (platforms[kWindows]) {
126135
print('\nBUILDING Windows for $packageName');
127136
if (isWindowsPlugin(plugin, fileSystem)) {
128-
int buildExitCode = await processRunner.runAndStream(
137+
final int buildExitCode = await processRunner.runAndStream(
129138
flutterCommand,
130139
<String>[
131140
'build',
@@ -142,7 +151,7 @@ class BuildExamplesCommand extends PluginCommand {
142151
}
143152
}
144153

145-
if (argResults[kIpa]) {
154+
if (platforms[kIpa]) {
146155
print('\nBUILDING IPA for $packageName');
147156
if (isIosPlugin(plugin, fileSystem)) {
148157
final int exitCode = await processRunner.runAndStream(
@@ -163,7 +172,7 @@ class BuildExamplesCommand extends PluginCommand {
163172
}
164173
}
165174

166-
if (argResults[kApk]) {
175+
if (platforms[kApk]) {
167176
print('\nBUILDING APK for $packageName');
168177
if (isAndroidPlugin(plugin, fileSystem)) {
169178
final int exitCode = await processRunner.runAndStream(
@@ -188,7 +197,7 @@ class BuildExamplesCommand extends PluginCommand {
188197

189198
if (failingPackages.isNotEmpty) {
190199
print('The following build are failing (see above for details):');
191-
for (String package in failingPackages) {
200+
for (final String package in failingPackages) {
192201
print(' * $package');
193202
}
194203
throw ToolExit(1);

0 commit comments

Comments
 (0)