build-many-glibcs: relax version check to allow non-digit characters

A version string may contain non-digit characters, commonly found in
built-from-VCS tools, e.g.
```
git version 2.39.GIT
git version 2.43.0.493.gbc7ee2e5e1
```

`int()` will raise a ValueError, leading to a spurious 'missing'.

Reviewed-by: DJ Delorie <dj@redhat.com>
This commit is contained in:
Fangrui Song 2024-01-31 15:46:23 -08:00
parent da89496337
commit 0d70accc06

View File

@ -1888,7 +1888,7 @@ def get_parser():
return parser return parser
def get_version_common(progname,line,word,delchars,arg1): def get_version_common(progname,line,word,arg1):
try: try:
out = subprocess.run([progname, arg1], out = subprocess.run([progname, arg1],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
@ -1896,13 +1896,12 @@ def get_version_common(progname,line,word,delchars,arg1):
stdin=subprocess.DEVNULL, stdin=subprocess.DEVNULL,
check=True, universal_newlines=True) check=True, universal_newlines=True)
v = out.stdout.splitlines()[line].split()[word] v = out.stdout.splitlines()[line].split()[word]
if delchars: v = re.match(r'[0-9]+(.[0-9]+)*', v).group()
v = v.replace(delchars,'')
return [int(x) for x in v.split('.')] return [int(x) for x in v.split('.')]
except: except:
return 'missing'; return 'missing';
def get_version_common_stderr(progname,line,word,delchars,arg1): def get_version_common_stderr(progname,line,word,arg1):
try: try:
out = subprocess.run([progname, arg1], out = subprocess.run([progname, arg1],
stdout=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
@ -1910,20 +1909,19 @@ def get_version_common_stderr(progname,line,word,delchars,arg1):
stdin=subprocess.DEVNULL, stdin=subprocess.DEVNULL,
check=True, universal_newlines=True) check=True, universal_newlines=True)
v = out.stderr.splitlines()[line].split()[word] v = out.stderr.splitlines()[line].split()[word]
if delchars: v = re.match(r'[0-9]+(.[0-9]+)*', v).group()
v = v.replace(delchars,'')
return [int(x) for x in v.split('.')] return [int(x) for x in v.split('.')]
except: except:
return 'missing'; return 'missing';
def get_version(progname): def get_version(progname):
return get_version_common (progname, 0, -1, None, '--version'); return get_version_common(progname, 0, -1, '--version');
def get_version_awk(progname): def get_version_awk(progname):
return get_version_common (progname, 0, 2, ',', '--version'); return get_version_common(progname, 0, 2, '--version');
def get_version_bzip2(progname): def get_version_bzip2(progname):
return get_version_common_stderr (progname, 0, 6, ',', '-h'); return get_version_common_stderr(progname, 0, 6, '-h');
def check_version(ver, req): def check_version(ver, req):
for v, r in zip(ver, req): for v, r in zip(ver, req):