blob: 3088aa23eb6d433756f08105d7e101fa2f77ef4b [file] [log] [blame]
Junji Watanabe607284d2023-04-20 03:14:52 +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"""
6Developers invoke this script via autosiso or autosiso.bat to simply run
Junji Watanabe48fcabe2023-04-21 01:28:51 +00007Siso/Reclient builds.
Junji Watanabe607284d2023-04-20 03:14:52 +00008"""
Junji Watanabe48fcabe2023-04-21 01:28:51 +00009# TODO(b/278976196): `siso ninja` command should handle the reclient and
10# authentication accordingly.
Junji Watanabe607284d2023-04-20 03:14:52 +000011
Junji Watanabe48fcabe2023-04-21 01:28:51 +000012import os
13import re
Junji Watanabe607284d2023-04-20 03:14:52 +000014import sys
15
16import reclient_helper
17import siso
18
19
Junji Watanabe48fcabe2023-04-21 01:28:51 +000020def _use_remoteexec(argv):
21 out_dir = reclient_helper.find_ninja_out_dir(argv)
22 gn_args_path = os.path.join(out_dir, 'args.gn')
23 if not os.path.exists(gn_args_path):
24 return False
25 with open(gn_args_path) as f:
26 for line in f:
27 line_without_comment = line.split('#')[0]
28 if re.search(r'(^|\s)use_remoteexec\s*=\s*true($|\s)',
29 line_without_comment):
30 return True
31 return False
32
33
Junji Watanabe607284d2023-04-20 03:14:52 +000034def main(argv):
Junji Watanabece3e8192023-08-04 07:00:12 +000035 # On Windows the autosiso.bat script passes along the arguments enclosed in
36 # double quotes. This prevents multiple levels of parsing of the special '^'
37 # characters needed when compiling a single file but means that this script
38 # gets called with a single argument containing all of the actual arguments,
39 # separated by spaces. When this case is detected we need to do argument
40 # splitting ourselves. This means that arguments containing actual spaces are
41 # not supported by autoninja, but that is not a real limitation.
42 if (sys.platform.startswith('win') and len(argv) == 2
43 and argv[1].count(' ') > 0):
44 argv = argv[:1] + argv[1].split()
Junji Watanabe3a5cc402023-05-22 04:59:44 +000045
Junji Watanabe48fcabe2023-04-21 01:28:51 +000046 if not _use_remoteexec(argv):
47 print(
48 "`use_remoteexec=true` is not detected.\n"
49 "Please run `siso` command directly.",
50 file=sys.stderr)
51 return 1
52
Ben Segalle49349b2023-06-01 02:54:56 +000053 with reclient_helper.build_context(argv, 'autosiso') as ret_code:
Junji Watanabe607284d2023-04-20 03:14:52 +000054 if ret_code:
55 return ret_code
56 argv = [
57 argv[0],
58 'ninja',
59 # Do not authenticate when using Reproxy.
60 '-project=',
61 '-reapi_instance=',
62 ] + argv[1:]
63 return siso.main(argv)
64
65
66if __name__ == '__main__':
67 try:
68 sys.exit(main(sys.argv))
69 except KeyboardInterrupt:
70 sys.exit(1)