xcrun.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python3
  2. # Copyright 2020 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. """
  6. Wrapper around xcrun adding support for --developer-dir parameter to set
  7. the DEVELOPER_DIR environment variable, and for converting paths relative
  8. to absolute (since this is required by most of the tool run via xcrun).
  9. """
  10. import argparse
  11. import os
  12. import subprocess
  13. import sys
  14. def xcrun(command, developer_dir):
  15. environ = dict(os.environ)
  16. if developer_dir:
  17. environ['DEVELOPER_DIR'] = os.path.abspath(developer_dir)
  18. processed_args = ['/usr/bin/xcrun']
  19. for arg in command:
  20. if os.path.exists(arg):
  21. arg = os.path.abspath(arg)
  22. processed_args.append(arg)
  23. process = subprocess.Popen(processed_args,
  24. stdout=subprocess.PIPE,
  25. stderr=subprocess.PIPE,
  26. universal_newlines=True,
  27. env=environ)
  28. stdout, stderr = process.communicate()
  29. sys.stdout.write(stdout)
  30. if process.returncode:
  31. sys.stderr.write(stderr)
  32. sys.exit(process.returncode)
  33. def main(args):
  34. parser = argparse.ArgumentParser(add_help=False)
  35. parser.add_argument(
  36. '--developer-dir',
  37. help='path to developer dir to use for the invocation of xcrun')
  38. parsed, remaining_args = parser.parse_known_args(args)
  39. xcrun(remaining_args, parsed.developer_dir)
  40. if __name__ == '__main__':
  41. main(sys.argv[1:])