44import  os 
55import  subprocess 
66import  sys 
7+ import  json 
78
89from  .config  import  ServerConfig 
910
@@ -19,7 +20,8 @@ def usage(name, msg=None):
1920            { name }  
2021            { name }  
2122
22-             workspace and project and be infered if only one in pwd. scheme must be specified. 
23+             workspace and project and be infered if only one in pwd. 
24+             scheme can be omit to bind the lastest build scheme. 
2325            see also `man xcodebuild` and xcodebuild -showBuildSettings 
2426
2527            Other Options: 
@@ -57,9 +59,6 @@ def main(argv=sys.argv):
5759        else :
5860            _usage (f"unknown arg { arg }  )
5961
60-     if  scheme  is  None :
61-         _usage ("you need to specify scheme!" )
62- 
6362    if  workspace  is  None :
6463
6564        def  get_workspace ():
@@ -82,17 +81,26 @@ def get_workspace():
8281
8382        workspace  =  get_workspace ()
8483
84+     lastest_scheme  =  False 
85+     if  scheme  is  None :
86+         output  =  subprocess .check_output (f"xcodebuild -list -json -workspace '{ workspace }  , shell = True , universal_newlines = True )
87+         output  =  json .loads (output )
88+         scheme  =  output ["workspace" ]["schemes" ][0 ]
89+         lastest_scheme  =  True 
90+         # _usage("you need to specify scheme!") 
91+ 
8592    # find and record build_root for workspace and scheme 
86-     cmd  =  f"""xcodebuild -showBuildSettings -workspace '{ workspace } { scheme } \\ bSYMROOT =" | head -1 | awk -F" = " '{{print $2}}' | tr -d '"' """ 
87-     build_dir  =  subprocess .check_output (cmd , shell = True , universal_newlines = True )
88-     build_root  =  os .path .join (build_dir , "../.." )
89-     build_root  =  os .path .abspath (build_root )
93+     output  =  subprocess .check_output (f"xcodebuild -showBuildSettings -json -workspace '{ workspace } { scheme }  , shell = True , universal_newlines = True )
94+     output  =  json .loads (output )
95+     build_dir  =  output [0 ]["buildSettings" ]["SYMROOT" ]
96+     build_root  =  os .path .abspath (os .path .join (build_dir , "../.." ))
97+ 
9098    print ("find root:" , build_root )
9199
92100    config  =  ServerConfig .shared ()
93101    config .workspace  =  os .path .abspath (os .path .expanduser (workspace ))
94102    config .build_root  =  build_root 
95-     config .scheme  =  scheme 
103+     config .scheme  =  None   if   lastest_scheme   else   scheme 
96104    config .kind  =  "xcode" 
97105    config .skip_validate_bin  =  skip_validate_bin 
98106    config .save ()
0 commit comments