3 # Module information generator
5 # Copyright Red Hat, Inc. 2015 - 2016
8 # Marc Mari <markmb@redhat.com>
10 # This work is licensed under the terms of the GNU GPL, version 2.
11 # See the COPYING file in the top-level directory.
16 def get_string_struct(line
):
19 # data[0] -> struct element name
23 return data
[2].replace('"', '')[:-1]
25 def add_module(fheader
, library
, format_name
, protocol_name
):
27 lines
.append('.library_name = "' + library
+ '",')
29 lines
.append('.format_name = "' + format_name
+ '",')
30 if protocol_name
!= "":
31 lines
.append('.protocol_name = "' + protocol_name
+ '",')
33 text
= '\n '.join(lines
)
34 fheader
.write('\n {\n ' + text
+ '\n },')
36 def process_file(fheader
, filename
):
37 # This parser assumes the coding style rules are being followed
38 with
open(filename
, "r") as cfile
:
40 library
, _
= os
.path
.splitext(os
.path
.basename(filename
))
43 line
= line
.replace('\n', '')
44 if line
.find(".format_name") != -1:
45 format_name
= get_string_struct(line
)
46 elif line
.find(".protocol_name") != -1:
47 protocol_name
= get_string_struct(line
)
49 add_module(fheader
, library
, format_name
, protocol_name
)
51 elif line
.find("static BlockDriver") != -1:
56 def print_top(fheader
):
57 fheader
.write('''/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
59 * QEMU Block Module Infrastructure
62 * Marc Mari <markmb@redhat.com>
67 fheader
.write('''#ifndef QEMU_MODULE_BLOCK_H
68 #define QEMU_MODULE_BLOCK_H
71 const char *format_name;
72 const char *protocol_name;
73 const char *library_name;
74 } block_driver_modules[] = {''')
76 def print_bottom(fheader
):
83 if __name__
== '__main__':
84 # First argument: output file
85 # All other arguments: modules source files (.c)
86 output_file
= sys
.argv
[1]
87 with
open(output_file
, 'w') as fheader
:
90 for filename
in sys
.argv
[2:]:
91 if os
.path
.isfile(filename
):
92 process_file(fheader
, filename
)
94 print("File " + filename
+ " does not exist.", file=sys
.stderr
)