@@ -82,37 +82,53 @@ def update(scheme):
8282 if workspace is None :
8383
8484 def get_workspace ():
85+ nonlocal project
8586 if project is None :
8687 workspaces = glob .glob ("*.xcworkspace" )
8788 if len (workspaces ) > 1 :
8889 _usage ("there are multiple xcworkspace in pwd, please specify one" )
8990 if len (workspaces ) == 1 :
9091 return workspaces [0 ]
9192
92- projects = glob .glob ("*.xcodeproj/*.xcworkspace " )
93+ projects = glob .glob ("*.xcodeproj" )
9394 if len (projects ) > 1 :
9495 _usage ("there are multiple xcodeproj in pwd, please specify one" )
9596 if len (projects ) == 1 :
96- return projects [0 ]
97+ project = projects [0 ]
98+ return os .path .join (project , "project.xcworkspace" )
9799
98100 _usage ("there no xcworkspace or xcodeproj in pwd, please specify one" )
99101 else :
100102 return os .path .join (project , "project.xcworkspace" )
101103
102104 workspace = get_workspace ()
105+ else :
106+ project = None # clear to avoid specify both
107+
108+ use_project = False
109+ if os .path .exists (workspace ):
110+ cmd_target = f"-workspace '{ workspace } '"
111+ elif project :
112+ cmd_target = f"-project '{ project } '"
113+ use_project = True
114+ else :
115+ _usage ("can't get exist xcworkspace, please specify one" )
103116
104117 lastest_scheme = False
105118 if scheme is None :
106- cmd = f"xcodebuild -list -json -workspace ' { workspace } ' "
119+ cmd = f"xcodebuild -list -json { cmd_target } "
107120 print ("run: " , cmd )
108121 output = subprocess .check_output (cmd , shell = True , universal_newlines = True )
109122 output = json .loads (output )
110- scheme = output ["workspace" ]["schemes" ][0 ]
123+ if use_project :
124+ scheme = output ["project" ]["schemes" ][0 ]
125+ else :
126+ scheme = output ["workspace" ]["schemes" ][0 ]
111127 lastest_scheme = True
112128 # _usage("you need to specify scheme!")
113129
114130 # find and record build_root for workspace and scheme
115- cmd = f"xcodebuild -showBuildSettings -json -workspace ' { workspace } ' -scheme '{ scheme } ' 2>/dev/null"
131+ cmd = f"xcodebuild -showBuildSettings -json { cmd_target } -scheme '{ scheme } ' 2>/dev/null"
116132 print ("run: " , cmd )
117133 output = subprocess .check_output (cmd , shell = True , universal_newlines = True )
118134 output = json .loads (output )
0 commit comments