From 144724e08598f5885614d6864282256a2619611b Mon Sep 17 00:00:00 2001 From: Jonas Termansen Date: Wed, 3 Apr 2024 09:28:30 +0000 Subject: [PATCH] [infra] Simplify RBE startup/shutdown logic. Change-Id: I45d99a1386bfb0d3af94a563cf5626d9bc7b4f68 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360743 Reviewed-by: Alexander Thomas Commit-Queue: Alexander Thomas --- tools/build.py | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/tools/build.py b/tools/build.py index bd12647aba3..62a57022c44 100755 --- a/tools/build.py +++ b/tools/build.py @@ -133,41 +133,31 @@ bootstrap_path = None def StartRBE(out_dir, env): global rbe_started, bootstrap_path - rbe = 'rbe' - if rbe_started: - return True - args_gn_path = os.path.join(out_dir, 'args.gn') - rbe_dir = 'buildtools/reclient' - with open(args_gn_path, 'r') as fp: - for line in fp: - if 'rbe_dir' in line: - words = line.split() - rbe_dir = words[2][1:-1] # rbe_dir = "/path/to/rbe" - if not rbe_dir: - print(f'Could not find {rbe} for {out_dir}') - return False - 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 - bootstrap = 'bootstrap' - bootstrap_path = os.path.join(rbe_dir, bootstrap) - bootstrap_command = [bootstrap_path] - process = subprocess.Popen(bootstrap_command, env=env) - process.wait() - if process.returncode != 0: - print(f"Failed to start {rbe}") - return False - rbe_started = True + if not rbe_started: + rbe_dir = 'buildtools/reclient' + with open(os.path.join(out_dir, 'args.gn'), 'r') as fp: + for line in fp: + if 'rbe_dir' in line: + words = line.split() + rbe_dir = words[2][1:-1] # rbe_dir = "/path/to/rbe" + bootstrap_path = os.path.join(rbe_dir, 'bootstrap') + bootstrap_command = [bootstrap_path] + process = subprocess.Popen(bootstrap_command, env=env) + process.wait() + if process.returncode != 0: + print('Failed to start RBE') + return False + rbe_started = True return True def StopRBE(env): global rbe_started, bootstrap_path - if not rbe_started: - return - bootstrap_command = [bootstrap_path, '--shutdown'] - process = subprocess.Popen(bootstrap_command, env=env) - process.wait() + if rbe_started: + bootstrap_command = [bootstrap_path, '--shutdown'] + process = subprocess.Popen(bootstrap_command, env=env) + process.wait() + rbe_started = False # Returns a tuple (build_config, command to run, whether rbe is used)