Fumitoshi Ukai | 3ca8d0d | 2023-04-13 05:24:08 +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 | """This script is a wrapper around the siso binary that is pulled to |
| 6 | third_party as part of gclient sync. It will automatically find the siso |
| 7 | binary when run inside a gclient source tree, so users can just type |
| 8 | "siso" on the command line.""" |
| 9 | |
| 10 | import os |
Junji Watanabe | 9ed72f9 | 2023-11-01 09:13:25 +0000 | [diff] [blame] | 11 | import signal |
Fumitoshi Ukai | 3ca8d0d | 2023-04-13 05:24:08 +0000 | [diff] [blame] | 12 | import subprocess |
| 13 | import sys |
| 14 | |
| 15 | import gclient_paths |
| 16 | |
| 17 | |
| 18 | def main(args): |
Junji Watanabe | 9ed72f9 | 2023-11-01 09:13:25 +0000 | [diff] [blame] | 19 | # Propagate signals to siso process so that it can run cleanup steps. |
| 20 | # Siso will be terminated immediately after the second Ctrl-C. |
| 21 | signal.signal(signal.SIGINT, lambda signum, frame: None) |
| 22 | if not sys.platform.startswith('win'): |
| 23 | signal.signal(signal.SIGTERM, lambda signum, frame: None) |
| 24 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 25 | # On Windows the siso.bat script passes along the arguments enclosed in |
| 26 | # double quotes. This prevents multiple levels of parsing of the special '^' |
| 27 | # characters needed when compiling a single file. When this case is |
| 28 | # detected, we need to split the argument. This means that arguments |
| 29 | # containing actual spaces are not supported by siso.bat, but that is not a |
| 30 | # real limitation. |
| 31 | if sys.platform.startswith('win') and len(args) == 2: |
| 32 | args = args[:1] + args[1].split() |
Fumitoshi Ukai | 3ca8d0d | 2023-04-13 05:24:08 +0000 | [diff] [blame] | 33 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 34 | # macOS's python sets CPATH, LIBRARY_PATH, SDKROOT implicitly. |
| 35 | # https://openradar.appspot.com/radar?id=5608755232243712 |
| 36 | # |
| 37 | # Removing those environment variables to avoid affecting clang's behaviors. |
| 38 | if sys.platform == 'darwin': |
| 39 | os.environ.pop("CPATH", None) |
| 40 | os.environ.pop("LIBRARY_PATH", None) |
| 41 | os.environ.pop("SDKROOT", None) |
Fumitoshi Ukai | 3ca8d0d | 2023-04-13 05:24:08 +0000 | [diff] [blame] | 42 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 43 | environ = os.environ.copy() |
Fumitoshi Ukai | 3ca8d0d | 2023-04-13 05:24:08 +0000 | [diff] [blame] | 44 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 45 | # Get gclient root + src. |
| 46 | primary_solution_path = gclient_paths.GetPrimarySolutionPath() |
| 47 | gclient_root_path = gclient_paths.FindGclientRoot(os.getcwd()) |
| 48 | gclient_src_root_path = None |
| 49 | if gclient_root_path: |
| 50 | gclient_src_root_path = os.path.join(gclient_root_path, 'src') |
Fumitoshi Ukai | 3ca8d0d | 2023-04-13 05:24:08 +0000 | [diff] [blame] | 51 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 52 | siso_override_path = os.environ.get('SISO_PATH') |
| 53 | if siso_override_path: |
| 54 | print('depot_tools/siso.py: Using Siso binary from SISO_PATH: %s.' % |
| 55 | siso_override_path) |
| 56 | if not os.path.isfile(siso_override_path): |
| 57 | print( |
| 58 | 'depot_tools/siso.py: Could not find Siso at provided ' |
| 59 | 'SISO_PATH.', |
| 60 | file=sys.stderr) |
| 61 | return 1 |
Richard Wang | 4992184 | 2023-06-19 07:34:02 +0000 | [diff] [blame] | 62 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 63 | for base_path in set( |
| 64 | [primary_solution_path, gclient_root_path, gclient_src_root_path]): |
| 65 | if not base_path: |
| 66 | continue |
| 67 | env = environ.copy() |
| 68 | sisoenv_path = os.path.join(base_path, 'build', 'config', 'siso', |
| 69 | '.sisoenv') |
| 70 | if not os.path.exists(sisoenv_path): |
| 71 | continue |
| 72 | with open(sisoenv_path) as f: |
| 73 | for line in f.readlines(): |
| 74 | k, v = line.rstrip().split('=', 1) |
| 75 | env[k] = v |
| 76 | siso_path = siso_override_path or os.path.join( |
| 77 | base_path, 'third_party', 'siso', |
| 78 | 'siso' + gclient_paths.GetExeSuffix()) |
| 79 | if os.path.isfile(siso_path): |
| 80 | return subprocess.call([siso_path] + args[1:], env=env) |
Fumitoshi Ukai | 3ca8d0d | 2023-04-13 05:24:08 +0000 | [diff] [blame] | 81 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 82 | print( |
| 83 | 'depot_tools/siso.py: Could not find .sisoenv under build/config/siso ' |
| 84 | 'of the current project. Did you run gclient sync?', |
| 85 | file=sys.stderr) |
| 86 | return 1 |
Fumitoshi Ukai | 3ca8d0d | 2023-04-13 05:24:08 +0000 | [diff] [blame] | 87 | |
| 88 | |
| 89 | if __name__ == '__main__': |
Junji Watanabe | 9ed72f9 | 2023-11-01 09:13:25 +0000 | [diff] [blame] | 90 | sys.exit(main(sys.argv)) |