Skip to content

Commit 52c191e

Browse files
Emmanuel Garciaadsonpleal
Emmanuel Garcia
authored andcommitted
Move plugin tools code (flutter#3544)
1 parent 908da30 commit 52c191e

20 files changed

+2722
-6
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

script/common.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ function check_changed_packages() {
4848

4949
# Runs the plugin tools from the plugin_tools git submodule.
5050
function plugin_tools() {
51-
(pushd "$REPO_DIR/script/plugin_tools" && dart pub get && popd) >/dev/null
52-
dart run "$REPO_DIR/script/plugin_tools/lib/src/main.dart" "$@"
51+
(pushd "$REPO_DIR/script/tool" && dart pub get && popd) >/dev/null
52+
dart run "$REPO_DIR/script/tool/lib/src/main.dart" "$@"
5353
}

script/plugin_tools

Lines changed: 0 additions & 1 deletion
This file was deleted.

script/tool/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Flutter Plugin Tools
2+
3+
To run the tool:
4+
5+
```sh
6+
dart pub get
7+
dart run lib/src/main.dart <args>
8+
```
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
import 'package:file/file.dart';
8+
import 'package:path/path.dart' as p;
9+
10+
import 'common.dart';
11+
12+
class AnalyzeCommand extends PluginCommand {
13+
AnalyzeCommand(
14+
Directory packagesDir,
15+
FileSystem fileSystem, {
16+
ProcessRunner processRunner = const ProcessRunner(),
17+
}) : super(packagesDir, fileSystem, processRunner: processRunner) {
18+
argParser.addMultiOption(_customAnalysisFlag,
19+
help:
20+
'Directories (comma seperated) that are allowed to have their own analysis options.',
21+
defaultsTo: <String>[]);
22+
}
23+
24+
static const String _customAnalysisFlag = 'custom-analysis';
25+
26+
@override
27+
final String name = 'analyze';
28+
29+
@override
30+
final String description = 'Analyzes all packages using package:tuneup.\n\n'
31+
'This command requires "pub" and "flutter" to be in your path.';
32+
33+
@override
34+
Future<Null> run() async {
35+
checkSharding();
36+
37+
print('Verifying analysis settings...');
38+
final List<FileSystemEntity> files = packagesDir.listSync(recursive: true);
39+
for (final FileSystemEntity file in files) {
40+
if (file.basename != 'analysis_options.yaml' &&
41+
file.basename != '.analysis_options') {
42+
continue;
43+
}
44+
45+
final bool whitelisted = argResults[_customAnalysisFlag].any(
46+
(String directory) =>
47+
p.isWithin(p.join(packagesDir.path, directory), file.path));
48+
if (whitelisted) {
49+
continue;
50+
}
51+
52+
print('Found an extra analysis_options.yaml in ${file.absolute.path}.');
53+
print(
54+
'If this was deliberate, pass the package to the analyze command with the --$_customAnalysisFlag flag and try again.');
55+
throw ToolExit(1);
56+
}
57+
58+
print('Activating tuneup package...');
59+
await processRunner.runAndStream(
60+
'pub', <String>['global', 'activate', 'tuneup'],
61+
workingDir: packagesDir, exitOnError: true);
62+
63+
await for (Directory package in getPackages()) {
64+
if (isFlutterPackage(package, fileSystem)) {
65+
await processRunner.runAndStream('flutter', <String>['packages', 'get'],
66+
workingDir: package, exitOnError: true);
67+
} else {
68+
await processRunner.runAndStream('pub', <String>['get'],
69+
workingDir: package, exitOnError: true);
70+
}
71+
}
72+
73+
final List<String> failingPackages = <String>[];
74+
await for (Directory package in getPlugins()) {
75+
final int exitCode = await processRunner.runAndStream(
76+
'pub', <String>['global', 'run', 'tuneup', 'check'],
77+
workingDir: package);
78+
if (exitCode != 0) {
79+
failingPackages.add(p.basename(package.path));
80+
}
81+
}
82+
83+
print('\n\n');
84+
if (failingPackages.isNotEmpty) {
85+
print('The following packages have analyzer errors (see above):');
86+
failingPackages.forEach((String package) {
87+
print(' * $package');
88+
});
89+
throw ToolExit(1);
90+
}
91+
92+
print('No analyzer errors found!');
93+
}
94+
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
import 'dart:io' as io;
7+
8+
import 'package:file/file.dart';
9+
import 'package:path/path.dart' as p;
10+
import 'package:platform/platform.dart';
11+
12+
import 'common.dart';
13+
14+
class BuildExamplesCommand extends PluginCommand {
15+
BuildExamplesCommand(
16+
Directory packagesDir,
17+
FileSystem fileSystem, {
18+
ProcessRunner processRunner = const ProcessRunner(),
19+
}) : super(packagesDir, fileSystem, processRunner: processRunner) {
20+
argParser.addFlag(kLinux, defaultsTo: false);
21+
argParser.addFlag(kMacos, defaultsTo: false);
22+
argParser.addFlag(kWindows, defaultsTo: false);
23+
argParser.addFlag(kIpa, defaultsTo: io.Platform.isMacOS);
24+
argParser.addFlag(kApk);
25+
argParser.addOption(
26+
kEnableExperiment,
27+
defaultsTo: '',
28+
help: 'Enables the given Dart SDK experiments.',
29+
);
30+
}
31+
32+
@override
33+
final String name = 'build-examples';
34+
35+
@override
36+
final String description =
37+
'Builds all example apps (IPA for iOS and APK for Android).\n\n'
38+
'This command requires "flutter" to be in your path.';
39+
40+
@override
41+
Future<Null> run() async {
42+
if (!argResults[kIpa] &&
43+
!argResults[kApk] &&
44+
!argResults[kLinux] &&
45+
!argResults[kMacos] &&
46+
!argResults[kWindows]) {
47+
print(
48+
'None of --linux, --macos, --windows, --apk nor --ipa were specified, '
49+
'so not building anything.');
50+
return;
51+
}
52+
final String flutterCommand =
53+
LocalPlatform().isWindows ? 'flutter.bat' : 'flutter';
54+
55+
final String enableExperiment = argResults[kEnableExperiment];
56+
57+
checkSharding();
58+
final List<String> failingPackages = <String>[];
59+
await for (Directory plugin in getPlugins()) {
60+
for (Directory example in getExamplesForPlugin(plugin)) {
61+
final String packageName =
62+
p.relative(example.path, from: packagesDir.path);
63+
64+
if (argResults[kLinux]) {
65+
print('\nBUILDING Linux for $packageName');
66+
if (isLinuxPlugin(plugin, fileSystem)) {
67+
int buildExitCode = await processRunner.runAndStream(
68+
flutterCommand,
69+
<String>[
70+
'build',
71+
kLinux,
72+
if (enableExperiment.isNotEmpty)
73+
'--enable-experiment=$enableExperiment',
74+
],
75+
workingDir: example);
76+
if (buildExitCode != 0) {
77+
failingPackages.add('$packageName (linux)');
78+
}
79+
} else {
80+
print('Linux is not supported by this plugin');
81+
}
82+
}
83+
84+
if (argResults[kMacos]) {
85+
print('\nBUILDING macOS for $packageName');
86+
if (isMacOsPlugin(plugin, fileSystem)) {
87+
// TODO(https://github.com/flutter/flutter/issues/46236):
88+
// Builing macos without running flutter pub get first results
89+
// in an error.
90+
int exitCode = await processRunner.runAndStream(
91+
flutterCommand, <String>['pub', 'get'],
92+
workingDir: example);
93+
if (exitCode != 0) {
94+
failingPackages.add('$packageName (macos)');
95+
} else {
96+
exitCode = await processRunner.runAndStream(
97+
flutterCommand,
98+
<String>[
99+
'build',
100+
kMacos,
101+
if (enableExperiment.isNotEmpty)
102+
'--enable-experiment=$enableExperiment',
103+
],
104+
workingDir: example);
105+
if (exitCode != 0) {
106+
failingPackages.add('$packageName (macos)');
107+
}
108+
}
109+
} else {
110+
print('macOS is not supported by this plugin');
111+
}
112+
}
113+
114+
if (argResults[kWindows]) {
115+
print('\nBUILDING Windows for $packageName');
116+
if (isWindowsPlugin(plugin, fileSystem)) {
117+
int buildExitCode = await processRunner.runAndStream(
118+
flutterCommand,
119+
<String>[
120+
'build',
121+
kWindows,
122+
if (enableExperiment.isNotEmpty)
123+
'--enable-experiment=$enableExperiment',
124+
],
125+
workingDir: example);
126+
if (buildExitCode != 0) {
127+
failingPackages.add('$packageName (windows)');
128+
}
129+
} else {
130+
print('Windows is not supported by this plugin');
131+
}
132+
}
133+
134+
if (argResults[kIpa]) {
135+
print('\nBUILDING IPA for $packageName');
136+
if (isIosPlugin(plugin, fileSystem)) {
137+
final int exitCode = await processRunner.runAndStream(
138+
flutterCommand,
139+
<String>[
140+
'build',
141+
'ios',
142+
'--no-codesign',
143+
if (enableExperiment.isNotEmpty)
144+
'--enable-experiment=$enableExperiment',
145+
],
146+
workingDir: example);
147+
if (exitCode != 0) {
148+
failingPackages.add('$packageName (ipa)');
149+
}
150+
} else {
151+
print('iOS is not supported by this plugin');
152+
}
153+
}
154+
155+
if (argResults[kApk]) {
156+
print('\nBUILDING APK for $packageName');
157+
if (isAndroidPlugin(plugin, fileSystem)) {
158+
final int exitCode = await processRunner.runAndStream(
159+
flutterCommand,
160+
<String>[
161+
'build',
162+
'apk',
163+
if (enableExperiment.isNotEmpty)
164+
'--enable-experiment=$enableExperiment',
165+
],
166+
workingDir: example);
167+
if (exitCode != 0) {
168+
failingPackages.add('$packageName (apk)');
169+
}
170+
} else {
171+
print('Android is not supported by this plugin');
172+
}
173+
}
174+
}
175+
}
176+
print('\n\n');
177+
178+
if (failingPackages.isNotEmpty) {
179+
print('The following build are failing (see above for details):');
180+
for (String package in failingPackages) {
181+
print(' * $package');
182+
}
183+
throw ToolExit(1);
184+
}
185+
186+
print('All builds successful!');
187+
}
188+
}

0 commit comments

Comments
 (0)