Skip to content

Commit c99acd8

Browse files
olehermanseminggo
authored andcommitted
Used new version_compare() function to simplify version related logic (#426)
Signed-off-by: Ole Herman Schumacher Elgesem <[email protected]>
1 parent a9fd0d4 commit c99acd8

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

bin/utils.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -165,55 +165,45 @@ def get_vs_versions():
165165

166166
def get_newest_msbuild(min_ver=None):
167167
versions = get_vs_versions()
168-
169-
min_ver_float = 0.0
170-
if isinstance(min_ver, str):
171-
# value of min_ver is string. such as : "12.0", "14.0"
172-
min_ver_float = float(min_ver)
173-
elif isinstance(min_ver, int) and min_ver in VS_VERSION_MAP.keys():
168+
cmp = cocos.version_compare
169+
if isinstance(min_ver, int) and min_ver in VS_VERSION_MAP.keys():
174170
# value of min_ver is int. such as : 2013, 2015
175-
min_ver_float = float(VS_VERSION_MAP[min_ver])
171+
min_ver = VS_VERSION_MAP[min_ver]
176172

177173
find_ver = None
178174
find_path = None
179-
for v in versions:
180-
cur_v = float(v)
181-
if cur_v < min_ver_float:
175+
for cur_ver in versions:
176+
if cmp(cur_ver, "<", min_ver):
182177
continue
183178

184179
v_path = get_msbuild_path(v)
185180
if v_path is not None:
186-
if (find_ver is None) or (cur_v > find_ver):
187-
find_ver = cur_v
181+
if (find_ver is None) or cmp(cur_ver, ">", find_ver):
182+
find_ver = cur_ver
188183
find_path = v_path
189184

190185
return find_path
191186

192187
def get_newest_devenv(min_ver=None):
193188
versions = get_vs_versions()
194-
195-
min_ver_float = 0.0
196-
if isinstance(min_ver, str):
197-
# value of min_ver is string. such as : "12.0", "14.0"
198-
min_ver_float = float(min_ver)
199-
elif isinstance(min_ver, int) and min_ver in VS_VERSION_MAP.keys():
189+
cmp = cocos.version_compare
190+
if isinstance(min_ver, int) and min_ver in VS_VERSION_MAP.keys():
200191
# value of min_ver is int. such as : 2013, 2015
201-
min_ver_float = float(VS_VERSION_MAP[min_ver])
192+
min_ver = VS_VERSION_MAP[min_ver]
202193

203194
find_ver = None
204195
find_path = None
205-
for v in versions:
206-
cur_v = float(v)
207-
if cur_v < min_ver_float:
196+
for cur_ver in versions:
197+
if cmp(cur_ver, "<", min_ver):
208198
continue
209199

210-
v_path = get_devenv_path(v)
200+
v_path = get_devenv_path(cur_ver)
211201
if v_path is not None:
212-
if (find_ver is None) or (cur_v > find_ver):
213-
find_ver = cur_v
202+
if (find_ver is None) or cmp(cur_ver, ">", find_ver):
203+
find_ver = cur_ver
214204
find_path = v_path
215205

216-
if min_ver_float > 0 and find_ver > min_ver_float:
206+
if cmp(min_ver, ">", 0) and cmp(find_ver, ">", min_ver):
217207
need_upgrade = True
218208
else:
219209
need_upgrade = False

0 commit comments

Comments
 (0)