From 566c3772a08284da4a857a0f791e36eb0428f50c Mon Sep 17 00:00:00 2001 From: Michael Savigny Date: Fri, 9 Feb 2024 14:59:58 +0000 Subject: [PATCH] Changing location of temp racing directory. Put temporary racing artifacts into .reproxy_tmp/racing/- in prep for permitting simultaneous builds against the same output directory. Bug: b/321554715 Change-Id: Iae9af9aed03197184e6d11da010d0bb10779ed23 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5273209 Reviewed-by: Takuto Ikuta Commit-Queue: Michael Savigny Reviewed-by: Junji Watanabe Reviewed-by: Ben Segall --- reclient_helper.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/reclient_helper.py b/reclient_helper.py index 53f939edbd..cd65243a57 100644 --- a/reclient_helper.py +++ b/reclient_helper.py @@ -6,6 +6,7 @@ the reclient lifecycle safely. It will automatically start reproxy before running ninja and stop reproxy when build stops for any reason e.g. build completion, keyboard interrupt etc.""" +import atexit import contextlib import datetime import hashlib @@ -194,14 +195,23 @@ def set_reproxy_path_flags(out_dir, make_dirs=True): Windows Only: RBE_server_address=pipe://md5(out_dir/.reproxy_tmp)/reproxy.pipe """ + os.environ.setdefault("AUTONINJA_BUILD_ID", str(uuid.uuid4())) + run_sub_dir = datetime_now().strftime( + '%Y%m%dT%H%M%S.%f') + "_" + os.environ["AUTONINJA_BUILD_ID"] tmp_dir = os.path.abspath(os.path.join(out_dir, '.reproxy_tmp')) log_dir = os.path.join(tmp_dir, 'logs') - run_log_dir = os.path.join( - log_dir, - datetime_now().strftime('%Y%m%dT%H%M%S.%f') + "_" + - os.environ["AUTONINJA_BUILD_ID"]) + run_log_dir = os.path.join(log_dir, run_sub_dir) racing_dir = os.path.join(tmp_dir, 'racing') + run_racing_dir = os.path.join(racing_dir, run_sub_dir) + + # Clear out old racing directories, if there are any. They are kept + # for a single build in the event the contents are needed for debugging. + if os.path.exists(racing_dir): + for rcd in os.listdir(racing_dir): + if os.path.isdir(os.path.join(racing_dir, rcd)): + shutil.rmtree(os.path.join(racing_dir, rcd)) + cache_dir = find_cache_dir(tmp_dir) if make_dirs: if os.path.isfile(os.path.join(log_dir, "rbe_metrics.txt")): @@ -219,6 +229,8 @@ def set_reproxy_path_flags(out_dir, make_dirs=True): os.makedirs(run_log_dir, exist_ok=True) os.makedirs(cache_dir, exist_ok=True) os.makedirs(racing_dir, exist_ok=True) + os.makedirs(run_racing_dir, exist_ok=True) + old_log_dirs = [ d for d in os.listdir(log_dir) if os.path.isdir(os.path.join(log_dir, d)) @@ -233,7 +245,7 @@ def set_reproxy_path_flags(out_dir, make_dirs=True): os.environ.setdefault("RBE_proxy_log_dir", run_log_dir) os.environ.setdefault("RBE_log_dir", run_log_dir) os.environ.setdefault("RBE_cache_dir", cache_dir) - os.environ.setdefault("RBE_racing_tmp_dir", racing_dir) + os.environ.setdefault("RBE_racing_tmp_dir", run_racing_dir) if sys.platform.startswith('win'): pipe_dir = hashlib.md5(tmp_dir.encode()).hexdigest() os.environ.setdefault("RBE_server_address", @@ -294,7 +306,9 @@ def build_context(argv, tool): try: set_reproxy_path_flags(ninja_out) except OSError as e: - print(f"Error creating reproxy_tmp in output dir: {e}", file=sys.stderr) + print( + f"Error creating reproxy temporary directories in output dir: {e}", + file=sys.stderr) yield 1 return