| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 # Copyright (c) 2012 Google Inc. All rights reserved. | 3 # Copyright (c) 2012 Google Inc. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """ | 7 """ |
| 8 Verifies that setting SDKROOT works. | 8 Verifies that setting SDKROOT works. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import TestGyp | 11 import TestGyp |
| 12 | 12 |
| 13 import os | 13 import os |
| 14 import subprocess | 14 import subprocess |
| 15 import sys | 15 import sys |
| 16 | 16 |
| 17 if sys.platform == 'darwin': | 17 if sys.platform == 'darwin': |
| 18 test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) | 18 test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) |
| 19 | 19 |
| 20 def GetSDKPath(sdk): |
| 21 """Return SDKROOT if the SDK version |sdk| is installed or empty string.""" |
| 22 DEVNULL = open(os.devnull, 'wb') |
| 23 try: |
| 24 proc = subprocess.Popen( |
| 25 ['xcodebuild', '-version', '-sdk', 'macosx' + sdk, 'Path'], |
| 26 stdout=subprocess.PIPE, stderr=DEVNULL) |
| 27 return proc.communicate()[0].rstrip('\n') |
| 28 finally: |
| 29 DEVNULL.close() |
| 30 |
| 31 def SelectSDK(): |
| 32 """Select the oldest SDK installed (greater than 10.6).""" |
| 33 for sdk in ['10.6', '10.7', '10.8', '10.9']: |
| 34 path = GetSDKPath(sdk) |
| 35 if path: |
| 36 return True, sdk, path |
| 37 return False, '', '' |
| 38 |
| 20 # Make sure this works on the bots, which only have the 10.6 sdk, and on | 39 # Make sure this works on the bots, which only have the 10.6 sdk, and on |
| 21 # dev machines, which usually don't have the 10.6 sdk. | 40 # dev machines which usually don't have the 10.6 sdk. |
| 22 sdk = '10.6' | 41 sdk_found, sdk, sdk_path = SelectSDK() |
| 23 DEVNULL = open(os.devnull, 'wb') | 42 if not sdk_found: |
| 24 proc = subprocess.Popen(['xcodebuild', '-version', '-sdk', 'macosx' + sdk], | |
| 25 stdout=DEVNULL, stderr=DEVNULL) | |
| 26 proc.communicate() | |
| 27 DEVNULL.close() | |
| 28 if proc.returncode: | |
| 29 sdk = '10.7' | |
| 30 | |
| 31 proc = subprocess.Popen(['xcodebuild', '-version', | |
| 32 '-sdk', 'macosx' + sdk, 'Path'], | |
| 33 stdout=subprocess.PIPE) | |
| 34 sdk_path = proc.communicate()[0].rstrip('\n') | |
| 35 if proc.returncode != 0: | |
| 36 test.fail_test() | 43 test.fail_test() |
| 37 | 44 |
| 38 test.write('sdkroot/test.gyp', test.read('sdkroot/test.gyp') % sdk) | 45 test.write('sdkroot/test.gyp', test.read('sdkroot/test.gyp') % sdk) |
| 39 | 46 |
| 40 test.run_gyp('test.gyp', '-D', 'sdk_path=%s' % sdk_path, | 47 test.run_gyp('test.gyp', '-D', 'sdk_path=%s' % sdk_path, |
| 41 chdir='sdkroot') | 48 chdir='sdkroot') |
| 42 test.build('test.gyp', test.ALL, chdir='sdkroot') | 49 test.build('test.gyp', test.ALL, chdir='sdkroot') |
| 43 test.pass_test() | 50 test.pass_test() |
| OLD | NEW |