pmb.parse._apkbuild: Set default attribute values before starting to parse (!866)
Theoretically it is possible to reference variables before they are defined. In the shell, these will simply be evaluated to an empty string. In preparation of replacing variables immediately after parsing attributes, these variables will be no longer replaced correctly. We can simplify the code further, and avoid this problem by initializing the dict with the default values, replacing them with the real values from the APKBUILD. This will also avoid a (somewhat unrelated) error in the bootimg test: File "pmb/parse/_apkbuild.py", line 46, in replace_variable apkbuild["pkgname"], match.group(0), KeyError: 'pkgname'
This commit is contained in:
parent
33e3553cdd
commit
3aabaf451c
|
@ -255,8 +255,15 @@ def apkbuild(args, path, check_pkgver=True, check_pkgname=True):
|
||||||
# Read the file and check line endings
|
# Read the file and check line endings
|
||||||
lines = read_file(path)
|
lines = read_file(path)
|
||||||
|
|
||||||
# Parse all attributes from the config
|
# Add default attributes
|
||||||
ret = {}
|
ret = {}
|
||||||
|
for attribute, options in pmb.config.apkbuild_attributes.items():
|
||||||
|
if options["array"]:
|
||||||
|
ret[attribute] = []
|
||||||
|
else:
|
||||||
|
ret[attribute] = ""
|
||||||
|
|
||||||
|
# Parse all attributes from the config
|
||||||
for i in range(len(lines)):
|
for i in range(len(lines)):
|
||||||
for attribute, options in pmb.config.apkbuild_attributes.items():
|
for attribute, options in pmb.config.apkbuild_attributes.items():
|
||||||
found, value, i = parse_attribute(attribute, lines, i, path)
|
found, value, i = parse_attribute(attribute, lines, i, path)
|
||||||
|
@ -278,14 +285,6 @@ def apkbuild(args, path, check_pkgver=True, check_pkgname=True):
|
||||||
value = []
|
value = []
|
||||||
ret[attribute] = value
|
ret[attribute] = value
|
||||||
|
|
||||||
# Add missing keys
|
|
||||||
for attribute, options in pmb.config.apkbuild_attributes.items():
|
|
||||||
if attribute not in ret:
|
|
||||||
if options["array"]:
|
|
||||||
ret[attribute] = []
|
|
||||||
else:
|
|
||||||
ret[attribute] = ""
|
|
||||||
|
|
||||||
# Properly format values
|
# Properly format values
|
||||||
ret = replace_variables(ret)
|
ret = replace_variables(ret)
|
||||||
ret = cut_off_function_names(ret)
|
ret = cut_off_function_names(ret)
|
||||||
|
|
Loading…
Reference in New Issue