blob: 751a32f5f69100de1281c267764f4a22270dc70c [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 Watanabe3a5cc402023-05-22 04:59:44 +000035 # TODO(b/283714114): support single file compile with '^'.
36 # The arguments need to be passed as a double quoted string on Windows.
37 #
38 # pylint: disable=line-too-long
39 # See also https://source.chromium.org/chromium/chromium/tools/depot_tools/+/main:autoninja.py;l=33-42;drc=eb2866e6541607f63cdc50038379886c77f17506
40
Junji Watanabe48fcabe2023-04-21 01:28:51 +000041 if not _use_remoteexec(argv):
42 print(
43 "`use_remoteexec=true` is not detected.\n"
44 "Please run `siso` command directly.",
45 file=sys.stderr)
46 return 1
47
Junji Watanabe607284d2023-04-20 03:14:52 +000048 with reclient_helper.build_context(argv) as ret_code:
49 if ret_code:
50 return ret_code
51 argv = [
52 argv[0],
53 'ninja',
54 # Do not authenticate when using Reproxy.
55 '-project=',
56 '-reapi_instance=',
57 ] + argv[1:]
58 return siso.main(argv)
59
60
61if __name__ == '__main__':
62 try:
63 sys.exit(main(sys.argv))
64 except KeyboardInterrupt:
65 sys.exit(1)