1#!/usr/bin/env python 2 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 5# found in the LICENSE file. 6 7""" 8Verifies that setting SDKROOT works. 9""" 10 11import TestGyp 12 13import os 14import subprocess 15import sys 16 17if sys.platform == 'darwin': 18 test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) 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 39 # Make sure this works on the bots, which only have the 10.6 sdk, and on 40 # dev machines which usually don't have the 10.6 sdk. 41 sdk_found, sdk, sdk_path = SelectSDK() 42 if not sdk_found: 43 test.fail_test() 44 45 test.write('sdkroot/test.gyp', test.read('sdkroot/test.gyp') % sdk) 46 47 test.run_gyp('test.gyp', '-D', 'sdk_path=%s' % sdk_path, 48 chdir='sdkroot') 49 test.build('test.gyp', test.ALL, chdir='sdkroot') 50 test.pass_test() 51