[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt PATCH 1/3] esx: separate header and source file generation



On Wed, Sep 23, 2020 at 11:17:43AM +0200, Ján Tomko wrote:
> Invoke the generator twice and introduce separate
> meson targets for headers and C sources.
> 
> Signed-off-by: Ján Tomko <jtomko redhat com>
> ---
>  scripts/esx_vi_generator.py | 159 ++++++++++++++++++++----------------
>  src/esx/meson.build         |  31 +++++--
>  2 files changed, 114 insertions(+), 76 deletions(-)
> 
> diff --git a/scripts/esx_vi_generator.py b/scripts/esx_vi_generator.py
> index 7929e1e682..2fac5152e5 100755
> --- a/scripts/esx_vi_generator.py
> +++ b/scripts/esx_vi_generator.py
> @@ -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"

It would be nice to use argparse here but that's for a different series.

> -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_typetostring = open_file(os.path.join(output_dirname, "esx_vi_types.generated.typetostring"))

This file is included by `src/esx/esx_vi_types.c` as part of a switch
so we might consider it as source.

> +    types_typefromstring = open_file(os.path.join(output_dirname, "esx_vi_types.generated.typefromstring"))

Similarly this file contains a lot of ifs and is included by
`src/esx/esx_vi_types.c` as source as well.

> +    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_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,96 +1607,112 @@ 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_typetostring.write(notice)
> +    types_typefromstring.write(notice)
> +    types_header.write(notice)
> +    methods_header.write(notice)
> +    helpers_header.write(notice)
> +else:
> +    types_source.write(notice)
> +    methods_macro.write(notice)
> +    methods_source.write(notice)
> +    helpers_source.write(notice)
>  
>  
>  # output enums
> -types_typedef.write(separator +
> -                    " * VI Enums\n" +
> -                    " */\n\n")
> +if header:
> +    types_typedef.write(separator +
> +                        " * VI Enums\n" +
> +                        " */\n\n")
>  
>  names = sorted(enums_by_name.keys())
>  
>  for name in names:
> -    types_typedef.write(enums_by_name[name].generate_typedef())
> -    types_typeenum.write(enums_by_name[name].generate_typeenum())
> -    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())
> +    if header:
> +        types_typedef.write(enums_by_name[name].generate_typedef())
> +        types_typeenum.write(enums_by_name[name].generate_typeenum())
> +        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())
> +    else:
> +        types_source.write(enums_by_name[name].generate_source())
>  
>  
>  # output objects
> -types_typedef.write("\n\n\n" +
> -                    separator +
> -                    " * VI Objects\n" +
> -                    " */\n\n")
> -types_typeenum.write("\n")
> -types_typetostring.write("\n")
> -types_typefromstring.write("\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")
>  
>  names = sorted(objects_by_name.keys())
>  
>  for name in names:
> -    types_typedef.write(objects_by_name[name].generate_typedef())
> -    types_typeenum.write(objects_by_name[name].generate_typeenum())
> -    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())
> +    if header:
> +        types_typedef.write(objects_by_name[name].generate_typedef())
> +        types_typeenum.write(objects_by_name[name].generate_typeenum())
> +        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())
> +    else:
> +        types_source.write(objects_by_name[name].generate_source())
>  
>  
>  # output managed objects
> -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")
> +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")
>  
>  names = sorted(managed_objects_by_name.keys())
>  
>  for name in names:
> -    types_typedef.write(managed_objects_by_name[name].generate_typedef())
> -    types_typeenum.write(managed_objects_by_name[name].generate_typeenum())
> -    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())
> +    if header:
> +        types_typedef.write(managed_objects_by_name[name].generate_typedef())
> +        types_typeenum.write(managed_objects_by_name[name].generate_typeenum())
> +        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())
> +    else:
> +        types_source.write(managed_objects_by_name[name].generate_source())
>  
>  
>  # output methods
>  names = sorted(methods_by_name.keys())
>  
>  for name in names:
> -    methods_header.write(methods_by_name[name].generate_header())
> -    methods_source.write(methods_by_name[name].generate_source())
> +    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:
> -    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)
> +    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)
>  
> -    methods_macro.write(string)
> +        methods_macro.write(string)
>  
>  
>  # output helpers
>  names = sorted(managed_objects_by_name.keys())
>  
>  for name in names:
> -    helpers_header.write(managed_objects_by_name[name].generate_helper_header())
> -    helpers_source.write(managed_objects_by_name[name].generate_helper_source())
> +    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())
> diff --git a/src/esx/meson.build b/src/esx/meson.build
> index f2d59462fe..b7a55f6b54 100644
> --- a/src/esx/meson.build
> +++ b/src/esx/meson.build
> @@ -12,18 +12,15 @@ esx_sources = [
>    'esx_vi_types.c',
>  ]
>  
> -esx_gen_sources = custom_target(
> -  'virtesxgen',
> +
> +esx_gen_headers = custom_target(
> +  'virtesxgenheaders',
>    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_types.generated.c',
>      'esx_vi_types.generated.h',
>      'esx_vi_types.generated.typedef',
>      'esx_vi_types.generated.typeenum',
> @@ -34,6 +31,27 @@ esx_gen_sources = custom_target(
>      meson_python_prog, python3_prog.path(), esx_vi_generator_prog.path(),
>      meson.source_root() / 'src',
>      meson.build_root() / 'src',
> +    'header',
> +  ],
> +)
> +
> +

No need for two empty lines as the rest of the file uses only one.

> +esx_gen_sources = custom_target(
> +  'virtesxgensources',
> +  input: [
> +    'esx_vi_generator.input',
> +  ],
> +  output: [
> +    'esx_vi.generated.c',
> +    'esx_vi_methods.generated.macro',
> +    'esx_vi_methods.generated.c',
> +    'esx_vi_types.generated.c',
> +  ],
> +  command: [
> +    meson_python_prog, python3_prog.path(), esx_vi_generator_prog.path(),
> +    meson.source_root() / 'src',
> +    meson.build_root() / 'src',
> +    'source',
>    ],
>  )
>  
> @@ -42,6 +60,7 @@ if conf.has('WITH_ESX')
>      'virt_driver_esx',
>      [
>        esx_sources,
> +      esx_gen_headers[1],
>        esx_gen_sources[1],
>      ],
>      dependencies: [
> -- 
> 2.26.2
> 

Attachment: signature.asc
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]