This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Emmanuel Garcia
committed
Feb 12, 2021
1 parent
197d976
commit e026242
Showing
20 changed files
with
2,722 additions
and
6 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule plugin_tools
deleted from
432c56
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!'); | ||
} | ||
} |
Oops, something went wrong.