pmb/parse/_apkbuild: wrap more calls in try-catch (!1864)

Otherwise pmb crashes on some APKBUILDs, for example:

source="https://files.pythonhosted.org/packages/source/${_pyname%${_pyname#?}}/$_pyname/$_pyname-$pkgver.tar.gz"
This commit is contained in:
Luca Weiss 2020-01-25 20:23:41 +01:00 committed by Oliver Smith
parent c8737740b1
commit 859159254e
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -68,26 +68,36 @@ def replace_variable(apkbuild, value: str) -> str:
# ${var/foo/bar}, ${var/foo/}, ${var/foo} # ${var/foo/bar}, ${var/foo/}, ${var/foo}
for match in revar3.finditer(value): for match in revar3.finditer(value):
newvalue = apkbuild[match.group(1)] try:
search = match.group(2) newvalue = apkbuild[match.group(1)]
replacement = match.group(3) search = match.group(2)
if replacement is None: # arg 3 is optional replacement = match.group(3)
replacement = "" if replacement is None: # arg 3 is optional
newvalue = newvalue.replace(search, replacement, 1) replacement = ""
logging.verbose("{}: replace '{}' with '{}'".format( newvalue = newvalue.replace(search, replacement, 1)
apkbuild["pkgname"], match.group(0), newvalue)) logging.verbose("{}: replace '{}' with '{}'".format(
value = value.replace(match.group(0), newvalue, 1) apkbuild["pkgname"], match.group(0), newvalue))
value = value.replace(match.group(0), newvalue, 1)
except KeyError:
logging.debug("{}: key '{}' for replacing '{}' not found, ignoring"
"".format(apkbuild["pkgname"], match.group(1),
match.group(0)))
# ${foo#bar} # ${foo#bar}
rematch4 = revar4.finditer(value) rematch4 = revar4.finditer(value)
for match in rematch4: for match in rematch4:
newvalue = apkbuild[match.group(1)] try:
substr = match.group(2) newvalue = apkbuild[match.group(1)]
if newvalue.startswith(substr): substr = match.group(2)
newvalue = newvalue.replace(substr, "", 1) if newvalue.startswith(substr):
logging.verbose("{}: replace '{}' with '{}'".format( newvalue = newvalue.replace(substr, "", 1)
apkbuild["pkgname"], match.group(0), newvalue)) logging.verbose("{}: replace '{}' with '{}'".format(
value = value.replace(match.group(0), newvalue, 1) apkbuild["pkgname"], match.group(0), newvalue))
value = value.replace(match.group(0), newvalue, 1)
except KeyError:
logging.debug("{}: key '{}' for replacing '{}' not found, ignoring"
"".format(apkbuild["pkgname"], match.group(1),
match.group(0)))
return value return value