parser: Add function to read a function from an APKBUILD (!1747)
This commit is contained in:
parent
cd7d6a2431
commit
7d7a29d032
|
@ -18,6 +18,7 @@ along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
from pmb.parse.arguments import arguments
|
from pmb.parse.arguments import arguments
|
||||||
from pmb.parse._apkbuild import apkbuild
|
from pmb.parse._apkbuild import apkbuild
|
||||||
|
from pmb.parse._apkbuild import function_body
|
||||||
from pmb.parse.binfmt_info import binfmt_info
|
from pmb.parse.binfmt_info import binfmt_info
|
||||||
from pmb.parse.deviceinfo import deviceinfo
|
from pmb.parse.deviceinfo import deviceinfo
|
||||||
from pmb.parse.kconfig import check
|
from pmb.parse.kconfig import check
|
||||||
|
|
|
@ -83,6 +83,31 @@ def cut_off_function_names(apkbuild):
|
||||||
return 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):
|
def read_file(path):
|
||||||
"""
|
"""
|
||||||
Read an APKBUILD file
|
Read an APKBUILD file
|
||||||
|
|
Loading…
Reference in New Issue