should_use_hermetic_xcode.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. # Copyright 2016 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. Prints "1" if Chrome targets should be built with hermetic Xcode.
  7. Prints "2" if Chrome targets should be built with hermetic Xcode, but the OS
  8. version does not meet the minimum requirements of the hermetic version of Xcode.
  9. Prints "3" if FORCE_MAC_TOOLCHAIN is set for an iOS target_os
  10. Otherwise prints "0".
  11. Usage:
  12. python should_use_hermetic_xcode.py <target_os>
  13. """
  14. from __future__ import print_function
  15. import argparse
  16. import os
  17. import sys
  18. _THIS_DIR_PATH = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
  19. _BUILD_PATH = os.path.join(_THIS_DIR_PATH, os.pardir)
  20. sys.path.insert(0, _BUILD_PATH)
  21. import mac_toolchain
  22. def _IsCorpMachine():
  23. if sys.platform == 'darwin':
  24. return os.path.isdir('/Library/GoogleCorpSupport/')
  25. if sys.platform.startswith('linux'):
  26. import subprocess
  27. try:
  28. return subprocess.check_output(['lsb_release',
  29. '-sc']).rstrip() == b'rodete'
  30. except:
  31. return False
  32. return False
  33. def main():
  34. parser = argparse.ArgumentParser(description='Download hermetic Xcode.')
  35. parser.add_argument('platform')
  36. args = parser.parse_args()
  37. force_toolchain = os.environ.get('FORCE_MAC_TOOLCHAIN')
  38. if force_toolchain and args.platform == 'ios':
  39. return "3"
  40. allow_corp = args.platform == 'mac' and _IsCorpMachine()
  41. if force_toolchain or allow_corp:
  42. if not mac_toolchain.PlatformMeetsHermeticXcodeRequirements():
  43. return "2"
  44. return "1"
  45. else:
  46. return "0"
  47. if __name__ == '__main__':
  48. print(main())
  49. sys.exit(0)