Skip to content

Commit 702277a

Browse files
committed
[tools] 修复 GCC 版本判断的方式并增加异常捕获
Signed-off-by: MurphyZhao <[email protected]>
1 parent 854d014 commit 702277a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tools/utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import sys
2626
import os
27+
import re
2728

2829
def splitall(loc):
2930
"""
@@ -245,10 +246,11 @@ def ProjectInfo(env):
245246
return proj
246247

247248
def VersionCmp(ver1, ver2):
248-
la=[];
249+
la=[]
249250
if ver1:
250-
la = ver1.split('.')
251-
lb = ver2.split('.')
251+
la = re.split("[. ]", ver1)
252+
lb = re.split("[. ]", ver2)
253+
252254
f = 0
253255
if len(la) > len(lb):
254256
f = len(la)
@@ -262,7 +264,7 @@ def VersionCmp(ver1, ver2):
262264
continue
263265
else:
264266
return -1
265-
except IndexError as e:
267+
except (IndexError, ValueError) as e:
266268
if len(la) > len(lb):
267269
return 1
268270
else:
@@ -274,7 +276,7 @@ def GCCC99Patch(cflags):
274276
gcc_version = building.GetDepend('GCC_VERSION')
275277
if gcc_version:
276278
gcc_version = gcc_version.replace('"', '')
277-
if VersionCmp(gcc_version, "4.8.0"):
279+
if VersionCmp(gcc_version, "4.8.0") == 1:
278280
# remove -std=c99 after GCC 4.8.x
279281
cflags = cflags.replace('-std=c99', '')
280282

0 commit comments

Comments
 (0)