Skip to content

Commit 1438095

Browse files
NunoDasNevesjinankjain
authored andcommitted
generate bindings: Generate header comment
Insert a comment below the bindgen one with the list of header files included Signed-off-by: Nuno Das Neves <[email protected]>
1 parent bc9e42b commit 1438095

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

scripts/generate_binding.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ def generate_unified_mshv_headers(kernel_hdr_path):
6565
logging.debug("Done generating unified header file")
6666

6767

68-
def run_bindgen(kernel_hdr_path, output_dir, bindgen_args):
68+
def run_bindgen(kernel_hdr_path, output_file, bindgen_args):
6969
cmd = f"""
7070
bindgen {bindgen_args} \
71-
{kernel_hdr_path}/combined_mshv.h -- -I {kernel_hdr_path}/include > {output_dir}/bindings.rs
71+
{kernel_hdr_path}/combined_mshv.h -- -I {kernel_hdr_path}/include > {output_file}
7272
"""
7373
logging.debug("Running bindgen: %s", cmd)
7474

@@ -77,6 +77,23 @@ def run_bindgen(kernel_hdr_path, output_dir, bindgen_args):
7777
rmtree(kernel_hdr_path)
7878

7979

80+
def update_bindings_comment(bindings_file):
81+
comment_lines = [
82+
"/*\n",
83+
" * Kernel (uapi) headers used for these bindings are as follows:\n",
84+
" */\n"
85+
]
86+
comment_lines[2:2] = map(lambda s: f" * {s}\n", mshv_header_files)
87+
88+
with open(bindings_file, "r") as f:
89+
lines = f.readlines()
90+
91+
lines[1:1] = comment_lines
92+
93+
with open(bindings_file, "w") as f:
94+
f.write("".join(lines))
95+
96+
8097
def main(args):
8198
bindgen = check_installed("bindgen")
8299
if not bindgen:
@@ -94,8 +111,10 @@ def main(args):
94111
bindgen_args = "--no-doc-comments --with-derive-default "
95112

96113
bindgen_args += args.bindgen_args
114+
output_file = f"{args.output}/bindings.rs"
97115

98-
run_bindgen(kernel_hdr_path, args.output, bindgen_args)
116+
run_bindgen(kernel_hdr_path, output_file, bindgen_args)
117+
update_bindings_comment(output_file)
99118

100119
return 0
101120

0 commit comments

Comments
 (0)