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

Commit 045a803

Browse files
committed
[et] Properly disable RBE with a flag or when not available
1 parent 599dbd7 commit 045a803

File tree

6 files changed

+139
-14
lines changed

6 files changed

+139
-14
lines changed

tools/engine_tool/lib/src/build_utils.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:io' as io show Directory;
6+
57
import 'package:engine_build_configs/engine_build_configs.dart';
8+
import 'package:path/path.dart' as p;
69

710
import 'environment.dart';
811
import 'logger.dart';
@@ -63,13 +66,30 @@ void debugCheckBuilds(List<Build> builds) {
6366
}
6467

6568
/// Build the build target in the environment.
66-
Future<int> runBuild(Environment environment, Build build) async {
69+
Future<int> runBuild(
70+
Environment environment,
71+
Build build, {
72+
List<String> extraGnArgs = const <String>[],
73+
}) async {
74+
// If RBE config files aren't in the tree, then disable RBE.
75+
final String rbeConfigPath = p.join(
76+
environment.engine.srcDir.path,
77+
'flutter',
78+
'build',
79+
'rbe',
80+
);
81+
final List<String> gnArgs = <String>[
82+
...extraGnArgs,
83+
if (!io.Directory(rbeConfigPath).existsSync()) '--no-rbe',
84+
];
85+
6786
final BuildRunner buildRunner = BuildRunner(
6887
platform: environment.platform,
6988
processRunner: environment.processRunner,
7089
abi: environment.abi,
7190
engineSrcDir: environment.engine.srcDir,
7291
build: build,
92+
extraGnArgs: gnArgs,
7393
runTests: false,
7494
);
7595

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ final class BuildCommand extends CommandBase {
3131
config.name: config.gn.join(' '),
3232
},
3333
);
34+
argParser.addFlag(
35+
rbeFlag,
36+
defaultsTo: true,
37+
help: 'RBE is enabled by default when available. Use --no-rbe to '
38+
'disable it.',
39+
);
3440
}
3541

3642
/// List of compatible builds.
@@ -45,14 +51,19 @@ final class BuildCommand extends CommandBase {
4551
@override
4652
Future<int> run() async {
4753
final String configName = argResults![configFlag] as String;
54+
final bool useRbe = argResults![rbeFlag] as bool;
4855
final Build? build =
4956
builds.where((Build build) => build.name == configName).firstOrNull;
5057
if (build == null) {
5158
environment.logger.error('Could not find config $configName');
5259
return 1;
5360
}
5461

62+
final List<String> extraGnArgs = <String>[
63+
if (!useRbe) '--no-rbe',
64+
];
65+
5566
// TODO(loic-sharma): Fetch dependencies if needed.
56-
return runBuild(environment, build);
67+
return runBuild(environment, build, extraGnArgs: extraGnArgs);
5768
}
5869
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ const String builderFlag = 'builder';
1616
const String configFlag = 'config';
1717
const String dryRunFlag = 'dry-run';
1818
const String quietFlag = 'quiet';
19+
const String rbeFlag = 'rbe';
1920
const String runTestsFlag = 'run-tests';
2021
const String verboseFlag = 'verbose';

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ final class RunCommand extends CommandBase {
3737
build.name: build.gn.join(' '),
3838
},
3939
);
40+
argParser.addFlag(
41+
rbeFlag,
42+
defaultsTo: true,
43+
help: 'RBE is enabled by default when available. Use --no-rbe to '
44+
'disable it.',
45+
);
4046
}
4147

4248
/// List of compatible builds.
@@ -142,15 +148,20 @@ final class RunCommand extends CommandBase {
142148
return 1;
143149
}
144150

151+
final bool useRbe = argResults![rbeFlag] as bool;
152+
final List<String> extraGnArgs = <String>[
153+
if (!useRbe) '--no-rbe',
154+
];
155+
145156
// First build the host.
146-
int r = await runBuild(environment, hostBuild);
157+
int r = await runBuild(environment, hostBuild, extraGnArgs: extraGnArgs);
147158
if (r != 0) {
148159
return r;
149160
}
150161

