Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 66ee93c

Browse files
authored
Move verbose to environment.verbose, pass to ninja --verbose if provided. (#52619)
Closes flutter/flutter#147894. While doing this PR I realized we were basically passing `(bool verbose, Envrionment)` as a tuple around, so I just moved the concept _into_ `Environment` directly, and made the necessary code changes across the tool and tests. To clarify, this does _not_ mimic the output of `ninja --verbose` _today_, because we also don't stream the output directly, and instead do terminal magic. Combined with a hypothetical fix for flutter/flutter#147903, this would work exactly the same as before. /cc @loic-sharma @johnmccutchan
1 parent 7cc54f9 commit 66ee93c

13 files changed

+47
-50
lines changed

tools/engine_tool/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ void main(List<String> args) async {
6666
platform: const LocalPlatform(),
6767
processRunner: ProcessRunner(),
6868
logger: Logger(),
69+
verbose: verbose,
6970
);
7071

7172
// Use the Engine and BuildConfig collection to build the CommandRunner.
7273
final ToolCommandRunner runner = ToolCommandRunner(
7374
environment: environment,
7475
configs: configs,
75-
verbose: verbose,
7676
help: help,
7777
);
7878

tools/engine_tool/lib/src/build_utils.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ List<Build> runnableBuilds(
5151
Environment env, Map<String, BuilderConfig> input, bool verbose) {
5252
return filterBuilds(input, (String configName, Build build) {
5353
return build.canRunOn(env.platform) &&
54-
(verbose || build.name.startsWith(env.platform.operatingSystem));
54+
(verbose || build.name.startsWith(env.platform.operatingSystem));
5555
});
5656
}
5757

@@ -119,9 +119,12 @@ String demangleConfigName(Environment env, String name) {
119119
}
120120

121121
/// Build the build target in the environment.
122-
Future<int> runBuild(Environment environment, Build build,
123-
{List<String> extraGnArgs = const <String>[],
124-
List<String> targets = const <String>[]}) async {
122+
Future<int> runBuild(
123+
Environment environment,
124+
Build build, {
125+
List<String> extraGnArgs = const <String>[],
126+
List<String> targets = const <String>[],
127+
}) async {
125128
// If RBE config files aren't in the tree, then disable RBE.
126129
final String rbeConfigPath = p.join(
127130
environment.engine.srcDir.path,
@@ -143,7 +146,11 @@ Future<int> runBuild(Environment environment, Build build,
143146
build: build,
144147
extraGnArgs: gnArgs,
145148
runTests: false,
146-
extraNinjaArgs: targets,
149+
extraNinjaArgs: <String>[
150+
...targets,
151+
// If the environment is verbose, pass the verbose flag to ninja.
152+
if (environment.verbose) '--verbose',
153+
],
147154
);
148155

149156
Spinner? spinner;

tools/engine_tool/lib/src/commands/build_command.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ final class BuildCommand extends CommandBase {
1515
BuildCommand({
1616
required super.environment,
1717
required Map<String, BuilderConfig> configs,
18-
super.verbose = false,
1918
super.help = false,
2019
super.usageLineLength,
2120
}) {
2221
// When printing the help/usage for this command, only list all builds
2322
// when the --verbose flag is supplied.
24-
final bool includeCiBuilds = verbose || !help;
23+
final bool includeCiBuilds = environment.verbose || !help;
2524
builds = runnableBuilds(environment, configs, includeCiBuilds);
2625
debugCheckBuilds(builds);
2726
addConfigOption(

tools/engine_tool/lib/src/commands/command.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,13 @@ abstract base class CommandBase extends Command<int> {
1515
/// Constructs the base command.
1616
CommandBase({
1717
required this.environment,
18-
this.verbose = false,
1918
this.help = false,
2019
int? usageLineLength,
2120
}) : argParser = ArgParser(usageLineLength: usageLineLength);
2221

2322
/// The host system environment.
2423
final Environment environment;
2524

26-
/// Whether verbose logging is enabled.
27-
final bool verbose;
28-
2925
/// Whether the Command is being constructed only to print the usage/help
3026
/// message.
3127
final bool help;

tools/engine_tool/lib/src/commands/command_runner.dart

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ final class ToolCommandRunner extends CommandRunner<int> {
2525
ToolCommandRunner({
2626
required this.environment,
2727
required this.configs,
28-
this.verbose = false,
2928
this.help = false,
3029
}) : super(toolName, toolDescription, usageLineLength: _usageLineLength) {
3130
final List<Command<int>> commands = <Command<int>>[
@@ -40,21 +39,18 @@ final class ToolCommandRunner extends CommandRunner<int> {
4039
QueryCommand(
4140
environment: environment,
4241
configs: configs,
43-
verbose: verbose,
4442
help: help,
4543
usageLineLength: _usageLineLength,
4644
),
4745
BuildCommand(
4846
environment: environment,
4947
configs: configs,
50-
verbose: verbose,
5148
help: help,
5249
usageLineLength: _usageLineLength,
5350
),
5451
RunCommand(
5552
environment: environment,
5653
configs: configs,
57-
verbose: verbose,
5854
usageLineLength: _usageLineLength,
5955
),
6056
LintCommand(
@@ -64,7 +60,6 @@ final class ToolCommandRunner extends CommandRunner<int> {
6460
TestCommand(
6561
environment: environment,
6662
configs: configs,
67-
verbose: verbose,
6863
help: help,
6964
usageLineLength: _usageLineLength,
7065
),
@@ -94,15 +89,12 @@ final class ToolCommandRunner extends CommandRunner<int> {
9489
/// Build configurations loaded from the engine from under ci/builders.
9590
final Map<String, BuilderConfig> configs;
9691

97-
/// Whether et should emit verbose logs.
98-
final bool verbose;
99-
10092
/// Whether the invocation is for a help command
10193
final bool help;
10294

10395
@override
10496
Future<int> run(Iterable<String> args) async {
105-
if (verbose) {
97+
if (environment.verbose) {
10698
environment.logger.level = Logger.infoLevel;
10799
}
108100
try {

tools/engine_tool/lib/src/commands/fetch_command.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import '../dependencies.dart';
66
import 'command.dart';
7-
import 'flags.dart';
87

98
/// The root 'fetch' command.
109
final class FetchCommand extends CommandBase {
@@ -25,7 +24,6 @@ final class FetchCommand extends CommandBase {
2524

2625
@override
2726
Future<int> run() {
28-
final bool verbose = globalResults![verboseFlag] as bool;
29-
return fetchDependencies(environment, verbose: verbose);
27+
return fetchDependencies(environment);
3028
}
3129
}

tools/engine_tool/lib/src/commands/query_command.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ final class QueryCommand extends CommandBase {
1515
QueryCommand({
1616
required super.environment,
1717
required this.configs,
18-
super.verbose = false,
1918
super.help = false,
2019
super.usageLineLength,
2120
}) {
@@ -45,13 +44,11 @@ final class QueryCommand extends CommandBase {
4544
addSubcommand(QueryBuildersCommand(
4645
environment: environment,
4746
configs: configs,
48-
verbose: verbose,
4947
help: help,
5048
));
5149
addSubcommand(QueryTargetsCommand(
5250
environment: environment,
5351
configs: configs,
54-
verbose: verbose,
5552
help: help,
5653
));
5754
}
@@ -73,7 +70,6 @@ final class QueryBuildersCommand extends CommandBase {
7370
QueryBuildersCommand({
7471
required super.environment,
7572
required this.configs,
76-
super.verbose = false,
7773
super.help = false,
7874
});
7975

@@ -93,7 +89,7 @@ final class QueryBuildersCommand extends CommandBase {
9389
// current platform.
9490
final bool all = parent!.argResults![allFlag]! as bool;
9591
final String? builderName = parent!.argResults![builderFlag] as String?;
96-
if (!verbose) {
92+
if (!environment.verbose) {
9793
environment.logger.status(
9894
'Add --verbose to see detailed information about each builder',
9995
);
@@ -115,7 +111,7 @@ final class QueryBuildersCommand extends CommandBase {
115111
continue;
116112
}
117113
environment.logger.status('"${build.name}" config', indent: 3);
118-
if (!verbose) {
114+
if (!environment.verbose) {
119115
continue;
120116
}
121117
environment.logger.status('gn flags:', indent: 6);
@@ -140,12 +136,11 @@ final class QueryTargetsCommand extends CommandBase {
140136
QueryTargetsCommand({
141137
required super.environment,
142138
required this.configs,
143-
super.verbose = false,
144139
super.help = false,
145140
}) {
146141
// When printing the help/usage for this command, only list all builds
147142
// when the --verbose flag is supplied.
148-
final bool includeCiBuilds = verbose || !help;
143+
final bool includeCiBuilds = environment.verbose || !help;
149144
builds = runnableBuilds(environment, configs, includeCiBuilds);
150145
debugCheckBuilds(builds);
151146
addConfigOption(

tools/engine_tool/lib/src/commands/run_command.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ final class RunCommand extends CommandBase {
1818
RunCommand({
1919
required super.environment,
2020
required Map<String, BuilderConfig> configs,
21-
super.verbose = false,
2221
super.help = false,
2322
super.usageLineLength,
2423
}) {
2524
// When printing the help/usage for this command, only list all builds
2625
// when the --verbose flag is supplied.
27-
final bool includeCiBuilds = verbose || !help;
26+
final bool includeCiBuilds = environment.verbose || !help;
2827
builds = runnableBuilds(environment, configs, includeCiBuilds);
2928
debugCheckBuilds(builds);
3029
// We default to nothing in order to automatically detect attached devices

tools/engine_tool/lib/src/commands/test_command.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ final class TestCommand extends CommandBase {
1717
TestCommand({
1818
required super.environment,
1919
required Map<String, BuilderConfig> configs,
20-
super.verbose = false,
2120
super.help = false,
2221
super.usageLineLength,
2322
}) {
2423
// When printing the help/usage for this command, only list all builds
2524
// when the --verbose flag is supplied.
26-
final bool includeCiBuilds = verbose || !help;
25+
final bool includeCiBuilds = environment.verbose || !help;
2726
builds = runnableBuilds(environment, configs, includeCiBuilds);
2827
debugCheckBuilds(builds);
2928
addConfigOption(

tools/engine_tool/lib/src/dependencies.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import 'environment.dart';
1010
import 'logger.dart';
1111

1212
/// Update Flutter engine dependencies. Returns an exit code.
13-
Future<int> fetchDependencies(
14-
Environment environment, {
15-
bool verbose = false,
16-
}) async {
13+
Future<int> fetchDependencies(Environment environment) async {
1714
if (!environment.processRunner.processManager.canRun('gclient')) {
1815
environment.logger.error('Cannot find the gclient command in your path');
1916
return 1;
2017
}
2118

22-
environment.logger.status('Fetching dependencies... ', newline: verbose);
19+
environment.logger.status(
20+
'Fetching dependencies... ',
21+
newline: environment.verbose,
22+
);
2323

2424
Spinner? spinner;
2525
ProcessRunnerResult result;
2626
try {
27-
if (!verbose) {
27+
if (!environment.verbose) {
2828
spinner = environment.logger.startSpinner();
2929
}
3030

@@ -35,9 +35,9 @@ Future<int> fetchDependencies(
3535
'-D',
3636
],
3737
runInShell: true,
38-
startMode: verbose
39-
? io.ProcessStartMode.inheritStdio
40-
: io.ProcessStartMode.normal,
38+
startMode: environment.verbose
39+
? io.ProcessStartMode.inheritStdio
40+
: io.ProcessStartMode.normal,
4141
);
4242
} finally {
4343
spinner?.finish();
@@ -48,7 +48,7 @@ Future<int> fetchDependencies(
4848

4949
// Verbose mode already logged output by making the child process inherit
5050
// this process's stdio handles.
51-
if (!verbose) {
51+
if (!environment.verbose) {
5252
environment.logger.error('Output:\n${result.output}');
5353
}
5454
}

tools/engine_tool/lib/src/environment.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ final class Environment {
2424
required this.logger,
2525
required this.platform,
2626
required this.processRunner,
27+
this.verbose = false,
2728
});
2829

30+
/// Whether the tool should be considered running in "verbose" mode.
31+
final bool verbose;
32+
2933
/// The host OS and architecture that the tool is running on.
3034
final ffi.Abi abi;
3135

tools/engine_tool/test/build_command_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,12 @@ void main() {
398398
() async {
399399
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
400400
cannedProcesses: cannedProcesses,
401+
verbose: true,
401402
);
402403
try {
403404
final ToolCommandRunner runner = ToolCommandRunner(
404405
environment: testEnv.environment,
405406
configs: configs,
406-
verbose: true,
407407
help: true,
408408
);
409409
final int result = await runner.run(<String>[

tools/engine_tool/test/utils.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class TestEnvironment {
5656
Engine engine, {
5757
Logger? logger,
5858
ffi.Abi abi = ffi.Abi.macosArm64,
59+
bool verbose = false,
5960
this.cannedProcesses = const <CannedProcess>[],
6061
}) {
6162
logger ??= Logger.test();
@@ -78,13 +79,15 @@ class TestEnvironment {
7879
throw UnimplementedError('onRun');
7980
})),
8081
logger: logger,
82+
verbose: verbose,
8183
);
8284
}
8385

8486
factory TestEnvironment.withTestEngine({
8587
bool withRbe = false,
8688
ffi.Abi abi = ffi.Abi.linuxX64,
8789
List<CannedProcess> cannedProcesses = const <CannedProcess>[],
90+
bool verbose = false,
8891
}) {
8992
final io.Directory rootDir = io.Directory.systemTemp.createTempSync('et');
9093
final TestEngine engine = TestEngine.createTemp(rootDir: rootDir);
@@ -107,8 +110,12 @@ class TestEnvironment {
107110
}
108111
return false;
109112
});
110-
final TestEnvironment testEnvironment = TestEnvironment(engine,
111-
abi: abi, cannedProcesses: cannedProcesses + <CannedProcess>[cannedGn]);
113+
final TestEnvironment testEnvironment = TestEnvironment(
114+
engine,
115+
abi: abi,
116+
cannedProcesses: cannedProcesses + <CannedProcess>[cannedGn],
117+
verbose: verbose,
118+
);
112119
return testEnvironment;
113120
}
114121

@@ -206,7 +213,8 @@ Matcher containsCommand(CommandMatcher commandMatcher) => (dynamic processes) {
206213
/// command[5] == 'flutter/fml:fml_arc_unittests';
207214
/// })
208215
/// );
209-
Matcher doesNotContainCommand(CommandMatcher commandMatcher) => (dynamic processes) {
216+
Matcher doesNotContainCommand(CommandMatcher commandMatcher) =>
217+
(dynamic processes) {
210218
Expect.type<List<ExecutedProcess>>(processes);
211219
final List<List<String>> commands = (processes as List<ExecutedProcess>)
212220
.map((ExecutedProcess process) => process.command)

0 commit comments

Comments
 (0)