Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
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
17 changes: 6 additions & 11 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ task:
<< : *MACOS_TEMPLATE
<< : *FLUTTER_UPGRADE_TEMPLATE
matrix:
### iOS+macOS tasks ***
- name: lint_darwin_plugins
script:
# TODO(jmagman): Lint macOS podspecs but skip any that fail library validation.
- find . -name "*.podspec" | xargs grep -l "osx" | xargs rm
- ./script/tool_runner.sh podspecs
### iOS tasks ###
- name: build_all_plugins_ipa
env:
Expand Down Expand Up @@ -251,14 +257,3 @@ task:
- ./script/tool_runner.sh build-examples --macos --no-ipa
drive_script:
- ./script/tool_runner.sh drive-examples --macos

task:
# Don't use FLUTTER_UPGRADE_TEMPLATE, Flutter tooling not needed.
<< : *MACOS_TEMPLATE
<< : *TOOL_SETUP_TEMPLATE
matrix:
- name: lint_darwin_plugins
script:
# TODO(jmagman): Lint macOS podspecs but skip any that fail library validation.
- find . -name "*.podspec" | xargs grep -l "osx" | xargs rm
- ./script/tool_runner.sh podspecs
2 changes: 2 additions & 0 deletions script/tool/bin/flutter_plugin_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9

export 'package:flutter_plugin_tools/src/main.dart';
6 changes: 4 additions & 2 deletions script/tool/lib/src/analyze_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9

import 'dart:async';

import 'package:file/file.dart';
Expand Down Expand Up @@ -42,8 +44,8 @@ class AnalyzeCommand extends PluginCommand {
continue;
}

