parser: Add function to read a function from an APKBUILD (!1747)

This commit is contained in:
Robert Yang 2019-02-05 11:22:27 -05:00 committed by Oliver Smith
parent cd7d6a2431
commit 7d7a29d032
2 changed files with 26 additions and 0 deletions

View File

@ -18,6 +18,7 @@ along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
from pmb.parse.arguments import arguments
from pmb.parse._apkbuild import apkbuild
from pmb.parse._apkbuild import function_body
from pmb.parse.binfmt_info import binfmt_info
from pmb.parse.deviceinfo import deviceinfo
from pmb.parse.kconfig import check

View File

@ -83,6 +83,31 @@ def cut_off_function_names(apkbuild):
return apkbuild
def function_body(path, func):
"""
Get the body of a function in an APKBUILD.
:param path: full path to the APKBUILD
:param func: name of function to get the body of.
:returns: function body in an array of strings.
"""
func_body = []
in_func = False
lines = read_file(path)
for line in lines:
if in_func:
if line.startswith("}"):
in_func = False
break
func_body.append(line)
continue
else:
if line.startswith(func + "() {"):
in_func = True
continue
return func_body
def read_file(path):
"""
Read an APKBUILD file