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

Move plugin tools code #3544

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

4 changes: 2 additions & 2 deletions script/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ function check_changed_packages() {

# Runs the plugin tools from the plugin_tools git submodule.
function plugin_tools() {
(pushd "$REPO_DIR/script/plugin_tools" && dart pub get && popd) >/dev/null
dart run "$REPO_DIR/script/plugin_tools/lib/src/main.dart" "$@"
(pushd "$REPO_DIR/script/tool" && dart pub get && popd) >/dev/null
dart run "$REPO_DIR/script/tool/lib/src/main.dart" "$@"
}
1 change: 0 additions & 1 deletion script/plugin_tools
Submodule plugin_tools deleted from 432c56
8 changes: 8 additions & 0 deletions script/tool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Flutter Plugin Tools

To run the tool:

```sh
dart pub get
dart run lib/src/main.dart <args>
```
94 changes: 94 additions & 0 deletions script/tool/lib/src/analyze_command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2017 The Chromium 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 'dart:async';

import 'package:file/file.dart';
import 'package:path/path.dart' as p;

import 'common.dart';

class AnalyzeCommand extends PluginCommand {
AnalyzeCommand(
Directory packagesDir,
FileSystem fileSystem, {
ProcessRunner processRunner = const ProcessRunner(),
}) : super(packagesDir, fileSystem, processRunner: processRunner) {
argParser.addMultiOption(_customAnalysisFlag,
help:
'Directories (comma seperated) that are allowed to have their own analysis options.',
defaultsTo: <String>[]);
}

static const String _customAnalysisFlag = 'custom-analysis';

@override
final String name = 'analyze';

@override
final String description = 'Analyzes all packages using package:tuneup.\n\n'
'This command requires "pub" and "flutter" to be in your path.';

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

print('Verifying analysis settings...');
final List<FileSystemEntity> files = packagesDir.listSync(recursive: true);
for (final FileSystemEntity file in files) {
if (file.basename != 'analysis_options.yaml' &&
file.basename != '.analysis_options') {
continue;
}

final bool whitelisted = argResults[_customAnalysisFlag].any(
(String directory) =>
p.isWithin(p.join(packagesDir.path, directory), file.path));
if (whitelisted) {
continue;
}

print('Found an extra analysis_options.yaml in ${file.absolute.path}.');
print(
'If this was deliberate, pass the package to the analyze command with the --$_customAnalysisFlag flag and try again.');
throw ToolExit(1);
}

print('Activating tuneup package...');
await processRunner.runAndStream(
'pub', <String>['global', 'activate', 'tuneup'],
workingDir: packagesDir, exitOnError: true);

await for (Directory package in getPackages()) {
if (isFlutterPackage(package, fileSystem)) {
await processRunner.runAndStream('flutter', <String>['packages', 'get'],
workingDir: package, exitOnError: true);
} else {
await processRunner.runAndStream('pub', <String>['get'],
workingDir: package, exitOnError: true);
}
}

final List<String> failingPackages = <String>[];
await for (Directory package in getPlugins()) {
final int exitCode = await processRunner.runAndStream(
'pub', <String>['global', 'run', 'tuneup', 'check'],
workingDir: package);
if (exitCode != 0) {
failingPackages.add(p.basename(package.path));
}
}

print('\n\n');
if (failingPackages.isNotEmpty) {
print('The following packages have analyzer errors (see above):');
failingPackages.forEach((String package) {
print(' * $package');
});
throw ToolExit(1);
}

print('No analyzer errors found!');
}
}
188 changes: 188 additions & 0 deletions script/tool/lib/src/build_examples_command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
// Copyright 2017 The Chromium 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 'dart:async';
import 'dart:io' as io;

import 'package:file/file.dart';
import 'package:path/path.dart' as p;
import 'package:platform/platform.dart';

import 'common.dart';

