blob: 69eaca9f4b879dd70d9c1ba105b576730fa7a7d3 [file] [log] [blame]
Ben Segall9e36ef62023-04-18 22:09:28 +00001#!/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
6binary that populates the log paths correctly for builds run via autoninja
7Call this script with the same -C argument used for the autoninja build
8Example usage:
9$ reclientreport -C out/my-ninja-out
10"""
11
12import argparse
13import os
14import subprocess
15import sys
Ben Segallf1390e52023-08-17 17:00:11 +000016import tarfile
17import tempfile
Ben Segall9e36ef62023-04-18 22:09:28 +000018
Ben Segall6b62f422023-04-20 13:29:36 +000019import reclient_helper
Ben Segall9e36ef62023-04-18 22:09:28 +000020
21
Ben Segallf1390e52023-08-17 17:00:11 +000022# TODO(b/296402157): Remove once reclientreport binary saves all logs on windows
23def temp_win_impl__b_296402157(out_dir):
Mike Frysinger124bb8e2023-09-06 05:48:55 +000024 '''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(f'Created log file at {f.name}. Please attach this to your bug '
32 'report!')
Ben Segallf1390e52023-08-17 17:00:11 +000033
34
Ben Segall9e36ef62023-04-18 22:09:28 +000035def main():
Mike Frysinger124bb8e2023-09-06 05:48:55 +000036 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)
Ben Segall9e36ef62023-04-18 22:09:28 +000042
Mike Frysinger124bb8e2023-09-06 05:48:55 +000043 args, extras = parser.parse_known_args()
44 if sys.platform.startswith('win'):
45 temp_win_impl__b_296402157(args.ninja_out)
46 return
47 if args.args and args.args[0] == '--':
48 args.args.pop(0)
49 if extras:
50 args.args = extras + args.args
Ben Segall9e36ef62023-04-18 22:09:28 +000051
Mike Frysinger124bb8e2023-09-06 05:48:55 +000052 reclient_helper.set_reproxy_path_flags(args.ninja_out, make_dirs=False)
53 reclient_bin_dir = reclient_helper.find_reclient_bin_dir()
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)
Ben Segall9e36ef62023-04-18 22:09:28 +000060
61
62if __name__ == '__main__':
Mike Frysinger124bb8e2023-09-06 05:48:55 +000063 sys.exit(main())