@@ -65,10 +65,10 @@ def generate_unified_mshv_headers(kernel_hdr_path):
65
65
logging .debug ("Done generating unified header file" )
66
66
67
67
68
- def run_bindgen (kernel_hdr_path , output_dir , bindgen_args ):
68
+ def run_bindgen (kernel_hdr_path , output_file , bindgen_args ):
69
69
cmd = f"""
70
70
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 }
72
72
"""
73
73
logging .debug ("Running bindgen: %s" , cmd )
74
74
@@ -77,6 +77,23 @@ def run_bindgen(kernel_hdr_path, output_dir, bindgen_args):
77
77
rmtree (kernel_hdr_path )
78
78
79
79
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
+
80
97
def main (args ):
81
98
bindgen = check_installed ("bindgen" )
82
99
if not bindgen :
@@ -94,8 +111,10 @@ def main(args):
94
111
bindgen_args = "--no-doc-comments --with-derive-default "
95
112
96
113
bindgen_args += args .bindgen_args
114
+ output_file = f"{ args .output } /bindings.rs"
97
115
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 )
99
118
100
119
return 0
101
120
0 commit comments