final bool allowed = (argResults[_customAnalysisFlag] as List<String>)
.any((String directory) =>
final bool allowed = (getStringListArg(_customAnalysisFlag)).any(
(String directory) =>
directory != null &&
directory.isNotEmpty &&
p.isWithin(p.join(packagesDir.path, directory), file.path));
Expand Down
6 changes: 4 additions & 2 deletions script/tool/lib/src/build_examples_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9

import 'dart:async';
import 'dart:io' as io;

Expand Down Expand Up @@ -52,7 +54,7 @@ class BuildExamplesCommand extends PluginCommand {
];
final Map<String, bool> platforms = <String, bool>{
for (final String platform in platformSwitches)
platform: argResults[platform] as bool
platform: getBoolArg(platform)
};
if (!platforms.values.any((bool enabled) => enabled)) {
print(
Expand All @@ -63,7 +65,7 @@ class BuildExamplesCommand extends PluginCommand {
final String flutterCommand =
const LocalPlatform().isWindows ? 'flutter.bat' : 'flutter';

final String enableExperiment = argResults[kEnableExperiment] as String;
final String enableExperiment = getStringArg(kEnableExperiment);

final List<String> failingPackages = <String>[];
await for (final Directory plugin in getPlugins()) {
Expand Down
101 changes: 56 additions & 45 deletions script/tool/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import 'package:colorize/colorize.dart';
import 'package:file/file.dart';
import 'package:git/git.dart';
import 'package:http/http.dart' as http;
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';
import 'package:yaml/yaml.dart';

/// The signature for a print handler for commands that allow overriding the
/// print destination.
typedef Print = void Function(Object object);
typedef Print = void Function(Object? object);

/// Key for windows platform.
const String kWindows = 'windows';
Expand Down Expand Up @@ -50,7 +49,7 @@ const String kEnableExperiment = 'enable-experiment';

/// Returns whether the given directory contains a Flutter package.
bool isFlutterPackage(FileSystemEntity entity, FileSystem fileSystem) {
if (entity == null || entity is! Directory) {
if (entity is! Directory) {
return false;
}

Expand All @@ -59,7 +58,7 @@ bool isFlutterPackage(FileSystemEntity entity, FileSystem fileSystem) {
fileSystem.file(p.join(entity.path, 'pubspec.yaml'));
final YamlMap pubspecYaml =
loadYaml(pubspecFile.readAsStringSync()) as YamlMap;
final YamlMap dependencies = pubspecYaml['dependencies'] as YamlMap;
final YamlMap? dependencies = pubspecYaml['dependencies'] as YamlMap?;
if (dependencies == null) {
return false;
}
Expand Down Expand Up @@ -87,7 +86,7 @@ bool pluginSupportsPlatform(
platform == kMacos ||
platform == kWindows ||
platform == kLinux);
if (entity == null || entity is! Directory) {
if (entity is! Directory) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this since it is done in the very beginning of the method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the very beginning of the method :)

return false;
}

Expand All @@ -96,15 +95,15 @@ bool pluginSupportsPlatform(
fileSystem.file(p.join(entity.path, 'pubspec.yaml'));
final YamlMap pubspecYaml =
loadYaml(pubspecFile.readAsStringSync()) as YamlMap;
final YamlMap flutterSection = pubspecYaml['flutter'] as YamlMap;
final YamlMap? flutterSection = pubspecYaml['flutter'] as YamlMap?;
if (flutterSection == null) {
return false;
}
final YamlMap pluginSection = flutterSection['plugin'] as YamlMap;
final YamlMap? pluginSection = flutterSection['plugin'] as YamlMap?;
if (pluginSection == null) {
return false;
}
final YamlMap platforms = pluginSection['platforms'] as YamlMap;
final YamlMap? platforms = pluginSection['platforms'] as YamlMap?;
if (platforms == null) {
// Legacy plugin specs are assumed to support iOS and Android.
if (!pluginSection.containsKey('platforms')) {
Expand Down Expand Up @@ -151,7 +150,7 @@ bool isLinuxPlugin(FileSystemEntity entity, FileSystem fileSystem) {
}

/// Throws a [ToolExit] with `exitCode` and log the `errorMessage` in red.
void printErrorAndExit({@required String errorMessage, int exitCode = 1}) {
void printErrorAndExit({required String errorMessage, int exitCode = 1}) {
final Colorize redError = Colorize(errorMessage)..red();
print(redError);
throw ToolExit(exitCode);
Expand Down Expand Up @@ -236,30 +235,45 @@ abstract class PluginCommand extends Command<void> {
/// The git directory to use. By default it uses the parent directory.
///
/// This can be mocked for testing.
final GitDir gitDir;
final GitDir? gitDir;

int _shardIndex;
int _shardCount;
int? _shardIndex;
int? _shardCount;

/// The shard of the overall command execution that this instance should run.
int get shardIndex {
if (_shardIndex == null) {
_checkSharding();
}
return _shardIndex;
return _shardIndex!;
}

/// The number of shards this command is divided into.
int get shardCount {
if (_shardCount == null) {
_checkSharding();
}
return _shardCount;
return _shardCount!;
}

/// Convenience accessor for boolean arguments.
bool getBoolArg(String key) {
return (argResults![key] as bool?) ?? false;
}

/// Convenience accessor for String arguments.
String getStringArg(String key) {
return (argResults![key] as String?) ?? '';
}

/// Convenience accessor for List<String> arguments.
List<String> getStringListArg(String key) {
return (argResults![key] as List<String>?) ?? <String>[];
}

void _checkSharding() {
final int shardIndex = int.tryParse(argResults[_shardIndexArg] as String);
final int shardCount = int.tryParse(argResults[_shardCountArg] as String);
final int? shardIndex = int.tryParse(getStringArg(_shardIndexArg));
final int? shardCount = int.tryParse(getStringArg(_shardCountArg));
if (shardIndex == null) {
usageException('$_shardIndexArg must be an integer');
}
Expand Down Expand Up @@ -317,12 +331,10 @@ abstract class PluginCommand extends Command<void> {
/// is a sibling of the packages directory. This is used for a small number
/// of packages in the flutter/packages repository.
Stream<Directory> _getAllPlugins() async* {
Set<String> plugins =
Set<String>.from(argResults[_pluginsArg] as List<String>);
Set<String> plugins = Set<String>.from(getStringListArg(_pluginsArg));
final Set<String> excludedPlugins =
Set<String>.from(argResults[_excludeArg] as List<String>);
final bool runOnChangedPackages =
argResults[_runOnChangedPackagesArg] as bool;
Set<String>.from(getStringListArg(_excludeArg));
final bool runOnChangedPackages = getBoolArg(_runOnChangedPackagesArg);
if (plugins.isEmpty && runOnChangedPackages) {
plugins = await _getChangedPackages();
}
Expand Down Expand Up @@ -429,9 +441,9 @@ abstract class PluginCommand extends Command<void> {
/// Throws tool exit if [gitDir] nor root directory is a git directory.
Future<GitVersionFinder> retrieveVersionFinder() async {
final String rootDir = packagesDir.parent.absolute.path;
final String baseSha = argResults[_kBaseSha] as String;
final String baseSha = getStringArg(_kBaseSha);

GitDir baseGitDir = gitDir;
GitDir? baseGitDir = gitDir;
if (baseGitDir == null) {
if (!await GitDir.isGitDir(rootDir)) {
printErrorAndExit(
Expand Down Expand Up @@ -490,7 +502,7 @@ class ProcessRunner {
Future<int> runAndStream(
String executable,
List<String> args, {
Directory workingDir,
Directory? workingDir,
bool exitOnError = false,
}) async {
print(
Expand Down Expand Up @@ -522,7 +534,7 @@ class ProcessRunner {
///
/// Returns the [io.ProcessResult] of the [executable].
Future<io.ProcessResult> run(String executable, List<String> args,
{Directory workingDir,
{Directory? workingDir,
bool exitOnError = false,
bool logOnError = false,
Encoding stdoutEncoding = io.systemEncoding,
Expand Down Expand Up @@ -550,15 +562,15 @@ class ProcessRunner {
/// passing [workingDir].
///
/// Returns the started [io.Process].
Future<io.Process> start(String executable, List<String> args,
{Directory workingDirectory}) async {
Future<io.Process?> start(String executable, List<String> args,
{Directory? workingDirectory}) async {
final io.Process process = await io.Process.start(executable, args,
workingDirectory: workingDirectory?.path);
return process;
}

String _getErrorString(String executable, List<String> args,
{Directory workingDir}) {
{Directory? workingDir}) {
final String workdir = workingDir == null ? '' : ' in ${workingDir.path}';
return 'ERROR: Unable to execute "$executable ${args.join(' ')}"$workdir.';
}
Expand All @@ -569,7 +581,7 @@ class PubVersionFinder {
/// Constructor.
///
/// Note: you should manually close the [httpClient] when done using the finder.
PubVersionFinder({this.pubHost = defaultPubHost, @required this.httpClient});
PubVersionFinder({this.pubHost = defaultPubHost, required this.httpClient});

/// The default pub host to use.
static const String defaultPubHost = 'https://pub.dev';
Expand All @@ -584,8 +596,8 @@ class PubVersionFinder {

/// Get the package version on pub.
Future<PubVersionFinderResponse> getPackageVersion(
{@required String package}) async {
assert(package != null && package.isNotEmpty);
{required String package}) async {
assert(package.isNotEmpty);
final Uri pubHostUri = Uri.parse(pubHost);
final Uri url = pubHostUri.replace(path: '/packages/$package.json');
final http.Response response = await httpClient.get(url);
Expand Down Expand Up @@ -618,8 +630,8 @@ class PubVersionFinder {
class PubVersionFinderResponse {
/// Constructor.
PubVersionFinderResponse({this.versions, this.result, this.httpResponse}) {
if (versions != null && versions.isNotEmpty) {
versions.sort((Version a, Version b) {
if (versions != null && versions!.isNotEmpty) {
versions!.sort((Version a, Version b) {
// TODO(cyanglaz): Think about how to handle pre-release version with [Version.prioritize].
// https://github.com/flutter/flutter/issues/82222
return b.compareTo(a);
Expand All @@ -631,13 +643,13 @@ class PubVersionFinderResponse {
///
/// This is sorted by largest to smallest, so the first element in the list is the largest version.
/// Might be `null` if the [result] is not [PubVersionFinderResult.success].
final List<Version> versions;
final List<Version>? versions;

/// The result of the version finder.
final PubVersionFinderResult result;
final PubVersionFinderResult? result;

/// The response object of the http request.
final http.Response httpResponse;
final http.Response? httpResponse;
}

/// An enum representing the result of [PubVersionFinder].
Expand Down Expand Up @@ -667,7 +679,7 @@ class GitVersionFinder {
final GitDir baseGitDir;

/// The base sha used to get diff.
final String baseSha;
final String? baseSha;

static bool _isPubspec(String file) {
return file.trim().endsWith('pubspec.yaml');
Expand All @@ -684,8 +696,7 @@ class GitVersionFinder {
final io.ProcessResult changedFilesCommand = await baseGitDir
.runCommand(<String>['diff', '--name-only', baseSha, 'HEAD']);
print('Determine diff with base sha: $baseSha');
final String changedFilesStdout =
changedFilesCommand.stdout.toString() ?? '';
final String changedFilesStdout = changedFilesCommand.stdout.toString();
if (changedFilesStdout.isEmpty) {
return <String>[];
}
Expand All @@ -696,7 +707,8 @@ class GitVersionFinder {

/// Get the package version specified in the pubspec file in `pubspecPath` and
/// at the revision of `gitRef` (defaulting to the base if not provided).
Future<Version> getPackageVersion(String pubspecPath, {String gitRef}) async {
Future<Version?> getPackageVersion(String pubspecPath,
{String? gitRef}) async {
final String ref = gitRef ?? (await _getBaseSha());

io.ProcessResult gitShow;
Expand All @@ -707,20 +719,19 @@ class GitVersionFinder {
return null;
}
final String fileContent = gitShow.stdout as String;
final String versionString = loadYaml(fileContent)['version'] as String;
final String? versionString = loadYaml(fileContent)['version'] as String?;
return versionString == null ? null : Version.parse(versionString);
}

Future<String> _getBaseSha() async {
if (baseSha != null && baseSha.isNotEmpty) {
return baseSha;
if (baseSha != null && baseSha!.isNotEmpty) {
return baseSha!;
}

io.ProcessResult baseShaFromMergeBase = await baseGitDir.runCommand(
<String>['merge-base', '--fork-point', 'FETCH_HEAD', 'HEAD'],
throwOnError: false);
if (baseShaFromMergeBase == null ||
baseShaFromMergeBase.stderr != null ||
if (baseShaFromMergeBase.stderr != null ||
baseShaFromMergeBase.stdout == null) {
baseShaFromMergeBase = await baseGitDir
.runCommand(<String>['merge-base', 'FETCH_HEAD', 'HEAD']);
Expand Down
2 changes: 2 additions & 0 deletions script/tool/lib/src/create_all_plugins_app_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9

import 'dart:async';
import 'dart:io' as io;

Expand Down
Loading