diff --git a/tools/engine_tool/lib/main.dart b/tools/engine_tool/lib/main.dart index c615b23600d86..9af1bc47b88c5 100644 --- a/tools/engine_tool/lib/main.dart +++ b/tools/engine_tool/lib/main.dart @@ -66,13 +66,13 @@ void main(List args) async { platform: const LocalPlatform(), processRunner: ProcessRunner(), logger: Logger(), + verbose: verbose, ); // Use the Engine and BuildConfig collection to build the CommandRunner. final ToolCommandRunner runner = ToolCommandRunner( environment: environment, configs: configs, - verbose: verbose, help: help, ); diff --git a/tools/engine_tool/lib/src/build_utils.dart b/tools/engine_tool/lib/src/build_utils.dart index b2bb9eb0090a2..df3ad2b1c740a 100644 --- a/tools/engine_tool/lib/src/build_utils.dart +++ b/tools/engine_tool/lib/src/build_utils.dart @@ -51,7 +51,7 @@ List runnableBuilds( Environment env, Map input, bool verbose) { return filterBuilds(input, (String configName, Build build) { return build.canRunOn(env.platform) && - (verbose || build.name.startsWith(env.platform.operatingSystem)); + (verbose || build.name.startsWith(env.platform.operatingSystem)); }); } @@ -119,9 +119,12 @@ String demangleConfigName(Environment env, String name) { } /// Build the build target in the environment. -Future runBuild(Environment environment, Build build, - {List extraGnArgs = const [], - List targets = const []}) async { +Future runBuild( + Environment environment, + Build build, { + List extraGnArgs = const [], + List targets = const [], +}) async { // If RBE config files aren't in the tree, then disable RBE. final String rbeConfigPath = p.join( environment.engine.srcDir.path, @@ -143,7 +146,11 @@ Future runBuild(Environment environment, Build build, build: build, extraGnArgs: gnArgs, runTests: false, - extraNinjaArgs: targets, + extraNinjaArgs: [ + ...targets, + // If the environment is verbose, pass the verbose flag to ninja. + if (environment.verbose) '--verbose', + ], ); Spinner? spinner; diff --git a/tools/engine_tool/lib/src/commands/build_command.dart b/tools/engine_tool/lib/src/commands/build_command.dart index 9316ee90bdd3a..bf716f15cae9f 100644 --- a/tools/engine_tool/lib/src/commands/build_command.dart +++ b/tools/engine_tool/lib/src/commands/build_command.dart @@ -15,13 +15,12 @@ final class BuildCommand extends CommandBase { BuildCommand({ required super.environment, required Map configs, - super.verbose = false, super.help = false, super.usageLineLength, }) { // When printing the help/usage for this command, only list all builds // when the --verbose flag is supplied. - final bool includeCiBuilds = verbose || !help; + final bool includeCiBuilds = environment.verbose || !help; builds = runnableBuilds(environment, configs, includeCiBuilds); debugCheckBuilds(builds); addConfigOption( diff --git a/tools/engine_tool/lib/src/commands/command.dart b/tools/engine_tool/lib/src/commands/command.dart index 8c634575cfa76..5419d413222f6 100644 --- a/tools/engine_tool/lib/src/commands/command.dart +++ b/tools/engine_tool/lib/src/commands/command.dart @@ -15,7 +15,6 @@ abstract base class CommandBase extends Command { /// Constructs the base command. CommandBase({ required this.environment, - this.verbose = false, this.help = false, int? usageLineLength, }) : argParser = ArgParser(usageLineLength: usageLineLength); @@ -23,9 +22,6 @@ abstract base class CommandBase extends Command { /// The host system environment. final Environment environment; - /// Whether verbose logging is enabled. - final bool verbose; - /// Whether the Command is being constructed only to print the usage/help /// message. final bool help; diff --git a/tools/engine_tool/lib/src/commands/command_runner.dart b/tools/engine_tool/lib/src/commands/command_runner.dart index 70cef3b904dd3..4909dd8ca2d7e 100644 --- a/tools/engine_tool/lib/src/commands/command_runner.dart +++ b/tools/engine_tool/lib/src/commands/command_runner.dart @@ -25,7 +25,6 @@ final class ToolCommandRunner extends CommandRunner { ToolCommandRunner({ required this.environment, required this.configs, - this.verbose = false, this.help = false, }) : super(toolName, toolDescription, usageLineLength: _usageLineLength) { final List> commands = >[ @@ -40,21 +39,18 @@ final class ToolCommandRunner extends CommandRunner { QueryCommand( environment: environment, configs: configs, - verbose: verbose, help: help, usageLineLength: _usageLineLength, ), BuildCommand( environment: environment, configs: configs, - verbose: verbose, help: help, usageLineLength: _usageLineLength, ), RunCommand( environment: environment, configs: configs, - verbose: verbose, usageLineLength: _usageLineLength, ), LintCommand( @@ -64,7 +60,6 @@ final class ToolCommandRunner extends CommandRunner { TestCommand( environment: environment, configs: configs, - verbose: verbose, help: help, usageLineLength: _usageLineLength, ), @@ -94,15 +89,12 @@ final class ToolCommandRunner extends CommandRunner { /// Build configurations loaded from the engine from under ci/builders. final Map configs; - /// Whether et should emit verbose logs. - final bool verbose; - /// Whether the invocation is for a help command final bool help; @override Future run(Iterable args) async { - if (verbose) { + if (environment.verbose) { environment.logger.level = Logger.infoLevel; } try { diff --git a/tools/engine_tool/lib/src/commands/fetch_command.dart b/tools/engine_tool/lib/src/commands/fetch_command.dart index f53557f851056..c645fd3729462 100644 --- a/tools/engine_tool/lib/src/commands/fetch_command.dart +++ b/tools/engine_tool/lib/src/commands/fetch_command.dart @@ -4,7 +4,6 @@ import '../dependencies.dart'; import 'command.dart'; -import 'flags.dart'; /// The root 'fetch' command. final class FetchCommand extends CommandBase { @@ -25,7 +24,6 @@ final class FetchCommand extends CommandBase { @override Future run() { - final bool verbose = globalResults![verboseFlag] as bool; - return fetchDependencies(environment, verbose: verbose); + return fetchDependencies(environment); } } diff --git a/tools/engine_tool/lib/src/commands/query_command.dart b/tools/engine_tool/lib/src/commands/query_command.dart index ebd254994782c..e07d33cfbbbaf 100644 --- a/tools/engine_tool/lib/src/commands/query_command.dart +++ b/tools/engine_tool/lib/src/commands/query_command.dart @@ -15,7 +15,6 @@ final class QueryCommand extends CommandBase { QueryCommand({ required super.environment, required this.configs, - super.verbose = false, super.help = false, super.usageLineLength, }) { @@ -45,13 +44,11 @@ final class QueryCommand extends CommandBase { addSubcommand(QueryBuildersCommand( environment: environment, configs: configs, - verbose: verbose, help: help, )); addSubcommand(QueryTargetsCommand( environment: environment, configs: configs, - verbose: verbose, help: help, )); } @@ -73,7 +70,6 @@ final class QueryBuildersCommand extends CommandBase { QueryBuildersCommand({ required super.environment, required this.configs, - super.verbose = false, super.help = false, }); @@ -93,7 +89,7 @@ final class QueryBuildersCommand extends CommandBase { // current platform. final bool all = parent!.argResults![allFlag]! as bool; final String? builderName = parent!.argResults![builderFlag] as String?; - if (!verbose) { + if (!environment.verbose) { environment.logger.status( 'Add --verbose to see detailed information about each builder', ); @@ -115,7 +111,7 @@ final class QueryBuildersCommand extends CommandBase { continue; } environment.logger.status('"${build.name}" config', indent: 3); - if (!verbose) { + if (!environment.verbose) { continue; } environment.logger.status('gn flags:', indent: 6); @@ -140,12 +136,11 @@ final class QueryTargetsCommand extends CommandBase { QueryTargetsCommand({ required super.environment, required this.configs, - super.verbose = false, super.help = false, }) { // When printing the help/usage for this command, only list all builds // when the --verbose flag is supplied. - final bool includeCiBuilds = verbose || !help; + final bool includeCiBuilds = environment.verbose || !help; builds = runnableBuilds(environment, configs, includeCiBuilds); debugCheckBuilds(builds); addConfigOption( diff --git a/tools/engine_tool/lib/src/commands/run_command.dart b/tools/engine_tool/lib/src/commands/run_command.dart index c0187b0e0f1fd..8798a4e5d3c6c 100644 --- a/tools/engine_tool/lib/src/commands/run_command.dart +++ b/tools/engine_tool/lib/src/commands/run_command.dart @@ -18,13 +18,12 @@ final class RunCommand extends CommandBase { RunCommand({ required super.environment, required Map configs, - super.verbose = false, super.help = false, super.usageLineLength, }) { // When printing the help/usage for this command, only list all builds // when the --verbose flag is supplied. - final bool includeCiBuilds = verbose || !help; + final bool includeCiBuilds = environment.verbose || !help; builds = runnableBuilds(environment, configs, includeCiBuilds); debugCheckBuilds(builds); // We default to nothing in order to automatically detect attached devices diff --git a/tools/engine_tool/lib/src/commands/test_command.dart b/tools/engine_tool/lib/src/commands/test_command.dart index ab504e6b584d6..47de807fa6a59 100644 --- a/tools/engine_tool/lib/src/commands/test_command.dart +++ b/tools/engine_tool/lib/src/commands/test_command.dart @@ -17,13 +17,12 @@ final class TestCommand extends CommandBase { TestCommand({ required super.environment, required Map configs, - super.verbose = false, super.help = false, super.usageLineLength, }) { // When printing the help/usage for this command, only list all builds // when the --verbose flag is supplied. - final bool includeCiBuilds = verbose || !help; + final bool includeCiBuilds = environment.verbose || !help; builds = runnableBuilds(environment, configs, includeCiBuilds); debugCheckBuilds(builds); addConfigOption( diff --git a/tools/engine_tool/lib/src/dependencies.dart b/tools/engine_tool/lib/src/dependencies.dart index 28bc2c9d7a31e..e9d113d1648a8 100644 --- a/tools/engine_tool/lib/src/dependencies.dart +++ b/tools/engine_tool/lib/src/dependencies.dart @@ -10,21 +10,21 @@ import 'environment.dart'; import 'logger.dart'; /// Update Flutter engine dependencies. Returns an exit code. -Future fetchDependencies( - Environment environment, { - bool verbose = false, -}) async { +Future fetchDependencies(Environment environment) async { if (!environment.processRunner.processManager.canRun('gclient')) { environment.logger.error('Cannot find the gclient command in your path'); return 1; } - environment.logger.status('Fetching dependencies... ', newline: verbose); + environment.logger.status( + 'Fetching dependencies... ', + newline: environment.verbose, + ); Spinner? spinner; ProcessRunnerResult result; try { - if (!verbose) { + if (!environment.verbose) { spinner = environment.logger.startSpinner(); } @@ -35,9 +35,9 @@ Future fetchDependencies( '-D', ], runInShell: true, - startMode: verbose - ? io.ProcessStartMode.inheritStdio - : io.ProcessStartMode.normal, + startMode: environment.verbose + ? io.ProcessStartMode.inheritStdio + : io.ProcessStartMode.normal, ); } finally { spinner?.finish(); @@ -48,7 +48,7 @@ Future fetchDependencies( // Verbose mode already logged output by making the child process inherit // this process's stdio handles. - if (!verbose) { + if (!environment.verbose) { environment.logger.error('Output:\n${result.output}'); } } diff --git a/tools/engine_tool/lib/src/environment.dart b/tools/engine_tool/lib/src/environment.dart index dfe40e501c4ac..6ae232d83e126 100644 --- a/tools/engine_tool/lib/src/environment.dart +++ b/tools/engine_tool/lib/src/environment.dart @@ -24,8 +24,12 @@ final class Environment { required this.logger, required this.platform, required this.processRunner, + this.verbose = false, }); + /// Whether the tool should be considered running in "verbose" mode. + final bool verbose; + /// The host OS and architecture that the tool is running on. final ffi.Abi abi; diff --git a/tools/engine_tool/test/build_command_test.dart b/tools/engine_tool/test/build_command_test.dart index 902ad3672f6d3..12c5aa1f82319 100644 --- a/tools/engine_tool/test/build_command_test.dart +++ b/tools/engine_tool/test/build_command_test.dart @@ -398,12 +398,12 @@ void main() { () async { final TestEnvironment testEnv = TestEnvironment.withTestEngine( cannedProcesses: cannedProcesses, + verbose: true, ); try { final ToolCommandRunner runner = ToolCommandRunner( environment: testEnv.environment, configs: configs, - verbose: true, help: true, ); final int result = await runner.run([ diff --git a/tools/engine_tool/test/utils.dart b/tools/engine_tool/test/utils.dart index 4b3aaf3721cc9..6e2e53226e202 100644 --- a/tools/engine_tool/test/utils.dart +++ b/tools/engine_tool/test/utils.dart @@ -56,6 +56,7 @@ class TestEnvironment { Engine engine, { Logger? logger, ffi.Abi abi = ffi.Abi.macosArm64, + bool verbose = false, this.cannedProcesses = const [], }) { logger ??= Logger.test(); @@ -78,6 +79,7 @@ class TestEnvironment { throw UnimplementedError('onRun'); })), logger: logger, + verbose: verbose, ); } @@ -85,6 +87,7 @@ class TestEnvironment { bool withRbe = false, ffi.Abi abi = ffi.Abi.linuxX64, List cannedProcesses = const [], + bool verbose = false, }) { final io.Directory rootDir = io.Directory.systemTemp.createTempSync('et'); final TestEngine engine = TestEngine.createTemp(rootDir: rootDir); @@ -107,8 +110,12 @@ class TestEnvironment { } return false; }); - final TestEnvironment testEnvironment = TestEnvironment(engine, - abi: abi, cannedProcesses: cannedProcesses + [cannedGn]); + final TestEnvironment testEnvironment = TestEnvironment( + engine, + abi: abi, + cannedProcesses: cannedProcesses + [cannedGn], + verbose: verbose, + ); return testEnvironment; } @@ -206,7 +213,8 @@ Matcher containsCommand(CommandMatcher commandMatcher) => (dynamic processes) { /// command[5] == 'flutter/fml:fml_arc_unittests'; /// }) /// ); -Matcher doesNotContainCommand(CommandMatcher commandMatcher) => (dynamic processes) { +Matcher doesNotContainCommand(CommandMatcher commandMatcher) => + (dynamic processes) { Expect.type>(processes); final List> commands = (processes as List) .map((ExecutedProcess process) => process.command)