run.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #===----------------------------------------------------------------------===##
  2. #
  3. # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. # See https://llvm.org/LICENSE.txt for license information.
  5. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. #
  7. #===----------------------------------------------------------------------===##
  8. """run.py is a utility for running a program.
  9. It can perform code signing, forward arguments to the program, and return the
  10. program's error code.
  11. """
  12. import subprocess
  13. import sys
  14. def main():
  15. codesign_ident = sys.argv[1]
  16. # Ignore 'run.py' and the codesigning identity.
  17. argv = sys.argv[2:]
  18. exec_path = argv[0]
  19. # Do any necessary codesigning.
  20. if codesign_ident:
  21. sign_cmd = ['xcrun', 'codesign', '-f', '-s', codesign_ident, exec_path]
  22. cs_rc = subprocess.call(sign_cmd, env={})
  23. if cs_rc != 0:
  24. sys.stderr.write('Failed to codesign: ' + exec_path)
  25. return cs_rc
  26. return subprocess.call(argv)
  27. if __name__ == '__main__':
  28. exit(main())