blob: e6135413c858e232b9d2904b799de455fcfca0af [file] [log] [blame]
Fumitoshi Ukai3ca8d0d2023-04-13 05:24:08 +00001#!/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
6third_party as part of gclient sync. It will automatically find the siso
7binary when run inside a gclient source tree, so users can just type
8"siso" on the command line."""
9
10import os
11import subprocess
12import sys
13
14import gclient_paths
15
16
17def main(args):
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 detected,
21 # we need to split the argument. This means that arguments containing actual
22 # spaces are not supported by siso.bat, but that is not a real limitation.
23 if sys.platform.startswith('win') and len(args) == 2:
24 args = args[:1] + args[1].split()
25
26 # macOS's python sets CPATH, LIBRARY_PATH, SDKROOT implicitly.
27 # https://openradar.appspot.com/radar?id=5608755232243712
28 #
29 # Removing those environment variables to avoid affecting clang's behaviors.
30 if sys.platform == 'darwin':
31 os.environ.pop("CPATH", None)
32 os.environ.pop("LIBRARY_PATH", None)
33 os.environ.pop("SDKROOT", None)
34
35 environ = os.environ.copy()
36
37 # Get gclient root + src.
38 primary_solution_path = gclient_paths.GetPrimarySolutionPath()
39 gclient_root_path = gclient_paths.FindGclientRoot(os.getcwd())
40 gclient_src_root_path = None
41 if gclient_root_path:
42 gclient_src_root_path = os.path.join(gclient_root_path, 'src')
43
44 for base_path in set(
45 [primary_solution_path, gclient_root_path, gclient_src_root_path]):
46 if not base_path:
47 continue
48 env = environ.copy()
49 sisoenv_path = os.path.join(base_path, 'build', 'config', 'siso',
50 '.sisoenv')
51 if os.path.exists(sisoenv_path):
52 with open(sisoenv_path) as f:
53 for line in f.readlines():
54 k, v = line.rstrip().split('=', 1)
55 env[k] = v
56 siso_path = os.path.join(base_path, 'third_party', 'siso',
57 'siso' + gclient_paths.GetExeSuffix())
58 if os.path.isfile(siso_path):
59 return subprocess.call([siso_path] + args[1:], env=env)
60
61 print(
62 'depot_tools/siso.py: Could not find Siso in the third_party of '
63 'the current project.',
64 file=sys.stderr)
65 return 1
66
67
68if __name__ == '__main__':
69 try:
70 sys.exit(main(sys.argv))
71 except KeyboardInterrupt:
72 sys.exit(1)