tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

xcrun.py (1493B)


      1 #!/usr/bin/env python3
      2 # Copyright 2020 The Chromium Authors
      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 
     11 import argparse
     12 import os
     13 import subprocess
     14 import sys
     15 
     16 
     17 def xcrun(command, developer_dir):
     18  environ = dict(os.environ)
     19  if developer_dir:
     20    environ['DEVELOPER_DIR'] = os.path.abspath(developer_dir)
     21 
     22  processed_args = ['/usr/bin/xcrun']
     23  for arg in command:
     24    if os.path.exists(arg):
     25      arg = os.path.abspath(arg)
     26    processed_args.append(arg)
     27 
     28  process = subprocess.Popen(processed_args,
     29                             stdout=subprocess.PIPE,
     30                             stderr=subprocess.PIPE,
     31                             universal_newlines=True,
     32                             env=environ)
     33 
     34  stdout, stderr = process.communicate()
     35  sys.stdout.write(stdout)
     36  if process.returncode:
     37    sys.stderr.write(stderr)
     38    sys.exit(process.returncode)
     39 
     40 
     41 def main(args):
     42  parser = argparse.ArgumentParser(add_help=False)
     43  parser.add_argument(
     44      '--developer-dir',
     45      help='path to developer dir to use for the invocation of xcrun')
     46 
     47  parsed, remaining_args = parser.parse_known_args(args)
     48  xcrun(remaining_args, parsed.developer_dir)
     49 
     50 
     51 if __name__ == '__main__':
     52  main(sys.argv[1:])