siso.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 signal
  11. import subprocess
  12. import sys
  13. import gclient_paths
  14. def main(args):
  15. # Propagate signals to siso process so that it can run cleanup steps.
  16. # Siso will be terminated immediately after the second Ctrl-C.
  17. signal.signal(signal.SIGINT, lambda signum, frame: None)
  18. if not sys.platform.startswith('win'):
  19. signal.signal(signal.SIGTERM, lambda signum, frame: None)
  20. # On Windows the siso.bat script passes along the arguments enclosed in
  21. # double quotes. This prevents multiple levels of parsing of the special '^'
  22. # characters needed when compiling a single file. When this case is
  23. # detected, we need to split the argument. This means that arguments
  24. # containing actual spaces are not supported by siso.bat, but that is not a
  25. # real limitation.
  26. if sys.platform.startswith('win') and len(args) == 2:
  27. args = args[:1] + args[1].split()
  28. # macOS's python sets CPATH, LIBRARY_PATH, SDKROOT implicitly.
  29. # https://openradar.appspot.com/radar?id=5608755232243712
  30. #
  31. # Removing those environment variables to avoid affecting clang's behaviors.
  32. if sys.platform == 'darwin':
  33. os.environ.pop("CPATH", None)
  34. os.environ.pop("LIBRARY_PATH", None)
  35. os.environ.pop("SDKROOT", None)
  36. environ = os.environ.copy()
  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. siso_override_path = os.environ.get('SISO_PATH')
  44. if siso_override_path:
  45. print('depot_tools/siso.py: Using Siso binary from SISO_PATH: %s.' %
  46. siso_override_path)
  47. if not os.path.isfile(siso_override_path):
  48. print(
  49. 'depot_tools/siso.py: Could not find Siso at provided '
  50. 'SISO_PATH.',
  51. file=sys.stderr)
  52. return 1
  53. for base_path in set(
  54. [primary_solution_path, gclient_root_path, gclient_src_root_path]):
  55. if not base_path:
  56. continue
  57. env = environ.copy()
  58. sisoenv_path = os.path.join(base_path, 'build', 'config', 'siso',
  59. '.sisoenv')
  60. if not os.path.exists(sisoenv_path):
  61. continue
  62. with open(sisoenv_path) as f:
  63. for line in f.readlines():
  64. k, v = line.rstrip().split('=', 1)
  65. env[k] = v
  66. siso_path = siso_override_path or os.path.join(
  67. base_path, 'third_party', 'siso',
  68. 'siso' + gclient_paths.GetExeSuffix())
  69. if os.path.isfile(siso_path):
  70. return subprocess.call([siso_path] + args[1:], env=env)
  71. print(
  72. 'depot_tools/siso.py: Could not find .sisoenv under build/config/siso '
  73. 'of the current project. Did you run gclient sync?',
  74. file=sys.stderr)
  75. return 1
  76. if __name__ == '__main__':
  77. sys.exit(main(sys.argv))