@@ -214,8 +214,69 @@ def buildtools_dir():
214214 return '%s-%s' % (host_os, host_cpu)
215215
216216
217+ def setup_rbe(args):
218+ rbe_gn_args = {}
219+ # RBE is default-off. If it is not asked for, then silently keep all default
220+ # flag values.
221+ if not args.rbe:
222+ return rbe_gn_args
223+
224+ if get_host_os() not in ['linux']:
225+ print(
226+ 'The --rbe flag has no effect. RBE is currently only supported on Linux.'
227+ )
228+ return rbe_gn_args
229+
230+ rbe_gn_args['use_rbe'] = True
231+
232+ # When running in CI, the recipes use their own rbe install, and take
233+ # care of starting and stopping the compiler proxy.
234+ running_on_luci = os.environ.get('LUCI_CONTEXT') is not None
235+
236+ # Bootstrap reproxy if not running in CI.
237+ if not running_on_luci:
238+ cipd_reclient_dir = os.path.join(
239+ SRC_ROOT,
240+ 'buildtools',
241+ buildtools_dir(),
242+ 'reclient',
243+ )
244+ bootstrap_path = os.path.join(cipd_reclient_dir, 'bootstrap')
245+ reproxy_path = os.path.join(cipd_reclient_dir, 'reproxy')
246+ rbe_cfg_path = os.path.join(SRC_ROOT, 'build', 'rbe.cfg')
247+ bootstrap_cmd = [
248+ bootstrap_path,
249+ '--re_proxy=' + reproxy_path,
250+ '--automatic_auth=true',
251+ '--cfg=' + rbe_cfg_path,
252+ ]
253+ try:
254+ subprocess.call(bootstrap_cmd, cwd=SRC_ROOT)
255+ except subprocess.CalledProcessError as exc:
256+ print('Failed to boostrap reproxy: ', exc.returncode, exc.output)
257+ return {}
258+
259+ if args.rbe_server_address:
260+ rbe_gn_args['rbe_server_address'] = args.rbe_server_address
261+ if args.rbe_exec_strategy:
262+ rbe_gn_args['rbe_exec_strategy'] = args.rbe_exec_strategy
263+ if args.rbe_dial_timeout:
264+ rbe_gn_args['rbe_dial_timeout'] = args.rbe_dial_timeout
265+ if args.rbe_platform:
266+ rbe_gn_args['rbe_platform'] = args.rbe_platform
267+ if args.rbe_dir:
268+ rbe_gn_args['rbe_dir'] = args.rbe_dir
269+
270+ return rbe_gn_args
271+
272+
217273def setup_goma(args):
218274 goma_gn_args = {}
275+ # If RBE is requested, don't try to use goma.
276+ if args.rbe:
277+ goma_gn_args['use_goma'] = False
278+ goma_gn_args['goma_dir'] = None
279+ return goma_gn_args
219280
220281 # args.goma has three states, True (--goma), False (--no-goma), and
221282 # None (default). In True mode, we force GOMA to be used (and fail
@@ -290,6 +351,8 @@ def to_gn_args(args):
290351
291352 gn_args.update(setup_goma(args))
292353
354+ gn_args.update(setup_rbe(args))
355+
293356 # If building for WASM, set the GN args using 'to_gn_wasm_args' as most
294357 # of the Flutter SDK specific arguments are unused.
295358 if args.target_os == 'wasm' or args.web:
@@ -913,6 +976,41 @@ def parse_args(args):
913976 help='Do not build the host-side development artifacts.'
914977 )
915978
979+ parser.add_argument('--rbe', default=None, action='store_true')
980+ parser.add_argument('--no-rbe', dest='rbe', action='store_false')
981+ parser.add_argument(
982+ '--rbe-server-address',
983+ default=None,
984+ type=str,
985+ help='The reproxy serveraddress'
986+ )
987+ parser.add_argument(
988+ '--rbe-exec-strategy',
989+ default=None,
990+ type=str,
991+ help='The RBE execution strategy.',
992+ choices=['local', 'remote', 'remote_local_fallback', 'racing']
993+ )
994+ parser.add_argument(
995+ '--rbe-dial-timeout',
996+ default=None,
997+ type=str,
998+ help='The timeout for connecting to the local reproxy server.',
999+ )
1000+ parser.add_argument(
1001+ '--rbe-platform',
1002+ default=None,
1003+ type=str,
1004+ help='The RBE "platform" string. This is used to identify remote platform '
1005+ 'settings like the docker image to use to run the command.'
1006+ )
1007+ parser.add_argument(
1008+ '--rbe-dir',
1009+ default=None,
1010+ type=str,
1011+ help='The location of the reclient binaries.'
1012+ )
1013+
9161014 parser.add_argument('--goma', default=None, action='store_true')
9171015 parser.add_argument('--no-goma', dest='goma', action='store_false')
9181016 parser.add_argument(
0 commit comments