class BuildExamplesCommand extends PluginCommand {
BuildExamplesCommand(
Directory packagesDir,
FileSystem fileSystem, {
ProcessRunner processRunner = const ProcessRunner(),
}) : super(packagesDir, fileSystem, processRunner: processRunner) {
argParser.addFlag(kLinux, defaultsTo: false);
argParser.addFlag(kMacos, defaultsTo: false);
argParser.addFlag(kWindows, defaultsTo: false);
argParser.addFlag(kIpa, defaultsTo: io.Platform.isMacOS);
argParser.addFlag(kApk);
argParser.addOption(
kEnableExperiment,
defaultsTo: '',
help: 'Enables the given Dart SDK experiments.',
);
}

@override
final String name = 'build-examples';

@override
final String description =
'Builds all example apps (IPA for iOS and APK for Android).\n\n'
'This command requires "flutter" to be in your path.';

@override
Future<Null> run() async {
if (!argResults[kIpa] &&
!argResults[kApk] &&
!argResults[kLinux] &&
!argResults[kMacos] &&
!argResults[kWindows]) {
print(
'None of --linux, --macos, --windows, --apk nor --ipa were specified, '
'so not building anything.');
return;
}
final String flutterCommand =
LocalPlatform().isWindows ? 'flutter.bat' : 'flutter';

final String enableExperiment = argResults[kEnableExperiment];

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

if (argResults[kLinux]) {
print('\nBUILDING Linux for $packageName');
if (isLinuxPlugin(plugin, fileSystem)) {
int buildExitCode = await processRunner.runAndStream(
flutterCommand,
<String>[
'build',
kLinux,
if (enableExperiment.isNotEmpty)
'--enable-experiment=$enableExperiment',
],
workingDir: example);
if (buildExitCode != 0) {
failingPackages.add('$packageName (linux)');
}
} else {
print('Linux is not supported by this plugin');
}
}

if (argResults[kMacos]) {
print('\nBUILDING macOS for $packageName');
if (isMacOsPlugin(plugin, fileSystem)) {
// TODO(https://github.com/flutter/flutter/issues/46236):
// Builing macos without running flutter pub get first results
// in an error.
int exitCode = await processRunner.runAndStream(
flutterCommand, <String>['pub', 'get'],
workingDir: example);
if (exitCode != 0) {
failingPackages.add('$packageName (macos)');
} else {
exitCode = await processRunner.runAndStream(
flutterCommand,
<String>[
'build',
kMacos,
if (enableExperiment.isNotEmpty)
'--enable-experiment=$enableExperiment',
],
workingDir: example);
if (exitCode != 0) {
failingPackages.add('$packageName (macos)');
}
}
} else {
print('macOS is not supported by this plugin');
}
}

if (argResults[kWindows]) {
print('\nBUILDING Windows for $packageName');
if (isWindowsPlugin(plugin, fileSystem)) {
int buildExitCode = await processRunner.runAndStream(
flutterCommand,
<String>[
'build',
kWindows,
if (enableExperiment.isNotEmpty)
'--enable-experiment=$enableExperiment',
],
workingDir: example);
if (buildExitCode != 0) {
failingPackages.add('$packageName (windows)');
}
} else {
print('Windows is not supported by this plugin');
}
}

if (argResults[kIpa]) {
print('\nBUILDING IPA for $packageName');
if (isIosPlugin(plugin, fileSystem)) {
final int exitCode = await processRunner.runAndStream(
flutterCommand,
<String>[
'build',
'ios',
'--no-codesign',
if (enableExperiment.isNotEmpty)
'--enable-experiment=$enableExperiment',
],
workingDir: example);
if (exitCode != 0) {
failingPackages.add('$packageName (ipa)');
}
} else {
print('iOS is not supported by this plugin');
}
}

if (argResults[kApk]) {
print('\nBUILDING APK for $packageName');
if (isAndroidPlugin(plugin, fileSystem)) {
final int exitCode = await processRunner.runAndStream(
flutterCommand,
<String>[
'build',
'apk',
if (enableExperiment.isNotEmpty)
'--enable-experiment=$enableExperiment',
],
workingDir: example);
if (exitCode != 0) {
failingPackages.add('$packageName (apk)');
}
} else {
print('Android is not supported by this plugin');
}
}
}
}
print('\n\n');

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

print('All builds successful!');
}
}
Loading