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 |
Ben Segall | b64ee7f | 2023-09-07 15:11:31 +0000 | [diff] [blame^] | 15 | import uuid |
Junji Watanabe | 607284d | 2023-04-20 03:14:52 +0000 | [diff] [blame] | 16 | |
| 17 | import reclient_helper |
| 18 | import siso |
| 19 | |
| 20 | |
Junji Watanabe | 48fcabe | 2023-04-21 01:28:51 +0000 | [diff] [blame] | 21 | def _use_remoteexec(argv): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 22 | 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 Watanabe | 48fcabe | 2023-04-21 01:28:51 +0000 | [diff] [blame] | 32 | return False |
Junji Watanabe | 48fcabe | 2023-04-21 01:28:51 +0000 | [diff] [blame] | 33 | |
| 34 | |
Junji Watanabe | 607284d | 2023-04-20 03:14:52 +0000 | [diff] [blame] | 35 | def main(argv): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 36 | # 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 Watanabe | 3a5cc40 | 2023-05-22 04:59:44 +0000 | [diff] [blame] | 46 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 47 | 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 Watanabe | 48fcabe | 2023-04-21 01:28:51 +0000 | [diff] [blame] | 53 | |
Ben Segall | b64ee7f | 2023-09-07 15:11:31 +0000 | [diff] [blame^] | 54 | os.environ.setdefault("AUTONINJA_BUILD_ID", str(uuid.uuid4())) |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 55 | 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 Watanabe | 607284d | 2023-04-20 03:14:52 +0000 | [diff] [blame] | 66 | |
| 67 | |
| 68 | if __name__ == '__main__': |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 69 | try: |
| 70 | sys.exit(main(sys.argv)) |
| 71 | except KeyboardInterrupt: |
| 72 | sys.exit(1) |