From 9e36ef60d0b3b3da1d79cf388275697281d27f21 Mon Sep 17 00:00:00 2001 From: Ben Segall Date: Tue, 18 Apr 2023 22:09:28 +0000 Subject: [PATCH] Add convenience wrapper for reclientreport for autoninja users This is designed to be called by a developer when they want to submit an reclient bug report. Developers could just call the //buildtools/reclient/reclientreport binary directly but this wrapper provides an easier way to set the same log flags that are set by ninja_reclient. I dont think we should bundle this logic into autoninja as this is not required in 99% of builds. Bug: b/277763387 Change-Id: I0204b6acc22f199b461ef710d0dfd07e05534af7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4414921 Reviewed-by: Gavin Mak Commit-Queue: Gavin Mak Reviewed-by: Takuto Ikuta Auto-Submit: Ben Segall --- OWNERS | 2 ++ RECLIENT_OWNERS | 2 ++ ninja_reclient.py | 13 +++++++------ reclientreport | 8 ++++++++ reclientreport.bat | 12 ++++++++++++ reclientreport.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 RECLIENT_OWNERS create mode 100755 reclientreport create mode 100644 reclientreport.bat create mode 100644 reclientreport.py diff --git a/OWNERS b/OWNERS index fe3a5388d..cbbf94e8f 100644 --- a/OWNERS +++ b/OWNERS @@ -14,8 +14,10 @@ per-file gn*=dpranke@google.com per-file ninja*=dpranke@google.com per-file ninja*=thakis@chromium.org per-file ninja_reclient.py=file://BUILD_OWNERS +per-file ninja_reclient.py=file://RECLIENT_OWNERS per-file ninjalog*=tikuta@chromium.org per-file post_build_ninja_summary.py=brucedawson@chromium.org +per-file reclientreport*=file://RECLIENT_OWNERS per-file presubmit*.py=brucedawson@chromium.org diff --git a/RECLIENT_OWNERS b/RECLIENT_OWNERS new file mode 100644 index 000000000..e2e668b4a --- /dev/null +++ b/RECLIENT_OWNERS @@ -0,0 +1,2 @@ +abdelaal@google.com +bentekkie@google.com diff --git a/ninja_reclient.py b/ninja_reclient.py index 4f6cf2b3c..1ed00d83a 100755 --- a/ninja_reclient.py +++ b/ninja_reclient.py @@ -72,10 +72,10 @@ def find_rel_ninja_out_dir(args): return '.' -def set_reproxy_path_flags(out_dir): +def set_reproxy_path_flags(out_dir, make_dirs=True): """Helper to setup the logs and cache directories for reclient - Creates the following directory structure: + Creates the following directory structure if make_dirs is true: out_dir/ .reproxy_tmp/ logs/ @@ -92,14 +92,15 @@ def set_reproxy_path_flags(out_dir): RBE_server_address=pipe://md5(out_dir/.reproxy_tmp)/reproxy.pipe """ tmp_dir = os.path.abspath(os.path.join(out_dir, '.reproxy_tmp')) - os.makedirs(tmp_dir, exist_ok=True) log_dir = os.path.join(tmp_dir, 'logs') - os.makedirs(log_dir, exist_ok=True) + cache_dir = os.path.join(tmp_dir, 'cache') + if make_dirs: + os.makedirs(tmp_dir, exist_ok=True) + os.makedirs(log_dir, exist_ok=True) + os.makedirs(cache_dir, exist_ok=True) os.environ.setdefault("RBE_output_dir", log_dir) os.environ.setdefault("RBE_proxy_log_dir", log_dir) os.environ.setdefault("RBE_log_dir", log_dir) - cache_dir = os.path.join(tmp_dir, 'cache') - os.makedirs(cache_dir, exist_ok=True) os.environ.setdefault("RBE_cache_dir", cache_dir) if sys.platform.startswith('win'): pipe_dir = hashlib.md5(tmp_dir.encode()).hexdigest() diff --git a/reclientreport b/reclientreport new file mode 100755 index 000000000..3da4c0108 --- /dev/null +++ b/reclientreport @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +# Copyright 2023 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +base_dir=$(dirname "$0") +PYTHONDONTWRITEBYTECODE=1 exec python3 "$base_dir/reclientreport.py" "$@" \ No newline at end of file diff --git a/reclientreport.bat b/reclientreport.bat new file mode 100644 index 000000000..1a746b9a1 --- /dev/null +++ b/reclientreport.bat @@ -0,0 +1,12 @@ +@echo off +:: Copyright 2023 The Chromium Authors. All rights reserved. +:: Use of this source code is governed by a BSD-style license that can be +:: found in the LICENSE file. +setlocal + +:: Ensure that "depot_tools" is somewhere in PATH so this tool can be used +:: standalone, but allow other PATH manipulations to take priority. +set PATH=%PATH%;%~dp0 + +:: Defer control. +python3 "%~dp0\reclientreport.py" "%*" \ No newline at end of file diff --git a/reclientreport.py b/reclientreport.py new file mode 100644 index 000000000..ca8f1db0c --- /dev/null +++ b/reclientreport.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# Copyright 2023 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +"""This script is a wrapper around the //buildtools/reclient/reclientreport +binary that populates the log paths correctly for builds run via autoninja +Call this script with the same -C argument used for the autoninja build +Example usage: +$ reclientreport -C out/my-ninja-out +""" + +import argparse +import os +import subprocess +import sys + +import ninja_reclient + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--ninja_out", + "-C", + required=True, + help="ninja out directory used for the autoninja build") + parser.add_argument('args', nargs=argparse.REMAINDER) + + args, extras = parser.parse_known_args() + if args.args and args.args[0] == '--': + args.args.pop(0) + if extras: + args.args = extras + args.args + + ninja_reclient.set_reproxy_path_flags(args.ninja_out, make_dirs=False) + reclient_bin_dir = ninja_reclient.find_reclient_bin_dir() + code = subprocess.call([os.path.join(reclient_bin_dir, 'reclientreport')] + + args.args) + if code != 0: + print("Failed to collect logs, make sure that %s/.reproxy_tmp exists" % + args.ninja_out, + file=sys.stderr) + + +if __name__ == '__main__': + sys.exit(main())