1#!/usr/bin/env python3 2 3# Copyright 2016 The Chromium Authors 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7""" 8Prints "1" if Chrome targets should be built with hermetic Xcode. 9Prints "2" if Chrome targets should be built with hermetic Xcode, but the OS 10version does not meet the minimum requirements of the hermetic version of Xcode. 11Prints "3" if FORCE_MAC_TOOLCHAIN is set for an iOS target_os 12Otherwise prints "0". 13 14Usage: 15 python should_use_hermetic_xcode.py <target_os> 16""" 17 18 19import argparse 20import os 21import sys 22 23_THIS_DIR_PATH = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) 24_BUILD_PATH = os.path.join(_THIS_DIR_PATH, os.pardir) 25sys.path.insert(0, _BUILD_PATH) 26 27import mac_toolchain 28 29 30def _IsCorpMachine(): 31 if sys.platform == 'darwin': 32 return os.path.isdir('/Library/GoogleCorpSupport/') 33 if sys.platform.startswith('linux'): 34 import subprocess 35 try: 36 return subprocess.check_output(['lsb_release', 37 '-sc']).rstrip() == b'rodete' 38 except: 39 return False 40 return False 41 42 43def main(): 44 parser = argparse.ArgumentParser(description='Download hermetic Xcode.') 45 parser.add_argument('platform') 46 args = parser.parse_args() 47 48 force_toolchain = os.environ.get('FORCE_MAC_TOOLCHAIN') 49 if force_toolchain and args.platform == 'ios': 50 return "3" 51 allow_corp = args.platform == 'mac' and _IsCorpMachine() 52 if force_toolchain or allow_corp: 53 if not mac_toolchain.PlatformMeetsHermeticXcodeRequirements(): 54 return "2" 55 return "1" 56 else: 57 return "0" 58 59 60if __name__ == '__main__': 61 print(main()) 62 sys.exit(0) 63