siso.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. import os
  10. import subprocess
  11. import sys
  12. import gclient_paths
  13. def main(args):
  14. # On Windows the siso.bat script passes along the arguments enclosed in
  15. # double quotes. This prevents multiple levels of parsing of the special '^'
  16. # characters needed when compiling a single file. When this case is detected,
  17. # we need to split the argument. This means that arguments containing actual
  18. # spaces are not supported by siso.bat, but that is not a real limitation.
  19. if sys.platform.startswith('win') and len(args) == 2:
  20. args = args[:1] + args[1].split()
  21. # macOS's python sets CPATH, LIBRARY_PATH, SDKROOT implicitly.
  22. # https://openradar.appspot.com/radar?id=5608755232243712
  23. #
  24. # Removing those environment variables to avoid affecting clang's behaviors.
  25. if sys.platform == 'darwin':
  26. os.environ.pop("CPATH", None)
  27. os.environ.pop("LIBRARY_PATH", None)
  28. os.environ.pop("SDKROOT", None)
  29. environ = os.environ.copy()
  30. # Get gclient root + src.
  31. primary_solution_path = gclient_paths.GetPrimarySolutionPath()
  32. gclient_root_path = gclient_paths.FindGclientRoot(os.getcwd())
  33. gclient_src_root_path = None
  34. if gclient_root_path:
  35. gclient_src_root_path = os.path.join(gclient_root_path, 'src')
  36. for base_path in set(
  37. [primary_solution_path, gclient_root_path, gclient_src_root_path]):
  38. if not base_path:
  39. continue
  40. env = environ.copy()
  41. sisoenv_path = os.path.join(base_path, 'build', 'config', 'siso',
  42. '.sisoenv')
  43. if os.path.exists(sisoenv_path):
  44. with open(sisoenv_path) as f:
  45. for line in f.readlines():
  46. k, v = line.rstrip().split('=', 1)
  47. env[k] = v
  48. siso_path = os.path.join(base_path, 'third_party', 'siso',
  49. 'siso' + gclient_paths.GetExeSuffix())
  50. if os.path.isfile(siso_path):
  51. return subprocess.call([siso_path] + args[1:], env=env)
  52. print(
  53. 'depot_tools/siso.py: Could not find Siso in the third_party of '
  54. 'the current project.',
  55. file=sys.stderr)
  56. return 1
  57. if __name__ == '__main__':
  58. try:
  59. sys.exit(main(sys.argv))
  60. except KeyboardInterrupt:
  61. sys.exit(1)