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