From da8e15b2235e1e6267788d0330b1d500fff66b3d Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 24 Aug 2021 20:43:02 -0400 Subject: [PATCH 01/10] WIP --- .../tool/lib/src/common/plugin_command.dart | 52 ++++++++- .../tool/test/common/plugin_command_test.dart | 105 ++++++++++++++++++ 2 files changed, 151 insertions(+), 6 deletions(-) diff --git a/script/tool/lib/src/common/plugin_command.dart b/script/tool/lib/src/common/plugin_command.dart index ec51261ab617..ffaebb056327 100644 --- a/script/tool/lib/src/common/plugin_command.dart +++ b/script/tool/lib/src/common/plugin_command.dart @@ -4,6 +4,7 @@ import 'dart:math'; +import 'package:args/args.dart'; import 'package:args/command_runner.dart'; import 'package:file/file.dart'; import 'package:git/git.dart'; @@ -72,11 +73,18 @@ abstract class PluginCommand extends Command { ); argParser.addFlag(_runOnChangedPackagesArg, help: 'Run the command on changed packages/plugins.\n' - 'If the $_packagesArg is specified, this flag is ignored.\n' 'If no packages have changed, or if there have been changes that may\n' 'affect all packages, the command runs on all packages.\n' 'The packages excluded with $_excludeArg is also excluded even if changed.\n' - 'See $_kBaseSha if a custom base is needed to determine the diff.'); + 'See $_kBaseSha if a custom base is needed to determine the diff.\n\n' + 'Cannot be combined with $_packagesArg.\n'); + argParser.addFlag(_packagesForBranchArg, + help: + 'This runs on all packages (equivalent to no package selection flag)\n' + 'on master, and behaves like --run-on-changed-packages on any other branch.\n\n' + 'Cannot be combined with $_packagesArg.\n\n' + 'This is intended for use in CI.\n', + hide: true); argParser.addOption(_kBaseSha, help: 'The base sha used to determine git diff. \n' 'This is useful when $_runOnChangedPackagesArg is specified.\n' @@ -89,6 +97,7 @@ abstract class PluginCommand extends Command { static const String _shardCountArg = 'shardCount'; static const String _excludeArg = 'exclude'; static const String _runOnChangedPackagesArg = 'run-on-changed-packages'; + static const String _packagesForBranchArg = 'packages-for-branch'; static const String _kBaseSha = 'base-sha'; /// The directory containing the plugin packages. @@ -266,14 +275,41 @@ abstract class PluginCommand extends Command { /// is a sibling of the packages directory. This is used for a small number /// of packages in the flutter/packages repository. Stream _getAllPackages() async* { + final Set packageSelectionFlags = { + _packagesArg, + _runOnChangedPackagesArg, + _packagesForBranchArg, + }; + if (packageSelectionFlags + .where((String flag) => argResults!.wasParsed(flag)) + .length > + 1) { + printError('Only one of --$_packagesArg, --$_runOnChangedPackagesArg, or ' + '--$_packagesForBranchArg can be provided.'); + throw ToolExit(exitInvalidArguments); + } + Set plugins = Set.from(getStringListArg(_packagesArg)); + final bool runOnChangedPackages; + if (getBoolArg(_runOnChangedPackagesArg)) { + runOnChangedPackages = true; + } else if (getBoolArg(_packagesForBranchArg)) { + final String? branch = await _getBranch(); + if (branch == null) { + printError('Unabled to determine branch; --$_packagesForBranchArg can ' + 'only be used in a git repository.'); + throw ToolExit(exitInvalidArguments); + } else { + runOnChangedPackages = branch != 'master'; + } + } else { + runOnChangedPackages = plugins.isEmpty; + } + final Set excludedPluginNames = getExcludedPackageNames(); - final bool runOnChangedPackages = getBoolArg(_runOnChangedPackagesArg); - if (plugins.isEmpty && - runOnChangedPackages && - !(await _changesRequireFullTest())) { + if (runOnChangedPackages && !(await _changesRequireFullTest())) { plugins = await _getChangedPackages(); } @@ -398,6 +434,10 @@ abstract class PluginCommand extends Command { return packages; } + Future _getBranch() async { + return null; + } + // Returns true if one or more files changed that have the potential to affect // any plugin (e.g., CI script changes). Future _changesRequireFullTest() async { diff --git a/script/tool/test/common/plugin_command_test.dart b/script/tool/test/common/plugin_command_test.dart index 10bdff4e9c56..efd68f4b8bea 100644 --- a/script/tool/test/common/plugin_command_test.dart +++ b/script/tool/test/common/plugin_command_test.dart @@ -7,6 +7,7 @@ import 'dart:io'; import 'package:args/command_runner.dart'; import 'package:file/file.dart'; import 'package:file/memory.dart'; +import 'package:flutter_plugin_tools/src/common/core.dart'; import 'package:flutter_plugin_tools/src/common/plugin_command.dart'; import 'package:flutter_plugin_tools/src/common/process_runner.dart'; import 'package:git/git.dart'; @@ -30,6 +31,7 @@ void main() { late Directory thirdPartyPackagesDir; late List?> gitDirCommands; late String gitDiffResponse; + late String gitRevParseResponse; setUp(() { fileSystem = MemoryFileSystem(); @@ -41,6 +43,7 @@ void main() { gitDirCommands = ?>[]; gitDiffResponse = ''; + gitRevParseResponse = ''; final MockGitDir gitDir = MockGitDir(); when(gitDir.runCommand(any, throwOnError: anyNamed('throwOnError'))) .thenAnswer((Invocation invocation) { @@ -49,6 +52,9 @@ void main() { if (invocation.positionalArguments[0][0] == 'diff') { when(mockProcessResult.stdout as String?) .thenReturn(gitDiffResponse); + } else if (invocation.positionalArguments[0][0] == 'rev-parse') { + when(mockProcessResult.stdout as String?) + .thenReturn(gitRevParseResponse); } return Future.value(mockProcessResult); }); @@ -184,6 +190,68 @@ void main() { expect(command.plugins, unorderedEquals([])); }); + group('conflicting package selecetion', () { + test('does not allow --packages with --run-on-changed-packages', + () async { + Error? commandError; + final List output = await runCapturingPrint(runner, [ + 'sample', + '--run-on-changed-packages', + '--packages=plugin1', + ], errorHandler: (Error e) { + commandError = e; + }); + + expect(commandError, isA()); + expect( + output, + containsAllInOrder([ + contains('Only one of --packages, --run-on-changed-packages, or ' + '--packages-for-branch can be provided.') + ])); + }); + + test('does not allow --packages with --packages-for-branch', () async { + Error? commandError; + final List output = await runCapturingPrint(runner, [ + 'sample', + '--packages-for-branch', + '--packages=plugin1', + ], errorHandler: (Error e) { + commandError = e; + }); + + expect(commandError, isA()); + expect( + output, + containsAllInOrder([ + contains('Only one of --packages, --run-on-changed-packages, or ' + '--packages-for-branch can be provided.') + ])); + }); + + test( + 'does not allow --run-on-changed-packages with --packages-for-branch', + () async { + Error? commandError; + final List output = await runCapturingPrint(runner, [ + 'sample', + '--packages-for-branch', + '--packages=plugin1', + ], errorHandler: (Error e) { + commandError = e; + }); + + expect(commandError, isA()); + expect( + output, + containsAllInOrder([ + contains('Only one of --packages, --run-on-changed-packages, or ' + '--packages-for-branch can be provided.') + ])); + }); + }); + group('test run-on-changed-packages', () { test('all plugins should be tested if there are no changes.', () async { final Directory plugin1 = createFakePlugin('plugin1', packagesDir); @@ -459,6 +527,43 @@ packages/plugin3/plugin3.dart }); }); + group('--packages-for-branch', () { + test('only tests changed packages on a branch', () async { + gitDiffResponse = 'packages/plugin1/plugin1.dart'; + gitRevParseResponse = 'a-branch'; + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + createFakePlugin('plugin2', packagesDir); + await runCapturingPrint( + runner, ['sample', '--pacakages-for-branch']); + + expect(command.plugins, unorderedEquals([plugin1.path])); + }); + + test('tests all packages on master', () async { + gitDiffResponse = 'packages/plugin1/plugin1.dart'; + gitRevParseResponse = 'master'; + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); + await runCapturingPrint( + runner, ['sample', '--pacakages-for-branch']); + + expect(command.plugins, + unorderedEquals([plugin1.path, plugin2.path])); + }); + + test('tests all packages if getting the branch fails', () async { + gitDiffResponse = 'packages/plugin1/plugin1.dart'; + gitRevParseResponse = ''; + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); + await runCapturingPrint( + runner, ['sample', '--pacakages-for-branch']); + + expect(command.plugins, + unorderedEquals([plugin1.path, plugin2.path])); + }); + }); + group('sharding', () { test('distributes evenly when evenly divisible', () async { final List> expectedShards = >[ From 7c74f7dc76278d069677e164e8eba36415904b2e Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 30 Aug 2021 13:33:15 -0400 Subject: [PATCH 02/10] Move branch behavioral switch from tool_runner.sh to a new tool flag --- script/tool/CHANGELOG.md | 2 + .../tool/lib/src/common/plugin_command.dart | 42 ++-- .../tool/test/common/plugin_command_test.dart | 186 ++++++++++-------- script/tool_runner.sh | 10 +- 4 files changed, 131 insertions(+), 109 deletions(-) diff --git a/script/tool/CHANGELOG.md b/script/tool/CHANGELOG.md index 634360461c8d..06aa7d65d325 100644 --- a/script/tool/CHANGELOG.md +++ b/script/tool/CHANGELOG.md @@ -9,6 +9,8 @@ `--no-push-flags`. Releases now always tag and push. - **Breaking change**: `publish`'s `--package` flag has been replaced with the `--packages` flag used by most other packages. +- **Breaking change** Passing both `--run-on-changed-packages` and `--packages` + is now an error; previously it the former would be ignored. ## 0.5.0 diff --git a/script/tool/lib/src/common/plugin_command.dart b/script/tool/lib/src/common/plugin_command.dart index ffaebb056327..1fb66cdf9484 100644 --- a/script/tool/lib/src/common/plugin_command.dart +++ b/script/tool/lib/src/common/plugin_command.dart @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:io' as io; import 'dart:math'; -import 'package:args/args.dart'; import 'package:args/command_runner.dart'; import 'package:file/file.dart'; import 'package:git/git.dart'; @@ -302,15 +302,23 @@ abstract class PluginCommand extends Command { throw ToolExit(exitInvalidArguments); } else { runOnChangedPackages = branch != 'master'; + // Log the mode for auditing what was intended to run. + print('--$_packagesForBranchArg: running on ' + '${runOnChangedPackages ? 'changed' : 'all'} packages'); } } else { - runOnChangedPackages = plugins.isEmpty; + runOnChangedPackages = false; } final Set excludedPluginNames = getExcludedPackageNames(); - if (runOnChangedPackages && !(await _changesRequireFullTest())) { - plugins = await _getChangedPackages(); + if (runOnChangedPackages) { + final GitVersionFinder gitVersionFinder = await retrieveVersionFinder(); + final List changedFiles = + await gitVersionFinder.getChangedFiles(); + if (!_changesRequireFullTest(changedFiles)) { + plugins = _getChangedPackages(changedFiles); + } } final Directory thirdPartyPackagesDirectory = packagesDir.parent @@ -410,14 +418,10 @@ abstract class PluginCommand extends Command { return gitVersionFinder; } - // Returns packages that have been changed relative to the git base. - Future> _getChangedPackages() async { - final GitVersionFinder gitVersionFinder = await retrieveVersionFinder(); - - final List allChangedFiles = - await gitVersionFinder.getChangedFiles(); + // Returns packages that have been changed given a list of changed files. + Set _getChangedPackages(List changedFiles) { final Set packages = {}; - for (final String path in allChangedFiles) { + for (final String path in changedFiles) { final List pathComponents = path.split('/'); final int packagesIndex = pathComponents.indexWhere((String element) => element == 'packages'); @@ -435,14 +439,18 @@ abstract class PluginCommand extends Command { } Future _getBranch() async { - return null; + final io.ProcessResult branchResult = await (await gitDir).runCommand( + ['rev-parse', '--abbrev-ref', 'HEAD'], + throwOnError: false); + if (branchResult.exitCode != 0) { + return null; + } + return (branchResult.stdout as String).trim(); } // Returns true if one or more files changed that have the potential to affect // any plugin (e.g., CI script changes). - Future _changesRequireFullTest() async { - final GitVersionFinder gitVersionFinder = await retrieveVersionFinder(); - + bool _changesRequireFullTest(List changedFiles) { const List specialFiles = [ '.ci.yaml', // LUCI config. '.cirrus.yml', // Cirrus config. @@ -457,9 +465,7 @@ abstract class PluginCommand extends Command { // check below is done via string prefixing. assert(specialDirectories.every((String dir) => dir.endsWith('/'))); - final List allChangedFiles = - await gitVersionFinder.getChangedFiles(); - return allChangedFiles.any((String path) => + return changedFiles.any((String path) => specialFiles.contains(path) || specialDirectories.any((String dir) => path.startsWith(dir))); } diff --git a/script/tool/test/common/plugin_command_test.dart b/script/tool/test/common/plugin_command_test.dart index efd68f4b8bea..7703f4b40c93 100644 --- a/script/tool/test/common/plugin_command_test.dart +++ b/script/tool/test/common/plugin_command_test.dart @@ -29,9 +29,6 @@ void main() { late MockPlatform mockPlatform; late Directory packagesDir; late Directory thirdPartyPackagesDir; - late List?> gitDirCommands; - late String gitDiffResponse; - late String gitRevParseResponse; setUp(() { fileSystem = MemoryFileSystem(); @@ -41,22 +38,15 @@ void main() { .childDirectory('third_party') .childDirectory('packages'); - gitDirCommands = ?>[]; - gitDiffResponse = ''; - gitRevParseResponse = ''; final MockGitDir gitDir = MockGitDir(); when(gitDir.runCommand(any, throwOnError: anyNamed('throwOnError'))) .thenAnswer((Invocation invocation) { - gitDirCommands.add(invocation.positionalArguments[0] as List?); - final MockProcessResult mockProcessResult = MockProcessResult(); - if (invocation.positionalArguments[0][0] == 'diff') { - when(mockProcessResult.stdout as String?) - .thenReturn(gitDiffResponse); - } else if (invocation.positionalArguments[0][0] == 'rev-parse') { - when(mockProcessResult.stdout as String?) - .thenReturn(gitRevParseResponse); - } - return Future.value(mockProcessResult); + final List arguments = + invocation.positionalArguments[0]! as List; + // Attach the first argument to the command to make targeting the mock + // results easier. + final String gitCommand = arguments.removeAt(0); + return processRunner.run('git-$gitCommand', arguments); }); processRunner = RecordingProcessRunner(); command = SamplePluginCommand( @@ -269,7 +259,9 @@ void main() { test( 'all plugins should be tested if there are no plugin related changes.', () async { - gitDiffResponse = 'AUTHORS'; + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: 'AUTHORS'), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir); final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runCapturingPrint(runner, [ @@ -283,10 +275,12 @@ void main() { }); test('all plugins should be tested if .cirrus.yml changes.', () async { - gitDiffResponse = ''' + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: ''' .cirrus.yml packages/plugin1/CHANGELOG -'''; +'''), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir); final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runCapturingPrint(runner, [ @@ -300,10 +294,12 @@ packages/plugin1/CHANGELOG }); test('all plugins should be tested if .ci.yaml changes', () async { - gitDiffResponse = ''' + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: ''' .ci.yaml packages/plugin1/CHANGELOG -'''; +'''), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir); final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runCapturingPrint(runner, [ @@ -318,10 +314,12 @@ packages/plugin1/CHANGELOG test('all plugins should be tested if anything in .ci/ changes', () async { - gitDiffResponse = ''' + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: ''' .ci/Dockerfile packages/plugin1/CHANGELOG -'''; +'''), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir); final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runCapturingPrint(runner, [ @@ -336,10 +334,12 @@ packages/plugin1/CHANGELOG test('all plugins should be tested if anything in script changes.', () async { - gitDiffResponse = ''' + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: ''' script/tool_runner.sh packages/plugin1/CHANGELOG -'''; +'''), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir); final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runCapturingPrint(runner, [ @@ -354,10 +354,12 @@ packages/plugin1/CHANGELOG test('all plugins should be tested if the root analysis options change.', () async { - gitDiffResponse = ''' + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: ''' analysis_options.yaml packages/plugin1/CHANGELOG -'''; +'''), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir); final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runCapturingPrint(runner, [ @@ -372,10 +374,12 @@ packages/plugin1/CHANGELOG test('all plugins should be tested if formatting options change.', () async { - gitDiffResponse = ''' + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: ''' .clang-format packages/plugin1/CHANGELOG -'''; +'''), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir); final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runCapturingPrint(runner, [ @@ -389,7 +393,9 @@ packages/plugin1/CHANGELOG }); test('Only changed plugin should be tested.', () async { - gitDiffResponse = 'packages/plugin1/plugin1.dart'; + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: 'packages/plugin1/plugin1.dart'), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir); createFakePlugin('plugin2', packagesDir); await runCapturingPrint(runner, [ @@ -403,10 +409,12 @@ packages/plugin1/CHANGELOG test('multiple files in one plugin should also test the plugin', () async { - gitDiffResponse = ''' + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: ''' packages/plugin1/plugin1.dart packages/plugin1/ios/plugin1.m -'''; +'''), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir); createFakePlugin('plugin2', packagesDir); await runCapturingPrint(runner, [ @@ -420,10 +428,12 @@ packages/plugin1/ios/plugin1.m test('multiple plugins changed should test all the changed plugins', () async { - gitDiffResponse = ''' + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: ''' packages/plugin1/plugin1.dart packages/plugin2/ios/plugin2.m -'''; +'''), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir); final Directory plugin2 = createFakePlugin('plugin2', packagesDir); createFakePlugin('plugin3', packagesDir); @@ -440,11 +450,13 @@ packages/plugin2/ios/plugin2.m test( 'multiple plugins inside the same plugin group changed should output the plugin group name', () async { - gitDiffResponse = ''' + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: ''' packages/plugin1/plugin1/plugin1.dart packages/plugin1/plugin1_platform_interface/plugin1_platform_interface.dart packages/plugin1/plugin1_web/plugin1_web.dart -'''; +'''), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir.childDirectory('plugin1')); createFakePlugin('plugin2', packagesDir); @@ -461,9 +473,11 @@ packages/plugin1/plugin1_web/plugin1_web.dart test( 'changing one plugin in a federated group should include all plugins in the group', () async { - gitDiffResponse = ''' + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: ''' packages/plugin1/plugin1/plugin1.dart -'''; +'''), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir.childDirectory('plugin1')); final Directory plugin2 = createFakePlugin('plugin1_platform_interface', @@ -482,35 +496,14 @@ packages/plugin1/plugin1/plugin1.dart [plugin1.path, plugin2.path, plugin3.path])); }); - test( - '--packages flag overrides the behavior of --run-on-changed-packages', - () async { - gitDiffResponse = ''' -packages/plugin1/plugin1.dart -packages/plugin2/ios/plugin2.m -packages/plugin3/plugin3.dart -'''; - final Directory plugin1 = - createFakePlugin('plugin1', packagesDir.childDirectory('plugin1')); - final Directory plugin2 = createFakePlugin('plugin2', packagesDir); - createFakePlugin('plugin3', packagesDir); - await runCapturingPrint(runner, [ - 'sample', - '--packages=plugin1,plugin2', - '--base-sha=master', - '--run-on-changed-packages' - ]); - - expect(command.plugins, - unorderedEquals([plugin1.path, plugin2.path])); - }); - test('--exclude flag works with --run-on-changed-packages', () async { - gitDiffResponse = ''' + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: ''' packages/plugin1/plugin1.dart packages/plugin2/ios/plugin2.m packages/plugin3/plugin3.dart -'''; +'''), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir.childDirectory('plugin1')); createFakePlugin('plugin2', packagesDir); @@ -529,38 +522,69 @@ packages/plugin3/plugin3.dart group('--packages-for-branch', () { test('only tests changed packages on a branch', () async { - gitDiffResponse = 'packages/plugin1/plugin1.dart'; - gitRevParseResponse = 'a-branch'; + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: 'packages/plugin1/plugin1.dart'), + ]; + processRunner.mockProcessesForExecutable['git-rev-parse'] = [ + MockProcess(stdout: 'a-branch'), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir); createFakePlugin('plugin2', packagesDir); - await runCapturingPrint( - runner, ['sample', '--pacakages-for-branch']); + + final List output = await runCapturingPrint( + runner, ['sample', '--packages-for-branch']); expect(command.plugins, unorderedEquals([plugin1.path])); + expect( + output, + containsAllInOrder([ + contains('--packages-for-branch: running on changed packages'), + ])); }); test('tests all packages on master', () async { - gitDiffResponse = 'packages/plugin1/plugin1.dart'; - gitRevParseResponse = 'master'; + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: 'packages/plugin1/plugin1.dart'), + ]; + processRunner.mockProcessesForExecutable['git-rev-parse'] = [ + MockProcess(stdout: 'master'), + ]; final Directory plugin1 = createFakePlugin('plugin1', packagesDir); final Directory plugin2 = createFakePlugin('plugin2', packagesDir); - await runCapturingPrint( - runner, ['sample', '--pacakages-for-branch']); + + final List output = await runCapturingPrint( + runner, ['sample', '--packages-for-branch']); expect(command.plugins, unorderedEquals([plugin1.path, plugin2.path])); + expect( + output, + containsAllInOrder([ + contains('--packages-for-branch: running on all packages'), + ])); }); - test('tests all packages if getting the branch fails', () async { - gitDiffResponse = 'packages/plugin1/plugin1.dart'; - gitRevParseResponse = ''; - final Directory plugin1 = createFakePlugin('plugin1', packagesDir); - final Directory plugin2 = createFakePlugin('plugin2', packagesDir); - await runCapturingPrint( - runner, ['sample', '--pacakages-for-branch']); + test('throws if getting the branch fails', () async { + processRunner.mockProcessesForExecutable['git-diff'] = [ + MockProcess(stdout: 'packages/plugin1/plugin1.dart'), + ]; + processRunner.mockProcessesForExecutable['git-rev-parse'] = [ + MockProcess(exitCode: 1), + ]; - expect(command.plugins, - unorderedEquals([plugin1.path, plugin2.path])); + Error? commandError; + final List output = await runCapturingPrint( + runner, ['sample', '--packages-for-branch'], + errorHandler: (Error e) { + commandError = e; + }); + + expect(commandError, isA()); + expect( + output, + containsAllInOrder([ + contains('Unabled to determine branch'), + ])); }); }); @@ -730,5 +754,3 @@ class SamplePluginCommand extends PluginCommand { } } } - -class MockProcessResult extends Mock implements ProcessResult {} diff --git a/script/tool_runner.sh b/script/tool_runner.sh index 93a7776d0a35..d6b74f038b2c 100755 --- a/script/tool_runner.sh +++ b/script/tool_runner.sh @@ -16,16 +16,8 @@ function plugin_tools() { ACTIONS=("$@") -BRANCH_NAME="${BRANCH_NAME:-"$(git rev-parse --abbrev-ref HEAD)"}" - # This has to be turned into a list and then split out to the command line, # otherwise it gets treated as a single argument. PLUGIN_SHARDING=($PLUGIN_SHARDING) -if [[ "${BRANCH_NAME}" == "master" ]]; then - echo "Running for all packages" - (cd "$REPO_DIR" && plugin_tools "${ACTIONS[@]}" ${PLUGIN_SHARDING[@]}) -else - echo running "${ACTIONS[@]}" - (cd "$REPO_DIR" && plugin_tools "${ACTIONS[@]}" --run-on-changed-packages ${PLUGIN_SHARDING[@]}) -fi +(cd "$REPO_DIR" && plugin_tools "${ACTIONS[@]}" --packages-for-branch ${PLUGIN_SHARDING[@]}) From 31ba457122b84a3364a9ced3b18b08c991960187 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 25 Aug 2021 16:32:17 -0400 Subject: [PATCH 03/10] Simplify tool_runner.sh --- script/tool_runner.sh | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/script/tool_runner.sh b/script/tool_runner.sh index d6b74f038b2c..99bab387e6b6 100755 --- a/script/tool_runner.sh +++ b/script/tool_runner.sh @@ -5,19 +5,18 @@ set -e +# WARNING! Do not remove this script, or change its behavior, unless you have +# verified that it will not break the flutter/flutter analysis run of this +# repository: https://github.com/flutter/flutter/blob/master/dev/bots/test.dart + readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" readonly REPO_DIR="$(dirname "$SCRIPT_DIR")" +readonly TOOL_PATH="$REPO_DIR/script/tool/bin/flutter_plugin_tools.dart" -# Runs the plugin tools from the in-tree source. -function plugin_tools() { - (pushd "$REPO_DIR/script/tool" && dart pub get && popd) >/dev/null - dart run "$REPO_DIR/script/tool/bin/flutter_plugin_tools.dart" "$@" -} - -ACTIONS=("$@") - -# This has to be turned into a list and then split out to the command line, -# otherwise it gets treated as a single argument. -PLUGIN_SHARDING=($PLUGIN_SHARDING) +# Ensure that the tool dependencies have been fetched. +(pushd "$REPO_DIR/script/tool" && dart pub get && popd) >/dev/null -(cd "$REPO_DIR" && plugin_tools "${ACTIONS[@]}" --packages-for-branch ${PLUGIN_SHARDING[@]}) +# The tool expects to be run from the repo root. +cd "$REPO_DIR" +# Run from the in-tree source. +dart run "$TOOL_PATH" "$@" --packages-for-branch $PLUGIN_SHARDING From 243ba40c60caacd1d098700d67e3600342eeb328 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 30 Aug 2021 15:02:55 -0400 Subject: [PATCH 04/10] Remove all but one use of tool_runner.sh --- .cirrus.yml | 56 +++++++++++++++++------------ script/configs/custom_analysis.yaml | 6 ++-- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index d830a2a15913..c5e0faf71475 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -6,6 +6,10 @@ only_if: $CIRRUS_TAG == '' env: CHANNEL: "master" # Default to master when not explicitly set by a task. PLUGIN_TOOL: "./script/tool/bin/flutter_plugin_tools.dart" + # The base command flags for most tool invocations, handling: + # - running the correct set of packages for the current branch + # - including any sharding that is configured for a task via $PLUGIN_SHARDING + COMMON_FLAGS: --packages-for-branch $PLUGIN_SHARDING tool_setup_template: &TOOL_SETUP_TEMPLATE tool_setup_script: @@ -68,11 +72,11 @@ task: - cd script/tool - CIRRUS_BUILD_ID=null pub run test - name: publishable - version_check_script: ./script/tool_runner.sh version-check - publish_check_script: ./script/tool_runner.sh publish-check + version_check_script: dart $PLUGIN_TOOL version-check $COMMON_FLAGS + publish_check_script: dart $PLUGIN_TOOL publish-check $COMMON_FLAGS - name: format - format_script: ./script/tool_runner.sh format --fail-on-change - pubspec_script: ./script/tool_runner.sh pubspec-check + format_script: dart $PLUGIN_TOOL format --fail-on-change $COMMON_FLAGS + pubspec_script: dart $PLUGIN_TOOL pubspec-check $COMMON_FLAGS license_script: dart $PLUGIN_TOOL license-check - name: test env: @@ -80,7 +84,7 @@ task: CHANNEL: "master" CHANNEL: "stable" test_script: - - ./script/tool_runner.sh test + - dart $PLUGIN_TOOL test $COMMON_FLAGS - name: analyze env: matrix: @@ -90,8 +94,12 @@ task: - cd script/tool - dart analyze --fatal-infos script: - # DO NOT change the custom-analysis argument here without changing the Dart repo. + # DO NOT change anything about this command without changing the + # dart-lang/sdk and flutter/flutter repositories first. # See the comment in script/configs/custom_analysis.yaml for details. + # This deliberately still uses tool_runner.sh to ensure that changes + # that would cause this command to fail show up here, not in the other + # repositories. - ./script/tool_runner.sh analyze --custom-analysis=script/configs/custom_analysis.yaml ### Android tasks ### - name: build_all_plugins_apk @@ -126,9 +134,9 @@ task: CHANNEL: "stable" build_script: - flutter config --enable-linux-desktop - - ./script/tool_runner.sh build-examples --linux + - dart $PLUGIN_TOOL build-examples --linux $COMMON_FLAGS drive_script: - - xvfb-run ./script/tool_runner.sh drive-examples --linux + - xvfb-run dart $PLUGIN_TOOL drive-examples --linux $COMMON_FLAGS # Heavy-workload Linux tasks. # These use machines with more CPUs and memory, so will reduce parallelization @@ -164,14 +172,15 @@ task: # TODO(stuartmorgan): See https://github.com/flutter/flutter/issues/24935 - export CIRRUS_CHANGE_MESSAGE="" - export CIRRUS_COMMIT_MESSAGE="" - - ./script/tool_runner.sh build-examples --apk + - dart $PLUGIN_TOOL build-examples --apk $COMMON_FLAGS lint_script: # Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they # might include non-ASCII characters which makes Gradle crash. # TODO(stuartmorgan): See https://github.com/flutter/flutter/issues/24935 - export CIRRUS_CHANGE_MESSAGE="" - export CIRRUS_COMMIT_MESSAGE="" - - ./script/tool_runner.sh lint-android # must come after build-examples + # Must come after build-examples. + - dart $PLUGIN_TOOL lint-android $COMMON_FLAGS native_unit_test_script: # Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they # might include non-ASCII characters which makes Gradle crash. @@ -180,7 +189,8 @@ task: - export CIRRUS_COMMIT_MESSAGE="" # Native integration tests are handled by firebase-test-lab below, so # only run unit tests. - - ./script/tool_runner.sh native-test --android --no-integration # must come after apk build + # Must come after build-examples. + - dart $PLUGIN_TOOL native-test --android --no-integration $COMMON_FLAGS firebase_test_lab_script: # Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they # might include non-ASCII characters which makes Gradle crash. @@ -189,7 +199,7 @@ task: - export CIRRUS_COMMIT_MESSAGE="" - if [[ -n "$GCLOUD_FIREBASE_TESTLAB_KEY" ]]; then - echo $GCLOUD_FIREBASE_TESTLAB_KEY > ${HOME}/gcloud-service-key.json - - ./script/tool_runner.sh firebase-test-lab --device model=flame,version=29 --device model=starqlteue,version=26 --exclude=script/configs/exclude_integration_android.yaml + - dart $PLUGIN_TOOL firebase-test-lab --device model=flame,version=29 --device model=starqlteue,version=26 --exclude=script/configs/exclude_integration_android.yaml $COMMON_FLAGS - else - echo "This user does not have permission to run Firebase Test Lab tests." - fi @@ -212,9 +222,9 @@ task: - dart lib/web_driver_installer.dart chromedriver --install-only - ./chromedriver/chromedriver --port=4444 & build_script: - - ./script/tool_runner.sh build-examples --web + - dart $PLUGIN_TOOL build-examples --web $COMMON_FLAGS drive_script: - - ./script/tool_runner.sh drive-examples --web --exclude=script/configs/exclude_integration_web.yaml + - dart $PLUGIN_TOOL drive-examples --web --exclude=script/configs/exclude_integration_web.yaml $COMMON_FLAGS # macOS tasks. task: @@ -224,7 +234,7 @@ task: ### iOS+macOS tasks *** - name: lint_darwin_plugins script: - - ./script/tool_runner.sh podspecs + - dart $PLUGIN_TOOL podspecs $COMMON_FLAGS ### iOS tasks ### - name: build_all_plugins_ipa env: @@ -249,16 +259,16 @@ task: - xcrun simctl list - xcrun simctl create Flutter-iPhone com.apple.CoreSimulator.SimDeviceType.iPhone-11 com.apple.CoreSimulator.SimRuntime.iOS-14-5 | xargs xcrun simctl boot build_script: - - ./script/tool_runner.sh build-examples --ios + - dart $PLUGIN_TOOL build-examples --ios $COMMON_FLAGS xcode_analyze_script: - - ./script/tool_runner.sh xcode-analyze --ios + - dart $PLUGIN_TOOL xcode-analyze --ios $COMMON_FLAGS native_test_script: - - ./script/tool_runner.sh native-test --ios --ios-destination "platform=iOS Simulator,name=iPhone 11,OS=latest" + - dart $PLUGIN_TOOL native-test --ios --ios-destination "platform=iOS Simulator,name=iPhone 11,OS=latest" $COMMON_FLAGS drive_script: # `drive-examples` contains integration tests, which changes the UI of the application. # This UI change sometimes affects `xctest`. # So we run `drive-examples` after `native-test`; changing the order will result ci failure. - - ./script/tool_runner.sh drive-examples --ios --exclude=script/configs/exclude_integration_ios.yaml + - dart $PLUGIN_TOOL drive-examples --ios --exclude=script/configs/exclude_integration_ios.yaml $COMMON_FLAGS ### macOS desktop tasks ### - name: build_all_plugins_macos env: @@ -277,10 +287,10 @@ task: PATH: $PATH:/usr/local/bin build_script: - flutter config --enable-macos-desktop - - ./script/tool_runner.sh build-examples --macos + - dart $PLUGIN_TOOL build-examples --macos $COMMON_FLAGS xcode_analyze_script: - - ./script/tool_runner.sh xcode-analyze --macos + - dart $PLUGIN_TOOL xcode-analyze --macos $COMMON_FLAGS native_test_script: - - ./script/tool_runner.sh native-test --macos --exclude=script/configs/exclude_native_macos.yaml + - dart $PLUGIN_TOOL native-test --macos --exclude=script/configs/exclude_native_macos.yaml $COMMON_FLAGS drive_script: - - ./script/tool_runner.sh drive-examples --macos + - dart $PLUGIN_TOOL drive-examples --macos $COMMON_FLAGS diff --git a/script/configs/custom_analysis.yaml b/script/configs/custom_analysis.yaml index 2b0f844de7e0..112cfa572c62 100644 --- a/script/configs/custom_analysis.yaml +++ b/script/configs/custom_analysis.yaml @@ -8,9 +8,11 @@ # from a top-level package into more specific packages in order to incrementally # migrate a federated plugin. # -# DO NOT move or delete this file without updating +# DO NOT move or delete this file without updating both # https://github.com/dart-lang/sdk/blob/master/tools/bots/flutter/analyze_flutter_plugins.sh -# which references this file from source, but out-of-repo. +# and +# https://github.com/flutter/flutter/blob/master/dev/bots/test.dart +# which reference this file from source, but out-of-repo. # Contact stuartmorgan or devoncarew for assistance if necessary. # TODO(ecosystem): Remove everything from this list. See: From 38fe65b03f9321dc71ca4c4bfb5d3d6ec43f0390 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 30 Aug 2021 15:44:37 -0400 Subject: [PATCH 05/10] Rename variable --- .cirrus.yml | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index c5e0faf71475..134d8b27f580 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -9,7 +9,7 @@ env: # The base command flags for most tool invocations, handling: # - running the correct set of packages for the current branch # - including any sharding that is configured for a task via $PLUGIN_SHARDING - COMMON_FLAGS: --packages-for-branch $PLUGIN_SHARDING + COMMON_TOOL_FLAGS: --packages-for-branch $PLUGIN_SHARDING tool_setup_template: &TOOL_SETUP_TEMPLATE tool_setup_script: @@ -72,11 +72,11 @@ task: - cd script/tool - CIRRUS_BUILD_ID=null pub run test - name: publishable - version_check_script: dart $PLUGIN_TOOL version-check $COMMON_FLAGS - publish_check_script: dart $PLUGIN_TOOL publish-check $COMMON_FLAGS + version_check_script: dart $PLUGIN_TOOL version-check $COMMON_TOOL_FLAGS + publish_check_script: dart $PLUGIN_TOOL publish-check $COMMON_TOOL_FLAGS - name: format - format_script: dart $PLUGIN_TOOL format --fail-on-change $COMMON_FLAGS - pubspec_script: dart $PLUGIN_TOOL pubspec-check $COMMON_FLAGS + format_script: dart $PLUGIN_TOOL format --fail-on-change $COMMON_TOOL_FLAGS + pubspec_script: dart $PLUGIN_TOOL pubspec-check $COMMON_TOOL_FLAGS license_script: dart $PLUGIN_TOOL license-check - name: test env: @@ -84,7 +84,7 @@ task: CHANNEL: "master" CHANNEL: "stable" test_script: - - dart $PLUGIN_TOOL test $COMMON_FLAGS + - dart $PLUGIN_TOOL test $COMMON_TOOL_FLAGS - name: analyze env: matrix: @@ -134,9 +134,9 @@ task: CHANNEL: "stable" build_script: - flutter config --enable-linux-desktop - - dart $PLUGIN_TOOL build-examples --linux $COMMON_FLAGS + - dart $PLUGIN_TOOL build-examples --linux $COMMON_TOOL_FLAGS drive_script: - - xvfb-run dart $PLUGIN_TOOL drive-examples --linux $COMMON_FLAGS + - xvfb-run dart $PLUGIN_TOOL drive-examples --linux $COMMON_TOOL_FLAGS # Heavy-workload Linux tasks. # These use machines with more CPUs and memory, so will reduce parallelization @@ -172,7 +172,7 @@ task: # TODO(stuartmorgan): See https://github.com/flutter/flutter/issues/24935 - export CIRRUS_CHANGE_MESSAGE="" - export CIRRUS_COMMIT_MESSAGE="" - - dart $PLUGIN_TOOL build-examples --apk $COMMON_FLAGS + - dart $PLUGIN_TOOL build-examples --apk $COMMON_TOOL_FLAGS lint_script: # Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they # might include non-ASCII characters which makes Gradle crash. @@ -180,7 +180,7 @@ task: - export CIRRUS_CHANGE_MESSAGE="" - export CIRRUS_COMMIT_MESSAGE="" # Must come after build-examples. - - dart $PLUGIN_TOOL lint-android $COMMON_FLAGS + - dart $PLUGIN_TOOL lint-android $COMMON_TOOL_FLAGS native_unit_test_script: # Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they # might include non-ASCII characters which makes Gradle crash. @@ -190,7 +190,7 @@ task: # Native integration tests are handled by firebase-test-lab below, so # only run unit tests. # Must come after build-examples. - - dart $PLUGIN_TOOL native-test --android --no-integration $COMMON_FLAGS + - dart $PLUGIN_TOOL native-test --android --no-integration $COMMON_TOOL_FLAGS firebase_test_lab_script: # Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they # might include non-ASCII characters which makes Gradle crash. @@ -199,7 +199,7 @@ task: - export CIRRUS_COMMIT_MESSAGE="" - if [[ -n "$GCLOUD_FIREBASE_TESTLAB_KEY" ]]; then - echo $GCLOUD_FIREBASE_TESTLAB_KEY > ${HOME}/gcloud-service-key.json - - dart $PLUGIN_TOOL firebase-test-lab --device model=flame,version=29 --device model=starqlteue,version=26 --exclude=script/configs/exclude_integration_android.yaml $COMMON_FLAGS + - dart $PLUGIN_TOOL firebase-test-lab --device model=flame,version=29 --device model=starqlteue,version=26 --exclude=script/configs/exclude_integration_android.yaml $COMMON_TOOL_FLAGS - else - echo "This user does not have permission to run Firebase Test Lab tests." - fi @@ -222,9 +222,9 @@ task: - dart lib/web_driver_installer.dart chromedriver --install-only - ./chromedriver/chromedriver --port=4444 & build_script: - - dart $PLUGIN_TOOL build-examples --web $COMMON_FLAGS + - dart $PLUGIN_TOOL build-examples --web $COMMON_TOOL_FLAGS drive_script: - - dart $PLUGIN_TOOL drive-examples --web --exclude=script/configs/exclude_integration_web.yaml $COMMON_FLAGS + - dart $PLUGIN_TOOL drive-examples --web --exclude=script/configs/exclude_integration_web.yaml $COMMON_TOOL_FLAGS # macOS tasks. task: @@ -234,7 +234,7 @@ task: ### iOS+macOS tasks *** - name: lint_darwin_plugins script: - - dart $PLUGIN_TOOL podspecs $COMMON_FLAGS + - dart $PLUGIN_TOOL podspecs $COMMON_TOOL_FLAGS ### iOS tasks ### - name: build_all_plugins_ipa env: @@ -259,16 +259,16 @@ task: - xcrun simctl list - xcrun simctl create Flutter-iPhone com.apple.CoreSimulator.SimDeviceType.iPhone-11 com.apple.CoreSimulator.SimRuntime.iOS-14-5 | xargs xcrun simctl boot build_script: - - dart $PLUGIN_TOOL build-examples --ios $COMMON_FLAGS + - dart $PLUGIN_TOOL build-examples --ios $COMMON_TOOL_FLAGS xcode_analyze_script: - - dart $PLUGIN_TOOL xcode-analyze --ios $COMMON_FLAGS + - dart $PLUGIN_TOOL xcode-analyze --ios $COMMON_TOOL_FLAGS native_test_script: - - dart $PLUGIN_TOOL native-test --ios --ios-destination "platform=iOS Simulator,name=iPhone 11,OS=latest" $COMMON_FLAGS + - dart $PLUGIN_TOOL native-test --ios --ios-destination "platform=iOS Simulator,name=iPhone 11,OS=latest" $COMMON_TOOL_FLAGS drive_script: # `drive-examples` contains integration tests, which changes the UI of the application. # This UI change sometimes affects `xctest`. # So we run `drive-examples` after `native-test`; changing the order will result ci failure. - - dart $PLUGIN_TOOL drive-examples --ios --exclude=script/configs/exclude_integration_ios.yaml $COMMON_FLAGS + - dart $PLUGIN_TOOL drive-examples --ios --exclude=script/configs/exclude_integration_ios.yaml $COMMON_TOOL_FLAGS ### macOS desktop tasks ### - name: build_all_plugins_macos env: @@ -287,10 +287,10 @@ task: PATH: $PATH:/usr/local/bin build_script: - flutter config --enable-macos-desktop - - dart $PLUGIN_TOOL build-examples --macos $COMMON_FLAGS + - dart $PLUGIN_TOOL build-examples --macos $COMMON_TOOL_FLAGS xcode_analyze_script: - - dart $PLUGIN_TOOL xcode-analyze --macos $COMMON_FLAGS + - dart $PLUGIN_TOOL xcode-analyze --macos $COMMON_TOOL_FLAGS native_test_script: - - dart $PLUGIN_TOOL native-test --macos --exclude=script/configs/exclude_native_macos.yaml $COMMON_FLAGS + - dart $PLUGIN_TOOL native-test --macos --exclude=script/configs/exclude_native_macos.yaml $COMMON_TOOL_FLAGS drive_script: - - dart $PLUGIN_TOOL drive-examples --macos $COMMON_FLAGS + - dart $PLUGIN_TOOL drive-examples --macos $COMMON_TOOL_FLAGS From 5b177bf62ce633934d89b7905665975d8f8dfc44 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 30 Aug 2021 15:44:44 -0400 Subject: [PATCH 06/10] Bump version --- script/tool/CHANGELOG.md | 2 +- script/tool/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/script/tool/CHANGELOG.md b/script/tool/CHANGELOG.md index 06aa7d65d325..e9e078258f4e 100644 --- a/script/tool/CHANGELOG.md +++ b/script/tool/CHANGELOG.md @@ -1,4 +1,4 @@ -## NEXT +## 0.6.0 - Added Android native integration test support to `native-test`. - Added a new `android-lint` command to lint Android plugin native code. diff --git a/script/tool/pubspec.yaml b/script/tool/pubspec.yaml index 02b3ca624b96..7c2bb0b3e3c0 100644 --- a/script/tool/pubspec.yaml +++ b/script/tool/pubspec.yaml @@ -1,7 +1,7 @@ name: flutter_plugin_tools description: Productivity utils for flutter/plugins and flutter/packages repository: https://github.com/flutter/plugins/tree/master/script/tool -version: 0.5.0 +version: 0.6.0 dependencies: args: ^2.1.0 From bcd156132feb4a82c1d9c308529c427f5d499a4e Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 31 Aug 2021 10:12:09 -0400 Subject: [PATCH 07/10] Add a comment about splitting --- script/tool/lib/src/common/plugin_command.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/script/tool/lib/src/common/plugin_command.dart b/script/tool/lib/src/common/plugin_command.dart index 1fb66cdf9484..514a90b85cc7 100644 --- a/script/tool/lib/src/common/plugin_command.dart +++ b/script/tool/lib/src/common/plugin_command.dart @@ -419,10 +419,12 @@ abstract class PluginCommand extends Command { } // Returns packages that have been changed given a list of changed files. + // + // The paths must use POSIX separators (e.g., as provided by git output). Set _getChangedPackages(List changedFiles) { final Set packages = {}; for (final String path in changedFiles) { - final List pathComponents = path.split('/'); + final List pathComponents = p.posix.split(path); final int packagesIndex = pathComponents.indexWhere((String element) => element == 'packages'); if (packagesIndex != -1) { From 984f1d8e7f498972ca06263d471bc72d4f09c2e3 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 31 Aug 2021 10:12:47 -0400 Subject: [PATCH 08/10] Revert "Rename variable" This reverts commit 38fe65b03f9321dc71ca4c4bfb5d3d6ec43f0390. --- .cirrus.yml | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 134d8b27f580..c5e0faf71475 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -9,7 +9,7 @@ env: # The base command flags for most tool invocations, handling: # - running the correct set of packages for the current branch # - including any sharding that is configured for a task via $PLUGIN_SHARDING - COMMON_TOOL_FLAGS: --packages-for-branch $PLUGIN_SHARDING + COMMON_FLAGS: --packages-for-branch $PLUGIN_SHARDING tool_setup_template: &TOOL_SETUP_TEMPLATE tool_setup_script: @@ -72,11 +72,11 @@ task: - cd script/tool - CIRRUS_BUILD_ID=null pub run test - name: publishable - version_check_script: dart $PLUGIN_TOOL version-check $COMMON_TOOL_FLAGS - publish_check_script: dart $PLUGIN_TOOL publish-check $COMMON_TOOL_FLAGS + version_check_script: dart $PLUGIN_TOOL version-check $COMMON_FLAGS + publish_check_script: dart $PLUGIN_TOOL publish-check $COMMON_FLAGS - name: format - format_script: dart $PLUGIN_TOOL format --fail-on-change $COMMON_TOOL_FLAGS - pubspec_script: dart $PLUGIN_TOOL pubspec-check $COMMON_TOOL_FLAGS + format_script: dart $PLUGIN_TOOL format --fail-on-change $COMMON_FLAGS + pubspec_script: dart $PLUGIN_TOOL pubspec-check $COMMON_FLAGS license_script: dart $PLUGIN_TOOL license-check - name: test env: @@ -84,7 +84,7 @@ task: CHANNEL: "master" CHANNEL: "stable" test_script: - - dart $PLUGIN_TOOL test $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL test $COMMON_FLAGS - name: analyze env: matrix: @@ -134,9 +134,9 @@ task: CHANNEL: "stable" build_script: - flutter config --enable-linux-desktop - - dart $PLUGIN_TOOL build-examples --linux $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL build-examples --linux $COMMON_FLAGS drive_script: - - xvfb-run dart $PLUGIN_TOOL drive-examples --linux $COMMON_TOOL_FLAGS + - xvfb-run dart $PLUGIN_TOOL drive-examples --linux $COMMON_FLAGS # Heavy-workload Linux tasks. # These use machines with more CPUs and memory, so will reduce parallelization @@ -172,7 +172,7 @@ task: # TODO(stuartmorgan): See https://github.com/flutter/flutter/issues/24935 - export CIRRUS_CHANGE_MESSAGE="" - export CIRRUS_COMMIT_MESSAGE="" - - dart $PLUGIN_TOOL build-examples --apk $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL build-examples --apk $COMMON_FLAGS lint_script: # Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they # might include non-ASCII characters which makes Gradle crash. @@ -180,7 +180,7 @@ task: - export CIRRUS_CHANGE_MESSAGE="" - export CIRRUS_COMMIT_MESSAGE="" # Must come after build-examples. - - dart $PLUGIN_TOOL lint-android $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL lint-android $COMMON_FLAGS native_unit_test_script: # Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they # might include non-ASCII characters which makes Gradle crash. @@ -190,7 +190,7 @@ task: # Native integration tests are handled by firebase-test-lab below, so # only run unit tests. # Must come after build-examples. - - dart $PLUGIN_TOOL native-test --android --no-integration $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL native-test --android --no-integration $COMMON_FLAGS firebase_test_lab_script: # Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they # might include non-ASCII characters which makes Gradle crash. @@ -199,7 +199,7 @@ task: - export CIRRUS_COMMIT_MESSAGE="" - if [[ -n "$GCLOUD_FIREBASE_TESTLAB_KEY" ]]; then - echo $GCLOUD_FIREBASE_TESTLAB_KEY > ${HOME}/gcloud-service-key.json - - dart $PLUGIN_TOOL firebase-test-lab --device model=flame,version=29 --device model=starqlteue,version=26 --exclude=script/configs/exclude_integration_android.yaml $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL firebase-test-lab --device model=flame,version=29 --device model=starqlteue,version=26 --exclude=script/configs/exclude_integration_android.yaml $COMMON_FLAGS - else - echo "This user does not have permission to run Firebase Test Lab tests." - fi @@ -222,9 +222,9 @@ task: - dart lib/web_driver_installer.dart chromedriver --install-only - ./chromedriver/chromedriver --port=4444 & build_script: - - dart $PLUGIN_TOOL build-examples --web $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL build-examples --web $COMMON_FLAGS drive_script: - - dart $PLUGIN_TOOL drive-examples --web --exclude=script/configs/exclude_integration_web.yaml $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL drive-examples --web --exclude=script/configs/exclude_integration_web.yaml $COMMON_FLAGS # macOS tasks. task: @@ -234,7 +234,7 @@ task: ### iOS+macOS tasks *** - name: lint_darwin_plugins script: - - dart $PLUGIN_TOOL podspecs $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL podspecs $COMMON_FLAGS ### iOS tasks ### - name: build_all_plugins_ipa env: @@ -259,16 +259,16 @@ task: - xcrun simctl list - xcrun simctl create Flutter-iPhone com.apple.CoreSimulator.SimDeviceType.iPhone-11 com.apple.CoreSimulator.SimRuntime.iOS-14-5 | xargs xcrun simctl boot build_script: - - dart $PLUGIN_TOOL build-examples --ios $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL build-examples --ios $COMMON_FLAGS xcode_analyze_script: - - dart $PLUGIN_TOOL xcode-analyze --ios $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL xcode-analyze --ios $COMMON_FLAGS native_test_script: - - dart $PLUGIN_TOOL native-test --ios --ios-destination "platform=iOS Simulator,name=iPhone 11,OS=latest" $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL native-test --ios --ios-destination "platform=iOS Simulator,name=iPhone 11,OS=latest" $COMMON_FLAGS drive_script: # `drive-examples` contains integration tests, which changes the UI of the application. # This UI change sometimes affects `xctest`. # So we run `drive-examples` after `native-test`; changing the order will result ci failure. - - dart $PLUGIN_TOOL drive-examples --ios --exclude=script/configs/exclude_integration_ios.yaml $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL drive-examples --ios --exclude=script/configs/exclude_integration_ios.yaml $COMMON_FLAGS ### macOS desktop tasks ### - name: build_all_plugins_macos env: @@ -287,10 +287,10 @@ task: PATH: $PATH:/usr/local/bin build_script: - flutter config --enable-macos-desktop - - dart $PLUGIN_TOOL build-examples --macos $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL build-examples --macos $COMMON_FLAGS xcode_analyze_script: - - dart $PLUGIN_TOOL xcode-analyze --macos $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL xcode-analyze --macos $COMMON_FLAGS native_test_script: - - dart $PLUGIN_TOOL native-test --macos --exclude=script/configs/exclude_native_macos.yaml $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL native-test --macos --exclude=script/configs/exclude_native_macos.yaml $COMMON_FLAGS drive_script: - - dart $PLUGIN_TOOL drive-examples --macos $COMMON_TOOL_FLAGS + - dart $PLUGIN_TOOL drive-examples --macos $COMMON_FLAGS From 56d86fdf89b8a6a6c1df15aa9d6fcc14e7f5fab9 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 31 Aug 2021 10:12:55 -0400 Subject: [PATCH 09/10] Revert "Remove all but one use of tool_runner.sh" This reverts commit 243ba40c60caacd1d098700d67e3600342eeb328. --- .cirrus.yml | 56 ++++++++++++----------------- script/configs/custom_analysis.yaml | 6 ++-- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index c5e0faf71475..d830a2a15913 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -6,10 +6,6 @@ only_if: $CIRRUS_TAG == '' env: CHANNEL: "master" # Default to master when not explicitly set by a task. PLUGIN_TOOL: "./script/tool/bin/flutter_plugin_tools.dart" - # The base command flags for most tool invocations, handling: - # - running the correct set of packages for the current branch - # - including any sharding that is configured for a task via $PLUGIN_SHARDING - COMMON_FLAGS: --packages-for-branch $PLUGIN_SHARDING tool_setup_template: &TOOL_SETUP_TEMPLATE tool_setup_script: @@ -72,11 +68,11 @@ task: - cd script/tool - CIRRUS_BUILD_ID=null pub run test - name: publishable - version_check_script: dart $PLUGIN_TOOL version-check $COMMON_FLAGS - publish_check_script: dart $PLUGIN_TOOL publish-check $COMMON_FLAGS + version_check_script: ./script/tool_runner.sh version-check + publish_check_script: ./script/tool_runner.sh publish-check - name: format - format_script: dart $PLUGIN_TOOL format --fail-on-change $COMMON_FLAGS - pubspec_script: dart $PLUGIN_TOOL pubspec-check $COMMON_FLAGS + format_script: ./script/tool_runner.sh format --fail-on-change + pubspec_script: ./script/tool_runner.sh pubspec-check license_script: dart $PLUGIN_TOOL license-check - name: test env: @@ -84,7 +80,7 @@ task: CHANNEL: "master" CHANNEL: "stable" test_script: - - dart $PLUGIN_TOOL test $COMMON_FLAGS + - ./script/tool_runner.sh test - name: analyze env: matrix: @@ -94,12 +90,8 @@ task: - cd script/tool - dart analyze --fatal-infos script: - # DO NOT change anything about this command without changing the - # dart-lang/sdk and flutter/flutter repositories first. + # DO NOT change the custom-analysis argument here without changing the Dart repo. # See the comment in script/configs/custom_analysis.yaml for details. - # This deliberately still uses tool_runner.sh to ensure that changes - # that would cause this command to fail show up here, not in the other - # repositories. - ./script/tool_runner.sh analyze --custom-analysis=script/configs/custom_analysis.yaml ### Android tasks ### - name: build_all_plugins_apk @@ -134,9 +126,9 @@ task: CHANNEL: "stable" build_script: - flutter config --enable-linux-desktop - - dart $PLUGIN_TOOL build-examples --linux $COMMON_FLAGS + - ./script/tool_runner.sh build-examples --linux drive_script: - - xvfb-run dart $PLUGIN_TOOL drive-examples --linux $COMMON_FLAGS + - xvfb-run ./script/tool_runner.sh drive-examples --linux # Heavy-workload Linux tasks. # These use machines with more CPUs and memory, so will reduce parallelization @@ -172,15 +164,14 @@ task: # TODO(stuartmorgan): See https://github.com/flutter/flutter/issues/24935 - export CIRRUS_CHANGE_MESSAGE="" - export CIRRUS_COMMIT_MESSAGE="" - - dart $PLUGIN_TOOL build-examples --apk $COMMON_FLAGS + - ./script/tool_runner.sh build-examples --apk lint_script: # Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they # might include non-ASCII characters which makes Gradle crash. # TODO(stuartmorgan): See https://github.com/flutter/flutter/issues/24935 - export CIRRUS_CHANGE_MESSAGE="" - export CIRRUS_COMMIT_MESSAGE="" - # Must come after build-examples. - - dart $PLUGIN_TOOL lint-android $COMMON_FLAGS + - ./script/tool_runner.sh lint-android # must come after build-examples native_unit_test_script: # Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they # might include non-ASCII characters which makes Gradle crash. @@ -189,8 +180,7 @@ task: - export CIRRUS_COMMIT_MESSAGE="" # Native integration tests are handled by firebase-test-lab below, so # only run unit tests. - # Must come after build-examples. - - dart $PLUGIN_TOOL native-test --android --no-integration $COMMON_FLAGS + - ./script/tool_runner.sh native-test --android --no-integration # must come after apk build firebase_test_lab_script: # Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they # might include non-ASCII characters which makes Gradle crash. @@ -199,7 +189,7 @@ task: - export CIRRUS_COMMIT_MESSAGE="" - if [[ -n "$GCLOUD_FIREBASE_TESTLAB_KEY" ]]; then - echo $GCLOUD_FIREBASE_TESTLAB_KEY > ${HOME}/gcloud-service-key.json - - dart $PLUGIN_TOOL firebase-test-lab --device model=flame,version=29 --device model=starqlteue,version=26 --exclude=script/configs/exclude_integration_android.yaml $COMMON_FLAGS + - ./script/tool_runner.sh firebase-test-lab --device model=flame,version=29 --device model=starqlteue,version=26 --exclude=script/configs/exclude_integration_android.yaml - else - echo "This user does not have permission to run Firebase Test Lab tests." - fi @@ -222,9 +212,9 @@ task: - dart lib/web_driver_installer.dart chromedriver --install-only - ./chromedriver/chromedriver --port=4444 & build_script: - - dart $PLUGIN_TOOL build-examples --web $COMMON_FLAGS + - ./script/tool_runner.sh build-examples --web drive_script: - - dart $PLUGIN_TOOL drive-examples --web --exclude=script/configs/exclude_integration_web.yaml $COMMON_FLAGS + - ./script/tool_runner.sh drive-examples --web --exclude=script/configs/exclude_integration_web.yaml # macOS tasks. task: @@ -234,7 +224,7 @@ task: ### iOS+macOS tasks *** - name: lint_darwin_plugins script: - - dart $PLUGIN_TOOL podspecs $COMMON_FLAGS + - ./script/tool_runner.sh podspecs ### iOS tasks ### - name: build_all_plugins_ipa env: @@ -259,16 +249,16 @@ task: - xcrun simctl list - xcrun simctl create Flutter-iPhone com.apple.CoreSimulator.SimDeviceType.iPhone-11 com.apple.CoreSimulator.SimRuntime.iOS-14-5 | xargs xcrun simctl boot build_script: - - dart $PLUGIN_TOOL build-examples --ios $COMMON_FLAGS + - ./script/tool_runner.sh build-examples --ios xcode_analyze_script: - - dart $PLUGIN_TOOL xcode-analyze --ios $COMMON_FLAGS + - ./script/tool_runner.sh xcode-analyze --ios native_test_script: - - dart $PLUGIN_TOOL native-test --ios --ios-destination "platform=iOS Simulator,name=iPhone 11,OS=latest" $COMMON_FLAGS + - ./script/tool_runner.sh native-test --ios --ios-destination "platform=iOS Simulator,name=iPhone 11,OS=latest" drive_script: # `drive-examples` contains integration tests, which changes the UI of the application. # This UI change sometimes affects `xctest`. # So we run `drive-examples` after `native-test`; changing the order will result ci failure. - - dart $PLUGIN_TOOL drive-examples --ios --exclude=script/configs/exclude_integration_ios.yaml $COMMON_FLAGS + - ./script/tool_runner.sh drive-examples --ios --exclude=script/configs/exclude_integration_ios.yaml ### macOS desktop tasks ### - name: build_all_plugins_macos env: @@ -287,10 +277,10 @@ task: PATH: $PATH:/usr/local/bin build_script: - flutter config --enable-macos-desktop - - dart $PLUGIN_TOOL build-examples --macos $COMMON_FLAGS + - ./script/tool_runner.sh build-examples --macos xcode_analyze_script: - - dart $PLUGIN_TOOL xcode-analyze --macos $COMMON_FLAGS + - ./script/tool_runner.sh xcode-analyze --macos native_test_script: - - dart $PLUGIN_TOOL native-test --macos --exclude=script/configs/exclude_native_macos.yaml $COMMON_FLAGS + - ./script/tool_runner.sh native-test --macos --exclude=script/configs/exclude_native_macos.yaml drive_script: - - dart $PLUGIN_TOOL drive-examples --macos $COMMON_FLAGS + - ./script/tool_runner.sh drive-examples --macos diff --git a/script/configs/custom_analysis.yaml b/script/configs/custom_analysis.yaml index 112cfa572c62..2b0f844de7e0 100644 --- a/script/configs/custom_analysis.yaml +++ b/script/configs/custom_analysis.yaml @@ -8,11 +8,9 @@ # from a top-level package into more specific packages in order to incrementally # migrate a federated plugin. # -# DO NOT move or delete this file without updating both +# DO NOT move or delete this file without updating # https://github.com/dart-lang/sdk/blob/master/tools/bots/flutter/analyze_flutter_plugins.sh -# and -# https://github.com/flutter/flutter/blob/master/dev/bots/test.dart -# which reference this file from source, but out-of-repo. +# which references this file from source, but out-of-repo. # Contact stuartmorgan or devoncarew for assistance if necessary. # TODO(ecosystem): Remove everything from this list. See: From fc4fd9e61071104a9f6a02ef219c20cd5ee629b9 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 31 Aug 2021 10:15:06 -0400 Subject: [PATCH 10/10] typo fix --- script/tool/test/common/plugin_command_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/tool/test/common/plugin_command_test.dart b/script/tool/test/common/plugin_command_test.dart index 7703f4b40c93..3ef0d3b3c005 100644 --- a/script/tool/test/common/plugin_command_test.dart +++ b/script/tool/test/common/plugin_command_test.dart @@ -180,7 +180,7 @@ void main() { expect(command.plugins, unorderedEquals([])); }); - group('conflicting package selecetion', () { + group('conflicting package selection', () { test('does not allow --packages with --run-on-changed-packages', () async { Error? commandError;