gyptest-sdkroot.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python
  2. # Copyright (c) 2012 Google Inc. 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. Verifies that setting SDKROOT works.
  7. """
  8. import TestGyp
  9. import os
  10. import subprocess
  11. import sys
  12. if sys.platform == 'darwin':
  13. test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
  14. def GetSDKPath(sdk):
  15. """Return SDKROOT if the SDK version |sdk| is installed or empty string."""
  16. DEVNULL = open(os.devnull, 'wb')
  17. try:
  18. proc = subprocess.Popen(
  19. ['xcodebuild', '-version', '-sdk', 'macosx' + sdk, 'Path'],
  20. stdout=subprocess.PIPE, stderr=DEVNULL)
  21. return proc.communicate()[0].rstrip('\n')
  22. finally:
  23. DEVNULL.close()
  24. def SelectSDK():
  25. """Select the oldest SDK installed (greater than 10.6)."""
  26. for sdk in ['10.6', '10.7', '10.8', '10.9']:
  27. path = GetSDKPath(sdk)
  28. if path:
  29. return True, sdk, path
  30. return False, '', ''
  31. # Make sure this works on the bots, which only have the 10.6 sdk, and on
  32. # dev machines which usually don't have the 10.6 sdk.
  33. sdk_found, sdk, sdk_path = SelectSDK()
  34. if not sdk_found:
  35. test.fail_test()
  36. test.write('sdkroot/test.gyp', test.read('sdkroot/test.gyp') % sdk)
  37. test.run_gyp('test.gyp', '-D', 'sdk_path=%s' % sdk_path,
  38. chdir='sdkroot')
  39. test.build('test.gyp', test.ALL, chdir='sdkroot')
  40. test.pass_test()