blob: c052c84d3371c2344c3362c754a57fb6b9256188 [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 Watanabe48fcabe2023-04-21 01:28:51 +000035 if not _use_remoteexec(argv):
36 print(
37 "`use_remoteexec=true` is not detected.\n"
38 "Please run `siso` command directly.",
39 file=sys.stderr)
40 return 1
41
Junji Watanabe607284d2023-04-20 03:14:52 +000042 with reclient_helper.build_context(argv) as ret_code:
43 if ret_code:
44 return ret_code
45 argv = [
46 argv[0],
47 'ninja',
48 # Do not authenticate when using Reproxy.
49 '-project=',
50 '-reapi_instance=',
51 ] + argv[1:]
52 return siso.main(argv)
53
54
55if __name__ == '__main__':
56 try:
57 sys.exit(main(sys.argv))
58 except KeyboardInterrupt:
59 sys.exit(1)