Ben Segall | 9e36ef6 | 2023-04-18 22:09:28 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright 2023 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | """This script is a wrapper around the //buildtools/reclient/reclientreport |
| 6 | binary that populates the log paths correctly for builds run via autoninja |
| 7 | Call this script with the same -C argument used for the autoninja build |
| 8 | Example usage: |
| 9 | $ reclientreport -C out/my-ninja-out |
| 10 | """ |
| 11 | |
| 12 | import argparse |
| 13 | import os |
| 14 | import subprocess |
| 15 | import sys |
Ben Segall | f1390e5 | 2023-08-17 17:00:11 +0000 | [diff] [blame^] | 16 | import tarfile |
| 17 | import tempfile |
Ben Segall | 9e36ef6 | 2023-04-18 22:09:28 +0000 | [diff] [blame] | 18 | |
Ben Segall | 6b62f42 | 2023-04-20 13:29:36 +0000 | [diff] [blame] | 19 | import reclient_helper |
Ben Segall | 9e36ef6 | 2023-04-18 22:09:28 +0000 | [diff] [blame] | 20 | |
| 21 | |
Ben Segall | f1390e5 | 2023-08-17 17:00:11 +0000 | [diff] [blame^] | 22 | # TODO(b/296402157): Remove once reclientreport binary saves all logs on windows |
| 23 | def temp_win_impl__b_296402157(out_dir): |
| 24 | '''Temporary implementation until b/296402157 is fixed''' |
| 25 | log_dir = os.path.abspath(os.path.join(out_dir, '.reproxy_tmp', 'logs')) |
| 26 | with tempfile.NamedTemporaryFile(prefix='reclientreport', |
| 27 | suffix='.tar.gz', |
| 28 | delete=False) as f: |
| 29 | with tarfile.open(fileobj=f, mode='w:gz') as tar: |
| 30 | tar.add(log_dir, arcname=os.path.basename(log_dir)) |
| 31 | print( |
| 32 | f'Created log file at {f.name}. Please attach this to your bug report!') |
| 33 | |
| 34 | |
Ben Segall | 9e36ef6 | 2023-04-18 22:09:28 +0000 | [diff] [blame] | 35 | def main(): |
| 36 | parser = argparse.ArgumentParser(description=__doc__) |
| 37 | parser.add_argument("--ninja_out", |
| 38 | "-C", |
| 39 | required=True, |
| 40 | help="ninja out directory used for the autoninja build") |
| 41 | parser.add_argument('args', nargs=argparse.REMAINDER) |
| 42 | |
| 43 | args, extras = parser.parse_known_args() |
Ben Segall | f1390e5 | 2023-08-17 17:00:11 +0000 | [diff] [blame^] | 44 | if sys.platform.startswith('win'): |
| 45 | temp_win_impl__b_296402157(args.ninja_out) |
| 46 | return |
Ben Segall | 9e36ef6 | 2023-04-18 22:09:28 +0000 | [diff] [blame] | 47 | if args.args and args.args[0] == '--': |
| 48 | args.args.pop(0) |
| 49 | if extras: |
| 50 | args.args = extras + args.args |
| 51 | |
Ben Segall | 6b62f42 | 2023-04-20 13:29:36 +0000 | [diff] [blame] | 52 | reclient_helper.set_reproxy_path_flags(args.ninja_out, make_dirs=False) |
| 53 | reclient_bin_dir = reclient_helper.find_reclient_bin_dir() |
Ben Segall | 9e36ef6 | 2023-04-18 22:09:28 +0000 | [diff] [blame] | 54 | code = subprocess.call([os.path.join(reclient_bin_dir, 'reclientreport')] + |
| 55 | args.args) |
| 56 | if code != 0: |
| 57 | print("Failed to collect logs, make sure that %s/.reproxy_tmp exists" % |
| 58 | args.ninja_out, |
| 59 | file=sys.stderr) |
| 60 | |
| 61 | |
| 62 | if __name__ == '__main__': |
| 63 | sys.exit(main()) |