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 | ce3e819 | 2023-08-04 07:00:12 +0000 | [diff] [blame] | 35 | # 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 Watanabe | 3a5cc40 | 2023-05-22 04:59:44 +0000 | [diff] [blame] | 45 | |
Junji Watanabe | 48fcabe | 2023-04-21 01:28:51 +0000 | [diff] [blame] | 46 | 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 Segall | e49349b | 2023-06-01 02:54:56 +0000 | [diff] [blame] | 53 | with reclient_helper.build_context(argv, 'autosiso') as ret_code: |
Junji Watanabe | 607284d | 2023-04-20 03:14:52 +0000 | [diff] [blame] | 54 | 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 | |
| 66 | if __name__ == '__main__': |
| 67 | try: |
| 68 | sys.exit(main(sys.argv)) |
| 69 | except KeyboardInterrupt: |
| 70 | sys.exit(1) |