Skip to content

Commit e541f03

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

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

config/cmd.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,21 @@ def get_workspace():
139139
return update(None if lastest_scheme else scheme)
140140

141141
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)
142+
# https://github.com/swiftlang/swift-package-manager/blob/f19d08cf79250514851490599319d22771074b01/Sources/PackageLoading/TargetSourcesBuilder.swift#L194
143+
# SPM print error message to stdout, skip it
144+
brace = s.find("{")
145+
bracket = s.find("[")
146+
if brace < 0: start = bracket
147+
elif bracket < 0: start = brace
148+
else: start = min(brace, bracket)
149+
if start < 0: start = 0
150+
151+
brace = s.rfind("}")
152+
bracket = s.rfind("]")
153+
if brace < 0: end = bracket
154+
elif bracket < 0: end = brace
155+
else: end = max(brace, bracket)
156+
if end < 0: end = len(s)
157+
else: end = end + 1
158+
159+
return json.loads(s[start:end])

0 commit comments

Comments
 (0)