From a27993d7c99a80821a7d5a5f593efbfa96afe538 Mon Sep 17 00:00:00 2001 From: Jonas Termansen Date: Tue, 5 Mar 2024 13:22:39 +0000 Subject: [PATCH] [infra] Fix not initializing RBE before gn. Bug: b/296994239 Change-Id: I344f07fa7f389fa5b0f5e65b24168f2d05daacbf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355683 Reviewed-by: William Hesse Commit-Queue: Jonas Termansen --- tools/build.py | 17 +---------------- tools/gn.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/tools/build.py b/tools/build.py index c26be7d971c4..89a5d8a88809 100755 --- a/tools/build.py +++ b/tools/build.py @@ -161,21 +161,6 @@ def StartRBE(out_dir, use_goma, env): if not os.path.exists(rbe_dir) or not os.path.isdir(rbe_dir): print(f'Could not find {rbe} at {rbe_dir}') return False - RBE_cfg = 'RBE_CFG' if HOST_OS == 'win32' else 'RBE_cfg' - RBE_server_address = ('RBE_SERVER_ADDRESS' - if HOST_OS == 'win32' else 'RBE_server_address') - if not use_goma and not RBE_cfg in env: - env[RBE_cfg] = os.path.join( - os.getcwd(), 'build', 'rbe', - 'windows.cfg' if HOST_OS == 'win32' else 'unix.cfg') - if not use_goma and not RBE_server_address in env: - with open(env[RBE_cfg], 'r') as f: - if not any([l.startswith('server_address') for l in f.readlines()]): - schema = 'pipe' if HOST_OS == 'win32' else 'unix' - socket = os.path.join(os.getcwd(), out_dir, 'reproxy.sock') - if HOST_OS == 'win32': - socket = socket.replace('\\', '_').replace(':', '_') - env[RBE_server_address] = f'{schema}://{socket}' bootstrap = 'goma_ctl.py' if use_goma else 'bootstrap' bootstrap_path = os.path.join(rbe_dir, bootstrap) bootstrap_command = [bootstrap_path] @@ -342,7 +327,7 @@ def Main(): env.pop('SDKROOT', None) # Always run GN before building. - gn_py.RunGnOnConfiguredConfigurations(options) + gn_py.RunGnOnConfiguredConfigurations(options, env) # Build all targets for each requested configuration. configs = [] diff --git a/tools/gn.py b/tools/gn.py index 8b22bbb32650..e2116e9e45a5 100755 --- a/tools/gn.py +++ b/tools/gn.py @@ -621,6 +621,26 @@ def parse_args(args): return options +def InitializeRBE(out_dir, env): + RBE_cfg = 'RBE_CFG' if HOST_OS == 'win32' else 'RBE_cfg' + RBE_server_address = ('RBE_SERVER_ADDRESS' + if HOST_OS == 'win32' else 'RBE_server_address') + # Default RBE_cfg to the appropriate configuration file. + if not RBE_cfg in env: + env[RBE_cfg] = os.path.join( + os.getcwd(), 'build', 'rbe', + 'windows.cfg' if HOST_OS == 'win32' else 'unix.cfg') + # Default RBE_server_address to inside the build directory. + if not RBE_server_address in env: + with open(env[RBE_cfg], 'r') as f: + if not any([l.startswith('server_address') for l in f.readlines()]): + schema = 'pipe' if HOST_OS == 'win32' else 'unix' + socket = os.path.join(os.getcwd(), out_dir, 'reproxy.sock') + if HOST_OS == 'win32': + socket = socket.replace('\\', '_').replace(':', '_') + env[RBE_server_address] = f'{schema}://{socket}' + + def ExecutableName(basename): if utils.IsWindows(): return f'{basename}.exe' @@ -652,13 +672,17 @@ def BuildGnCommand(args, mode, arch, target_os, sanitizer, out_dir): return command -def RunGnOnConfiguredConfigurations(args): +def RunGnOnConfiguredConfigurations(args, env={}): + initialized_rbe = False commands = [] for target_os in args.os: for mode in args.mode: for arch in args.arch: for sanitizer in args.sanitizer: out_dir = GetOutDir(mode, arch, target_os, sanitizer) + if args.rbe and not initialized_rbe: + InitializeRBE(out_dir, env) + initialized_rbe = True commands.append( BuildGnCommand(args, mode, arch, target_os, sanitizer, out_dir)) @@ -674,7 +698,7 @@ def cleanup(command): for command in commands: try: - process = subprocess.Popen(command, cwd=DART_ROOT) + process = subprocess.Popen(command, cwd=DART_ROOT, env=env) active_commands.append([command, process]) except Exception as e: print('Error: %s' % e)