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 9"""run.py is a utility for running a program. 10 11It can perform code signing, forward arguments to the program, and return the 12program's error code. 13""" 14 15import subprocess 16import sys 17 18 19def main(): 20 codesign_ident = sys.argv[1] 21 22 # Ignore 'run.py' and the codesigning identity. 23 argv = sys.argv[2:] 24 25 exec_path = argv[0] 26 27 # Do any necessary codesigning. 28 if codesign_ident: 29 sign_cmd = ['xcrun', 'codesign', '-f', '-s', codesign_ident, exec_path] 30 cs_rc = subprocess.call(sign_cmd, env={}) 31 if cs_rc != 0: 32 sys.stderr.write('Failed to codesign: ' + exec_path) 33 return cs_rc 34 35 return subprocess.call(argv) 36 37if __name__ == '__main__': 38 exit(main()) 39