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
1 changed files with 26 additions and 16 deletions

View File

@ -68,26 +68,36 @@ def replace_variable(apkbuild, value: str) -> str:
# ${var/foo/bar}, ${var/foo/}, ${var/foo}
for match in revar3.finditer(value):
newvalue = apkbuild[match.group(1)]
search = match.group(2)
replacement = match.group(3)
if replacement is None: # arg 3 is optional
replacement = ""
newvalue = newvalue.replace(search, replacement, 1)
logging.verbose("{}: replace '{}' with '{}'".format(
apkbuild["pkgname"], match.group(0), newvalue))
value = value.replace(match.group(0), newvalue, 1)
try:
newvalue = apkbuild[match.group(1)]
search = match.group(2)
replacement = match.group(3)
if replacement is None: # arg 3 is optional
replacement = ""
newvalue = newvalue.replace(search, replacement, 1)
logging.verbose("{}: replace '{}' with '{}'".format(
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}
rematch4 = revar4.finditer(value)
for match in rematch4:
newvalue = apkbuild[match.group(1)]
substr = match.group(2)
if newvalue.startswith(substr):
newvalue = newvalue.replace(substr, "", 1)
logging.verbose("{}: replace '{}' with '{}'".format(
apkbuild["pkgname"], match.group(0), newvalue))
value = value.replace(match.group(0), newvalue, 1)
try:
newvalue = apkbuild[match.group(1)]
substr = match.group(2)
if newvalue.startswith(substr):
newvalue = newvalue.replace(substr, "", 1)
logging.verbose("{}: replace '{}' with '{}'".format(
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