Junji Watanabe | 607284d | 2023-04-20 03:14:52 +0000 | [diff] [blame] | 1 | #!/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 | """ |
| 6 | Developers invoke this script via autosiso or autosiso.bat to simply run |
Junji Watanabe | 48fcabe | 2023-04-21 01:28:51 +0000 | [diff] [blame^] | 7 | Siso/Reclient builds. |
Junji Watanabe | 607284d | 2023-04-20 03:14:52 +0000 | [diff] [blame] | 8 | """ |
Junji Watanabe | 48fcabe | 2023-04-21 01:28:51 +0000 | [diff] [blame^] | 9 | # TODO(b/278976196): `siso ninja` command should handle the reclient and |
| 10 | # authentication accordingly. |
Junji Watanabe | 607284d | 2023-04-20 03:14:52 +0000 | [diff] [blame] | 11 | |
Junji Watanabe | 48fcabe | 2023-04-21 01:28:51 +0000 | [diff] [blame^] | 12 | import os |
| 13 | import re |
Junji Watanabe | 607284d | 2023-04-20 03:14:52 +0000 | [diff] [blame] | 14 | import sys |
| 15 | |
| 16 | import reclient_helper |
| 17 | import siso |
| 18 | |
| 19 | |
Junji Watanabe | 48fcabe | 2023-04-21 01:28:51 +0000 | [diff] [blame^] | 20 | def _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 Watanabe | 607284d | 2023-04-20 03:14:52 +0000 | [diff] [blame] | 34 | def main(argv): |
Junji Watanabe | 48fcabe | 2023-04-21 01:28:51 +0000 | [diff] [blame^] | 35 | 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 Watanabe | 607284d | 2023-04-20 03:14:52 +0000 | [diff] [blame] | 42 | 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 | |
| 55 | if __name__ == '__main__': |
| 56 | try: |
| 57 | sys.exit(main(sys.argv)) |
| 58 | except KeyboardInterrupt: |
| 59 | sys.exit(1) |