151162
// Now build the target if it isn't the same.
152163
if (hostBuild.name != build.name) {
153-
r = await runBuild(environment, build);
164+
r = await runBuild(environment, build, extraGnArgs: extraGnArgs);
154165
if (r != 0) {
155166
return r;
156167
}

tools/engine_tool/test/build_command_test.dart

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:engine_tool/src/commands/command_runner.dart';
1313
import 'package:engine_tool/src/environment.dart';
1414
import 'package:engine_tool/src/logger.dart';
1515
import 'package:litetest/litetest.dart';
16+
import 'package:path/path.dart' as path;
1617
import 'package:platform/platform.dart';
1718
import 'package:process_fakes/process_fakes.dart';
1819
import 'package:process_runner/process_runner.dart';
@@ -54,23 +55,28 @@ void main() {
5455
'win_test_config': winTestConfig,
5556
};
5657

57-
(Environment, List<List<String>>) linuxEnv(Logger logger) {
58+
(Environment, List<List<String>>) linuxEnv(Logger logger, {Engine? eng}) {
59+
eng ??= engine;
5860
final List<List<String>> runHistory = <List<String>>[];
5961
return (
6062
Environment(
6163
abi: ffi.Abi.linuxX64,
62-
engine: engine,
64+
engine: eng,
6365
platform: FakePlatform(
6466
operatingSystem: Platform.linux,
6567
resolvedExecutable: io.Platform.resolvedExecutable),
6668
processRunner: ProcessRunner(
67-
processManager: FakeProcessManager(onStart: (List<String> command) {
68-
runHistory.add(command);
69-
return FakeProcess();
70-
}, onRun: (List<String> command) {
71-
runHistory.add(command);
72-
return io.ProcessResult(81, 0, '', '');
73-
}),
69+
processManager: FakeProcessManager(
70+
canRun: (Object? exe, {String? workingDirectory}) => true,
71+
onStart: (List<String> command) {
72+
runHistory.add(command);
73+
return FakeProcess();
74+
},
75+
onRun: (List<String> command) {
76+
runHistory.add(command);
77+
return io.ProcessResult(81, 0, '', '');
78+
},
79+
),
7480
),
7581
logger: logger,
7682
),
@@ -82,7 +88,7 @@ void main() {
8288
final Logger logger = Logger.test();
8389
final (Environment env, _) = linuxEnv(logger);
8490
final List<Build> result = runnableBuilds(env, configs);
85-
expect(result.length, equals(6));
91+
expect(result.length, equals(8));
8692
expect(result[0].name, equals('build_name'));
8793
});
8894

@@ -157,4 +163,69 @@ void main() {
157163
expect(result, equals(0));
158164
expect(runHistory.length, lessThanOrEqualTo(3));
159165
});
166+
167+
test('build command runs rbe on an rbe build', () async {
168+
final Logger logger = Logger.test();
169+
final (Environment env, List<List<String>> runHistory) = linuxEnv(logger);
170+
final ToolCommandRunner runner = ToolCommandRunner(
171+
environment: env,
172+
configs: configs,
173+
);
174+
final int result = await runner.run(<String>[
175+
'build',
176+
'--config',
177+
'android_debug_rbe_arm64',
178+
]);
179+
expect(result, equals(0));
180+
expect(runHistory[0][0], contains(path.join('tools', 'gn')));
181+
expect(runHistory[0][4], equals('--rbe'));
182+
expect(runHistory[1][0], contains(path.join('reclient', 'bootstrap')));
183+
});
184+
185+
test('build command does not run rbe when disabled', () async {
186+
final Logger logger = Logger.test();
187+
final (Environment env, List<List<String>> runHistory) = linuxEnv(logger);
188+
final ToolCommandRunner runner = ToolCommandRunner(
189+
environment: env,
190+
configs: configs,
191+
);
192+
final int result = await runner.run(<String>[
193+
'build',
194+
'--config',
195+
'android_debug_rbe_arm64',
196+
'--no-rbe',
197+
]);
198+
expect(result, equals(0));
199+
expect(runHistory[0][0], contains(path.join('tools', 'gn')));
200+
expect(runHistory[0], doesNotContainAny(<String>['--rbe']));
201+
expect(runHistory[1][0], contains(path.join('ninja', 'ninja')));
202+
});
203+
204+
test('build command does not run rbe when rbe configs do not exist', () async {
205+
final Logger logger = Logger.test();
206+
final io.Directory rootDir = io.Directory.systemTemp.createTempSync('et');
207+
try {
208+
final Engine eng = TestEngine.createTemp(rootDir: rootDir);
209+
final (Environment env, List<List<String>> runHistory) = linuxEnv(logger, eng: eng);
210+
final ToolCommandRunner runner = ToolCommandRunner(
211+
environment: env,
212+
configs: configs,
213+
);
214+
final int result = await runner.run(<String>[
215+
'build',
216+
'--config',
217+
'android_debug_rbe_arm64',
218+
]);
219+
expect(result, equals(0));
220+
expect(runHistory[0][0], contains(path.join('tools', 'gn')));
221+
expect(runHistory[0], doesNotContainAny(<String>['--rbe']));
222+
expect(runHistory[1][0], contains(path.join('ninja', 'ninja')));
223+
} finally {
224+
try {
225+
rootDir.deleteSync(recursive: true);
226+
} catch (_) {
227+
// Ignore temp directory deletion failure.
228+
}
229+
}
230+
});
160231
}

tools/engine_tool/test/fixtures.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ String testConfig(String os) => '''
7070
"config": "android_debug_arm64",
7171
"targets": ["ninja_target"]
7272
}
73+
},
74+
{
75+
"drone_dimensions": [
76+
"os=$os"
77+
],
78+
"gn": ["--gn-arg", "--lto", "--no-goma", "--rbe"],
79+
"name": "android_debug_rbe_arm64",
80+
"ninja": {
81+
"config": "android_debug_rbe_arm64",
82+
"targets": ["ninja_target"]
83+
}
7384
}
7485
],
7586
"generators": {

0 commit comments

Comments
 (0)