Add --rbe-force-local flag to force rbe task execution to happen on the local machine (flutter/engine#55635)
`build`, `test`, and `run` commands all support the `--exec-strategy`
flag ('auto', 'local', 'remote').
This flag controls the RBE task execution strategy (when RBE is
enabled).
Closes #150877
This commit is contained in:
@@ -7,6 +7,7 @@ import 'dart:io' as io;
|
||||
import 'package:engine_build_configs/engine_build_configs.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
import 'commands/flags.dart';
|
||||
import 'environment.dart';
|
||||
import 'label.dart';
|
||||
import 'logger.dart';
|
||||
@@ -119,6 +120,20 @@ String demangleConfigName(Environment env, String name) {
|
||||
return _doNotMangle(env, name) ? name : '${_osPrefix(env)}$name';
|
||||
}
|
||||
|
||||
/// Make an RbeConfig.
|
||||
RbeConfig makeRbeConfig(String execStrategy) {
|
||||
switch (execStrategy) {
|
||||
case buildStrategyFlagValueAuto:
|
||||
return const RbeConfig();
|
||||
case buildStrategyFlagValueLocal:
|
||||
return const RbeConfig(execStrategy: RbeExecStrategy.local);
|
||||
case buildStrategyFlagValueRemote:
|
||||
return const RbeConfig(execStrategy: RbeExecStrategy.remote);
|
||||
default:
|
||||
throw FatalError('Unknown RBE execution strategy "$execStrategy"');
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the build target in the environment.
|
||||
Future<int> runBuild(
|
||||
Environment environment,
|
||||
@@ -127,6 +142,7 @@ Future<int> runBuild(
|
||||
List<String> extraGnArgs = const <String>[],
|
||||
List<Label> targets = const <Label>[],
|
||||
int concurrency = 0,
|
||||
RbeConfig rbeConfig = const RbeConfig(),
|
||||
}) async {
|
||||
final List<String> gnArgs = <String>[
|
||||
if (!enableRbe) '--no-rbe',
|
||||
@@ -140,6 +156,7 @@ Future<int> runBuild(
|
||||
abi: environment.abi,
|
||||
engineSrcDir: environment.engine.srcDir,
|
||||
build: build,
|
||||
rbeConfig: rbeConfig,
|
||||
concurrency: concurrency,
|
||||
extraGnArgs: gnArgs,
|
||||
runTests: false,
|
||||
|
||||
@@ -30,11 +30,7 @@ final class BuildCommand extends CommandBase {
|
||||
builds,
|
||||
);
|
||||
addConcurrencyOption(argParser);
|
||||
argParser.addFlag(
|
||||
rbeFlag,
|
||||
defaultsTo: environment.hasRbeConfigInTree(),
|
||||
help: 'RBE is enabled by default when available.',
|
||||
);
|
||||
addRbeOptions(argParser, environment);
|
||||
argParser.addFlag(
|
||||
ltoFlag,
|
||||
help: 'Whether LTO should be enabled for a build. Default is disabled',
|
||||
@@ -110,6 +106,7 @@ et build //flutter/fml:fml_benchmarks # Build a specific target in `//flutter/f
|
||||
extraGnArgs: extraGnArgs,
|
||||
targets: allTargets.toList(),
|
||||
enableRbe: useRbe,
|
||||
rbeConfig: makeRbeConfig(argResults![buildStrategyFlag] as String),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,3 +68,29 @@ void addConcurrencyOption(ArgParser parser) {
|
||||
help: 'Specify the concurrency level to use for the ninja build.',
|
||||
);
|
||||
}
|
||||
|
||||
/// Adds the --rbe and --exec-stragey flags.
|
||||
void addRbeOptions(ArgParser parser, Environment environment) {
|
||||
parser.addFlag(
|
||||
rbeFlag,
|
||||
defaultsTo: environment.hasRbeConfigInTree(),
|
||||
help: 'RBE is enabled by default when available.',
|
||||
);
|
||||
parser.addOption(
|
||||
buildStrategyFlag,
|
||||
allowed: [
|
||||
buildStrategyFlagValueAuto,
|
||||
buildStrategyFlagValueLocal,
|
||||
buildStrategyFlagValueRemote,
|
||||
],
|
||||
allowedHelp: {
|
||||
buildStrategyFlagValueAuto:
|
||||
'If RBE is enabled, use remote builds, otherwise fallback to local builds.',
|
||||
buildStrategyFlagValueLocal:
|
||||
'Use local builds regardless of RBE being enabled.',
|
||||
buildStrategyFlagValueRemote:
|
||||
'Use RBE builds, and fail if they are not available instead of falling back.'
|
||||
},
|
||||
defaultsTo: buildStrategyFlagValueAuto,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@ const String builderFlag = 'builder';
|
||||
const String concurrencyFlag = 'concurrency';
|
||||
const String configFlag = 'config';
|
||||
const String dryRunFlag = 'dry-run';
|
||||
const String buildStrategyFlag = 'build-strategy';
|
||||
const String buildStrategyFlagValueAuto = 'auto';
|
||||
const String buildStrategyFlagValueLocal = 'local';
|
||||
const String buildStrategyFlagValueRemote = 'remote';
|
||||
const String ltoFlag = 'lto';
|
||||
const String quietFlag = 'quiet';
|
||||
const String rbeFlag = 'rbe';
|
||||
|
||||
@@ -41,12 +41,7 @@ final class RunCommand extends CommandBase {
|
||||
defaultsTo: '',
|
||||
);
|
||||
addConcurrencyOption(argParser);
|
||||
argParser.addFlag(
|
||||
rbeFlag,
|
||||
defaultsTo: environment.hasRbeConfigInTree(),
|
||||
help: 'RBE is enabled by default when available.',
|
||||
);
|
||||
|
||||
addRbeOptions(argParser, environment);
|
||||
_flutterTool = flutterTool ?? FlutterTool.fromEnvironment(environment);
|
||||
}
|
||||
|
||||
@@ -186,6 +181,7 @@ See `flutter run --help` for a listing
|
||||
concurrency: concurrency,
|
||||
extraGnArgs: extraGnArgs,
|
||||
enableRbe: useRbe,
|
||||
rbeConfig: makeRbeConfig(argResults![buildStrategyFlag] as String),
|
||||
);
|
||||
if (r != 0) {
|
||||
throw FatalError('Failed to build host (${hostBuild.name})');
|
||||
@@ -200,6 +196,7 @@ See `flutter run --help` for a listing
|
||||
extraGnArgs: extraGnArgs,
|
||||
enableRbe: useRbe,
|
||||
targets: buildTargetsForShell,
|
||||
rbeConfig: makeRbeConfig(argResults![buildStrategyFlag] as String),
|
||||
);
|
||||
if (r != 0) {
|
||||
throw FatalError('Failed to build target (${targetBuild.name})');
|
||||
|
||||
@@ -32,11 +32,7 @@ final class TestCommand extends CommandBase {
|
||||
builds,
|
||||
);
|
||||
addConcurrencyOption(argParser);
|
||||
argParser.addFlag(
|
||||
rbeFlag,
|
||||
defaultsTo: environment.hasRbeConfigInTree(),
|
||||
help: 'RBE is enabled by default when available.',
|
||||
);
|
||||
addRbeOptions(argParser, environment);
|
||||
}
|
||||
|
||||
/// List of compatible builds.
|
||||
@@ -102,7 +98,8 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f
|
||||
// Make sure there is at least one test target.
|
||||
final List<ExecutableBuildTarget> testTargets = buildTargets
|
||||
.whereType<ExecutableBuildTarget>()
|
||||
.where((ExecutableBuildTarget t) => t.testOnly).toList();
|
||||
.where((ExecutableBuildTarget t) => t.testOnly)
|
||||
.toList();
|
||||
|
||||
if (testTargets.isEmpty) {
|
||||
environment.logger.error('No test targets found');
|
||||
@@ -115,6 +112,7 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f
|
||||
concurrency: concurrency,
|
||||
targets: testTargets.map((BuildTarget target) => target.label).toList(),
|
||||
enableRbe: useRbe,
|
||||
rbeConfig: makeRbeConfig(argResults![buildStrategyFlag] as String),
|
||||
);
|
||||
if (buildExitCode != 0) {
|
||||
return buildExitCode;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:engine_build_configs/engine_build_configs.dart';
|
||||
import 'package:engine_tool/src/build_utils.dart';
|
||||
import 'package:engine_tool/src/commands/flags.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('makeRbeConfig local selects local strategy', () {
|
||||
expect(makeRbeConfig(buildStrategyFlagValueLocal),
|
||||
equals(const RbeConfig(execStrategy: RbeExecStrategy.local)));
|
||||
});
|
||||
|
||||
test('makeRbeConfig remote selects remote strategy', () {
|
||||
expect(makeRbeConfig(buildStrategyFlagValueRemote),
|
||||
equals(const RbeConfig(execStrategy: RbeExecStrategy.remote)));
|
||||
});
|
||||
|
||||
test('makeRbeConfig auto selects racing strategy', () {
|
||||
expect(makeRbeConfig(buildStrategyFlagValueAuto).execStrategy,
|
||||
equals(RbeExecStrategy.racing));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user