1515import  subprocess 
1616import  sys 
1717
18- 
1918from  optparse  import  OptionParser 
2019
20+ sys .path .insert (1 , '../../build' )
21+ from  pyutil .file_util  import  symlink 
22+ 
2123
2224def  parse_version (version_str ):
2325  """'10.6' => [10, 6]""" 
@@ -35,6 +37,9 @@ def main():
3537  parser .add_option ("--print_sdk_path" ,
3638                    action = "store_true" , dest = "print_sdk_path" , default = False ,
3739                    help = "Additionaly print the path the SDK (appears first)." )
40+   parser .add_option ("--symlink" ,
41+                     action = "store" , type = "string" , dest = "symlink" , default = "" ,
42+                     help = "Whether to create a symlink in the buildroot to the SDK." )
3843  (options , args ) =  parser .parse_args ()
3944  min_sdk_version  =  args [0 ]
4045
@@ -43,8 +48,7 @@ def main():
4348                         stderr = subprocess .STDOUT )
4449  out , err  =  job .communicate ()
4550  if  job .returncode  !=  0 :
46-     print  >>  sys .stderr , out 
47-     print  >>  sys .stderr , err 
51+     sys .stderr .writelines ([out , err ])
4852    raise  Exception (('Error %d running xcode-select, you might have to run ' 
4953      '|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| ' 
5054      'if you are using Xcode 4.' ) %  job .returncode )
@@ -64,27 +68,33 @@ def main():
6468  best_sdk  =  sorted (sdks , key = parse_version )[0 ]
6569
6670  if  options .verify  and  best_sdk  !=  min_sdk_version  and  not  options .sdk_path :
67-     print  >>  sys .stderr , '' 
68-     print  >>  sys .stderr , '                                           vvvvvvv' 
69-     print  >>  sys .stderr , '' 
70-     print  >>  sys .stderr , \
71-         'This build requires the %s SDK, but it was not found on your system.'  \
72-         %  min_sdk_version 
73-     print  >>  sys .stderr , \
74-         'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.' 
75-     print  >>  sys .stderr , '' 
76-     print  >>  sys .stderr , '                                           ^^^^^^^' 
77-     print  >>  sys .stderr , '' 
71+     sys .stderr .writelines ([
72+       '' ,
73+       '                                           vvvvvvv' ,
74+       '' ,
75+       'This build requires the %s SDK, but it was not found on your system.'  \
76+         %  min_sdk_version ,
77+       'Either install it, or explicitly set mac_sdk in your gn args.' ,
78+       '' ,
79+       '                                           ^^^^^^^' ,
80+       '' ])
7881    return  min_sdk_version 
7982
80-   if  options .print_sdk_path :
81-     print  subprocess .check_output (['xcodebuild' , '-version' , '-sdk' ,
82-                                    'macosx'  +  best_sdk , 'Path' ]).strip ()
83+   if  options .symlink  or  options .print_sdk_path :
84+     sdk_output  =  subprocess .check_output (['xcodebuild' , '-version' , '-sdk' ,
85+                                           'macosx'  +  best_sdk , 'Path' ]).strip ()
86+     if  options .symlink :
87+       symlink_target  =  os .path .join (options .symlink , os .path .basename (sdk_output ))
88+       symlink (sdk_output , symlink_target )
89+       sdk_output  =  symlink_target 
90+ 
91+     if  options .print_sdk_path :
92+       print (sdk_output )
8393
8494  return  best_sdk 
8595
8696
8797if  __name__  ==  '__main__' :
8898  if  sys .platform  !=  'darwin' :
8999    raise  Exception ("This script only runs on Mac" )
90-   print   main ()
100+   print ( main () )
0 commit comments