mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-12 12:32:41 +00:00
python: pass conditionals through clippy for DEFPY
Track what conditionals apply when a DEFPY is encountered, and stack them around the autogenerated clippy wrapper. Otherwise conditional DEFPYs result in undefined function warnings. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
parent
379effbf70
commit
d11238bb5e
@ -173,7 +173,7 @@ handlers = {
|
|||||||
# common form, without requiring a more advanced template engine (e.g.
|
# common form, without requiring a more advanced template engine (e.g.
|
||||||
# jinja2)
|
# jinja2)
|
||||||
templ = Template(
|
templ = Template(
|
||||||
"""/* $fnname => "$cmddef" */
|
"""$cond_begin/* $fnname => "$cmddef" */
|
||||||
DEFUN_CMD_FUNC_DECL($fnname)
|
DEFUN_CMD_FUNC_DECL($fnname)
|
||||||
#define funcdecl_$fnname static int ${fnname}_magic(\\
|
#define funcdecl_$fnname static int ${fnname}_magic(\\
|
||||||
const struct cmd_element *self __attribute__ ((unused)),\\
|
const struct cmd_element *self __attribute__ ((unused)),\\
|
||||||
@ -211,7 +211,7 @@ $argblocks
|
|||||||
$argassert
|
$argassert
|
||||||
return ${fnname}_magic(self, vty, argc, argv$arglist);
|
return ${fnname}_magic(self, vty, argc, argv$arglist);
|
||||||
}
|
}
|
||||||
|
$cond_end
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -265,7 +265,25 @@ def process_file(fn, ofd, dumpfd, all_defun, macros):
|
|||||||
errors = 0
|
errors = 0
|
||||||
filedata = clippy.parse(fn)
|
filedata = clippy.parse(fn)
|
||||||
|
|
||||||
|
cond_stack = []
|
||||||
|
|
||||||
for entry in filedata["data"]:
|
for entry in filedata["data"]:
|
||||||
|
if entry["type"] == "PREPROC":
|
||||||
|
line = entry["line"].lstrip()
|
||||||
|
tokens = line.split(maxsplit=1)
|
||||||
|
line = "#" + line + "\n"
|
||||||
|
|
||||||
|
if not tokens:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if tokens[0] in ["if", "ifdef", "ifndef"]:
|
||||||
|
cond_stack.append(line)
|
||||||
|
elif tokens[0] in ["elif", "else"]:
|
||||||
|
prev_line = cond_stack.pop(-1)
|
||||||
|
cond_stack.append(prev_line + line)
|
||||||
|
elif tokens[0] in ["endif"]:
|
||||||
|
cond_stack.pop(-1)
|
||||||
|
continue
|
||||||
if entry["type"].startswith("DEFPY") or (
|
if entry["type"].startswith("DEFPY") or (
|
||||||
all_defun and entry["type"].startswith("DEFUN")
|
all_defun and entry["type"].startswith("DEFUN")
|
||||||
):
|
):
|
||||||
@ -385,6 +403,8 @@ def process_file(fn, ofd, dumpfd, all_defun, macros):
|
|||||||
else:
|
else:
|
||||||
dumpfd.write('"%s":\n\t---- no magic arguments ----\n\n' % (cmddef))
|
dumpfd.write('"%s":\n\t---- no magic arguments ----\n\n' % (cmddef))
|
||||||
|
|
||||||
|
params["cond_begin"] = "".join(cond_stack)
|
||||||
|
params["cond_end"] = "".join(["#endif\n"] * len(cond_stack))
|
||||||
params["argdefs"] = "".join(argdefs)
|
params["argdefs"] = "".join(argdefs)
|
||||||
params["argdecls"] = "".join(argdecls)
|
params["argdecls"] = "".join(argdecls)
|
||||||
params["arglist"] = "".join(arglist)
|
params["arglist"] = "".join(arglist)
|
||||||
|
Loading…
Reference in New Issue
Block a user