Skip to content

Commit a7e3659

Browse files
committed
fix: compatible with stdout from SPM
1 parent f7bb50b commit a7e3659

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

config/cmd.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,7 @@ def get_workspace():
119119
cmd = f"xcodebuild -list -json {cmd_target}"
120120
print("run: ", cmd)
121121
output = subprocess.check_output(cmd, shell=True, universal_newlines=True)
122-
if output[0] != "{":
123-
# https://github.com/swiftlang/swift-package-manager/blob/f19d08cf79250514851490599319d22771074b01/Sources/PackageLoading/TargetSourcesBuilder.swift#L194
124-
# SPM print error message to stdout, skip it
125-
start = output.find("{")
126-
output = output[start:]
127-
output = json.loads(output)
122+
output = json_loads(output)
128123
if use_project:
129124
scheme = output["project"]["schemes"][0]
130125
else:
@@ -136,9 +131,22 @@ def get_workspace():
136131
cmd = f"xcodebuild -showBuildSettings -json {cmd_target} -scheme '{scheme}' 2>/dev/null"
137132
print("run: ", cmd)
138133
output = subprocess.check_output(cmd, shell=True, universal_newlines=True)
139-
output = json.loads(output)
134+
output = json_loads(output)
140135
build_dir = output[0]["buildSettings"]["SYMROOT"]
141136
build_root = os.path.abspath(os.path.join(build_dir, "../.."))
142137

143138
workspace = os.path.abspath(os.path.expanduser(workspace))
144139
return update(None if lastest_scheme else scheme)
140+
141+
def json_loads(s: str):
142+
if s[0] != "{" and s[0] != "[":
143+
# https://github.com/swiftlang/swift-package-manager/blob/f19d08cf79250514851490599319d22771074b01/Sources/PackageLoading/TargetSourcesBuilder.swift#L194
144+
# SPM print error message to stdout, skip it
145+
brace = s.find("{")
146+
bracket = s.find("[")
147+
if brace < 0: start = bracket
148+
elif bracket < 0: start = brace
149+
else: start = min(brace, bracket)
150+
if start > 0: s = s[start:]
151+
152+
return json.loads(s)

0 commit comments

Comments
 (0)