Skip to content

Commit

Permalink
Switch script/tools over to the new analysis options (flutter#3777)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stuartmorgan authored Apr 6, 2021
1 parent 81aad8f commit 3f2e2ac
Show file tree
Hide file tree
Showing 35 changed files with 675 additions and 652 deletions.
1 change: 0 additions & 1 deletion script/tool/analysis_options.yaml

This file was deleted.

18 changes: 9 additions & 9 deletions script/tool/lib/src/analyze_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import 'package:path/path.dart' as p;

import 'common.dart';

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

@override
Future<Null> run() async {
checkSharding();

Future<void> run() async {
print('Verifying analysis settings...');
final List<FileSystemEntity> files = packagesDir.listSync(recursive: true);
for (final FileSystemEntity file in files) {
Expand All @@ -42,8 +42,8 @@ class AnalyzeCommand extends PluginCommand {
continue;
}

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

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

final List<String> failingPackages = <String>[];
await for (Directory package in getPlugins()) {
await for (final Directory package in getPlugins()) {
final int exitCode = await processRunner.runAndStream(
'pub', <String>['global', 'run', 'tuneup', 'check'],
workingDir: package);
Expand All @@ -85,9 +85,9 @@ class AnalyzeCommand extends PluginCommand {
print('\n\n');
if (failingPackages.isNotEmpty) {
print('The following packages have analyzer errors (see above):');
failingPackages.forEach((String package) {
for (final String package in failingPackages) {
print(' * $package');
});
}
throw ToolExit(1);
}

Expand Down
59 changes: 34 additions & 25 deletions script/tool/lib/src/build_examples_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import 'package:platform/platform.dart';

import 'common.dart';

/// A command to build the example applications for packages.
class BuildExamplesCommand extends PluginCommand {
/// Creates an instance of the build command.
BuildExamplesCommand(
Directory packagesDir,
FileSystem fileSystem, {
Expand Down Expand Up @@ -39,33 +41,40 @@ class BuildExamplesCommand extends PluginCommand {
'This command requires "flutter" to be in your path.';

@override
Future<Null> run() async {
if (!argResults[kIpa] &&
!argResults[kApk] &&
!argResults[kLinux] &&
!argResults[kMacos] &&
!argResults[kWeb] &&
!argResults[kWindows]) {
print('None of --linux, --macos, --web, --windows, --apk, or --ipa were '
'specified, so not building anything.');
Future<void> run() async {
final List<String> platformSwitches = <String>[
kApk,
kIpa,
kLinux,
kMacos,
kWeb,
kWindows,
];
final Map<String, bool> platforms = <String, bool>{
for (final String platform in platformSwitches)
platform: argResults[platform] as bool
};
if (!platforms.values.any((bool enabled) => enabled)) {
print(
'None of ${platformSwitches.map((String platform) => '--$platform').join(', ')} '
'were specified, so not building anything.');
return;
}
final String flutterCommand =
LocalPlatform().isWindows ? 'flutter.bat' : 'flutter';
const LocalPlatform().isWindows ? 'flutter.bat' : 'flutter';

final String enableExperiment = argResults[kEnableExperiment];
final String enableExperiment = argResults[kEnableExperiment] as String;

checkSharding();
final List<String> failingPackages = <String>[];
await for (Directory plugin in getPlugins()) {
for (Directory example in getExamplesForPlugin(plugin)) {
await for (final Directory plugin in getPlugins()) {
for (final Directory example in getExamplesForPlugin(plugin)) {
final String packageName =
p.relative(example.path, from: packagesDir.path);

if (argResults[kLinux]) {
if (platforms[kLinux]) {
print('\nBUILDING Linux for $packageName');
if (isLinuxPlugin(plugin, fileSystem)) {
int buildExitCode = await processRunner.runAndStream(
final int buildExitCode = await processRunner.runAndStream(
flutterCommand,
<String>[
'build',
Expand All @@ -82,10 +91,10 @@ class BuildExamplesCommand extends PluginCommand {
}
}

if (argResults[kMacos]) {
if (platforms[kMacos]) {
print('\nBUILDING macOS for $packageName');
if (isMacOsPlugin(plugin, fileSystem)) {
int exitCode = await processRunner.runAndStream(
final int exitCode = await processRunner.runAndStream(
flutterCommand,
<String>[
'build',
Expand All @@ -102,10 +111,10 @@ class BuildExamplesCommand extends PluginCommand {
}
}

if (argResults[kWeb]) {
if (platforms[kWeb]) {
print('\nBUILDING web for $packageName');
if (isWebPlugin(plugin, fileSystem)) {
int buildExitCode = await processRunner.runAndStream(
final int buildExitCode = await processRunner.runAndStream(
flutterCommand,
<String>[
'build',
Expand All @@ -122,10 +131,10 @@ class BuildExamplesCommand extends PluginCommand {
}
}

if (argResults[kWindows]) {
if (platforms[kWindows]) {
print('\nBUILDING Windows for $packageName');
if (isWindowsPlugin(plugin, fileSystem)) {
int buildExitCode = await processRunner.runAndStream(
final int buildExitCode = await processRunner.runAndStream(
flutterCommand,
<String>[
'build',
Expand All @@ -142,7 +151,7 @@ class BuildExamplesCommand extends PluginCommand {
}
}

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

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

if (failingPackages.isNotEmpty) {
print('The following build are failing (see above for details):');
for (String package in failingPackages) {
for (final String package in failingPackages) {
print(' * $package');
}
throw ToolExit(1);
Expand Down
Loading

0 comments on commit 3f2e2ac

Please sign in to comment.