esx: separate header and source file generation

Invoke the generator twice and introduce separate
meson targets for headers and C sources.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Ján Tomko 2020-09-23 08:37:20 +02:00
parent b15483ff7b
commit 01c620ffc0
2 changed files with 115 additions and 77 deletions

View File

@ -1331,24 +1331,27 @@ additional_object_features = {
removed_object_features = {}
if len(sys.argv) != 3:
report_error("usage: %s srcdir builddir" % sys.argv[0])
if len(sys.argv) != 4:
report_error("usage: %s srcdir builddir header" % sys.argv[0])
input_filename = os.path.join(sys.argv[1], "esx/esx_vi_generator.input")
output_dirname = os.path.join(sys.argv[2], "esx")
header = sys.argv[3] == "header"
types_typedef = open_file(os.path.join(output_dirname, "esx_vi_types.generated.typedef"))
types_typeenum = open_file(os.path.join(output_dirname, "esx_vi_types.generated.typeenum"))
types_typetostring = open_file(os.path.join(output_dirname, "esx_vi_types.generated.typetostring"))
types_typefromstring = open_file(os.path.join(output_dirname, "esx_vi_types.generated.typefromstring"))
types_header = open_file(os.path.join(output_dirname, "esx_vi_types.generated.h"))
types_source = open_file(os.path.join(output_dirname, "esx_vi_types.generated.c"))
methods_header = open_file(os.path.join(output_dirname, "esx_vi_methods.generated.h"))
methods_source = open_file(os.path.join(output_dirname, "esx_vi_methods.generated.c"))
methods_macro = open_file(os.path.join(output_dirname, "esx_vi_methods.generated.macro"))
helpers_header = open_file(os.path.join(output_dirname, "esx_vi.generated.h"))
helpers_source = open_file(os.path.join(output_dirname, "esx_vi.generated.c"))
if header:
types_typedef = open_file(os.path.join(output_dirname, "esx_vi_types.generated.typedef"))
types_typeenum = open_file(os.path.join(output_dirname, "esx_vi_types.generated.typeenum"))
types_header = open_file(os.path.join(output_dirname, "esx_vi_types.generated.h"))
methods_header = open_file(os.path.join(output_dirname, "esx_vi_methods.generated.h"))
helpers_header = open_file(os.path.join(output_dirname, "esx_vi.generated.h"))
else:
types_typetostring = open_file(os.path.join(output_dirname, "esx_vi_types.generated.typetostring"))
types_typefromstring = open_file(os.path.join(output_dirname, "esx_vi_types.generated.typefromstring"))
types_source = open_file(os.path.join(output_dirname, "esx_vi_types.generated.c"))
methods_macro = open_file(os.path.join(output_dirname, "esx_vi_methods.generated.macro"))
methods_source = open_file(os.path.join(output_dirname, "esx_vi_methods.generated.c"))
helpers_source = open_file(os.path.join(output_dirname, "esx_vi.generated.c"))
number = 0
@ -1604,72 +1607,85 @@ for obj in managed_objects_by_name.values():
notice = "/* Generated by esx_vi_generator.py */\n\n\n\n"
types_typedef.write(notice)
types_typeenum.write(notice)
types_typetostring.write(notice)
types_typefromstring.write(notice)
types_header.write(notice)
types_source.write(notice)
methods_header.write(notice)
methods_source.write(notice)
methods_macro.write(notice)
helpers_header.write(notice)
helpers_source.write(notice)
if (header):
types_typedef.write(notice)
types_typeenum.write(notice)
types_header.write(notice)
methods_header.write(notice)
helpers_header.write(notice)
else:
types_typetostring.write(notice)
types_typefromstring.write(notice)
types_source.write(notice)
methods_macro.write(notice)
methods_source.write(notice)
helpers_source.write(notice)
# output enums
types_typedef.write(separator +
if header:
types_typedef.write(separator +
" * VI Enums\n" +
" */\n\n")
names = sorted(enums_by_name.keys())
for name in names:
if header:
types_typedef.write(enums_by_name[name].generate_typedef())
types_typeenum.write(enums_by_name[name].generate_typeenum())
types_header.write(enums_by_name[name].generate_header())
else:
types_typetostring.write(enums_by_name[name].generate_typetostring())
types_typefromstring.write(enums_by_name[name].generate_typefromstring())
types_header.write(enums_by_name[name].generate_header())
types_source.write(enums_by_name[name].generate_source())
# output objects
types_typedef.write("\n\n\n" +
if header:
types_typedef.write("\n\n\n" +
separator +
" * VI Objects\n" +
" */\n\n")
types_typeenum.write("\n")
types_typetostring.write("\n")
types_typefromstring.write("\n")
types_typeenum.write("\n")
else:
types_typetostring.write("\n")
types_typefromstring.write("\n")
names = sorted(objects_by_name.keys())
for name in names:
if header:
types_typedef.write(objects_by_name[name].generate_typedef())
types_typeenum.write(objects_by_name[name].generate_typeenum())
types_header.write(objects_by_name[name].generate_header())
else:
types_typetostring.write(objects_by_name[name].generate_typetostring())
types_typefromstring.write(objects_by_name[name].generate_typefromstring())
types_header.write(objects_by_name[name].generate_header())
types_source.write(objects_by_name[name].generate_source())
# output managed objects
types_typedef.write("\n\n\n" +
if header:
types_typedef.write("\n\n\n" +
separator +
" * VI Managed Objects\n" +
" */\n\n")
types_typeenum.write("\n")
types_typetostring.write("\n")
types_typefromstring.write("\n")
types_typeenum.write("\n")
else:
types_typetostring.write("\n")
types_typefromstring.write("\n")
names = sorted(managed_objects_by_name.keys())
for name in names:
if header:
types_typedef.write(managed_objects_by_name[name].generate_typedef())
types_typeenum.write(managed_objects_by_name[name].generate_typeenum())
types_header.write(managed_objects_by_name[name].generate_header())
else:
types_typetostring.write(managed_objects_by_name[name].generate_typetostring())
types_typefromstring.write(managed_objects_by_name[name].generate_typefromstring())
types_header.write(managed_objects_by_name[name].generate_header())
types_source.write(managed_objects_by_name[name].generate_source())
@ -1677,13 +1693,16 @@ for name in names:
names = sorted(methods_by_name.keys())
for name in names:
if header:
methods_header.write(methods_by_name[name].generate_header())
else:
methods_source.write(methods_by_name[name].generate_source())
names = list(autobind_names)
names.sort()
if not header:
names = list(autobind_names)
names.sort()
for name in names:
for name in names:
string = aligned("#define ESX_VI__METHOD__PARAMETER__THIS__%s " % name, "\\\n", 78)
string += " ESX_VI__METHOD__PARAMETER__THIS_FROM_SERVICE(ManagedObjectReference, \\\n"
string += aligned("", "%s)\n\n\n\n" % name, 49)
@ -1695,5 +1714,7 @@ for name in names:
names = sorted(managed_objects_by_name.keys())
for name in names:
if header:
helpers_header.write(managed_objects_by_name[name].generate_helper_header())
else:
helpers_source.write(managed_objects_by_name[name].generate_helper_source())

View File

@ -12,21 +12,36 @@ esx_sources = [
'esx_vi_types.c',
]
esx_gen_headers = custom_target(
'virtesxgenheaders',
input: [
'esx_vi_generator.input',
],
output: [
'esx_vi.generated.h',
'esx_vi_methods.generated.h',
'esx_vi_types.generated.h',
'esx_vi_types.generated.typedef',
'esx_vi_types.generated.typeenum',
],
command: [
meson_python_prog, python3_prog.path(), esx_vi_generator_prog.path(),
meson.source_root() / 'src',
meson.build_root() / 'src',
'header',
],
)
esx_gen_sources = custom_target(
'virtesxgen',
'virtesxgensources',
input: [
'esx_vi_generator.input',
],
output: [
'esx_vi.generated.c',
'esx_vi.generated.h',
'esx_vi_methods.generated.c',
'esx_vi_methods.generated.h',
'esx_vi_methods.generated.macro',
'esx_vi_methods.generated.c',
'esx_vi_types.generated.c',
'esx_vi_types.generated.h',
'esx_vi_types.generated.typedef',
'esx_vi_types.generated.typeenum',
'esx_vi_types.generated.typefromstring',
'esx_vi_types.generated.typetostring',
],
@ -34,6 +49,7 @@ esx_gen_sources = custom_target(
meson_python_prog, python3_prog.path(), esx_vi_generator_prog.path(),
meson.source_root() / 'src',
meson.build_root() / 'src',
'source',
],
)
@ -42,6 +58,7 @@ if conf.has('WITH_ESX')
'virt_driver_esx',
[
esx_sources,
esx_gen_headers[1],
esx_gen_sources[1],
],
dependencies: [