blob: 46b13697ad625a77e9cd9306d13633797b195cfb [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
Ben Segallb64ee7f2023-09-07 15:11:31 +000015import uuid
Junji Watanabe607284d2023-04-20 03:14:52 +000016
17import reclient_helper
18import siso
19
20
Junji Watanabe48fcabe2023-04-21 01:28:51 +000021def _use_remoteexec(argv):
Mike Frysinger124bb8e2023-09-06 05:48:55 +000022 out_dir = reclient_helper.find_ninja_out_dir(argv)
23 gn_args_path = os.path.join(out_dir, 'args.gn')
24 if not os.path.exists(gn_args_path):
25 return False
26 with open(gn_args_path) as f:
27 for line in f:
28 line_without_comment = line.split('#')[0]
29 if re.search(r'(^|\s)use_remoteexec\s*=\s*true($|\s)',
30 line_without_comment):
31 return True
Junji Watanabe48fcabe2023-04-21 01:28:51 +000032 return False
Junji Watanabe48fcabe2023-04-21 01:28:51 +000033
34
Junji Watanabe607284d2023-04-20 03:14:52 +000035def main(argv):
Mike Frysinger124bb8e2023-09-06 05:48:55 +000036 # On Windows the autosiso.bat script passes along the arguments enclosed in
37 # double quotes. This prevents multiple levels of parsing of the special '^'
38 # characters needed when compiling a single file but means that this script
39 # gets called with a single argument containing all of the actual arguments,
40 # separated by spaces. When this case is detected we need to do argument
41 # splitting ourselves. This means that arguments containing actual spaces
42 # are not supported by autoninja, but that is not a real limitation.
43 if (sys.platform.startswith('win') and len(argv) == 2
44 and argv[1].count(' ') > 0):
45 argv = argv[:1] + argv[1].split()
Junji Watanabe3a5cc402023-05-22 04:59:44 +000046
Mike Frysinger124bb8e2023-09-06 05:48:55 +000047 if not _use_remoteexec(argv):
48 print(
49 "`use_remoteexec=true` is not detected.\n"
50 "Please run `siso` command directly.",
51 file=sys.stderr)
52 return 1
Junji Watanabe48fcabe2023-04-21 01:28:51 +000053
Ben Segallb64ee7f2023-09-07 15:11:31 +000054 os.environ.setdefault("AUTONINJA_BUILD_ID", str(uuid.uuid4()))
Mike Frysinger124bb8e2023-09-06 05:48:55 +000055 with reclient_helper.build_context(argv, 'autosiso') as ret_code:
56 if ret_code:
57 return ret_code
58 argv = [
59 argv[0],
60 'ninja',
61 # Do not authenticate when using Reproxy.
62 '-project=',
63 '-reapi_instance=',
64 ] + argv[1:]
65 return siso.main(argv)
Junji Watanabe607284d2023-04-20 03:14:52 +000066
67
68if __name__ == '__main__':
Mike Frysinger124bb8e2023-09-06 05:48:55 +000069 try:
70 sys.exit(main(sys.argv))
71 except KeyboardInterrupt:
72 sys.exit(1)