Nina Schoetterl-Glausch <nsg@xxxxxxxxxxxxx> writes: > On Mon, 2023-02-27 at 08:59 +0100, Thomas Huth wrote: [...] >> I'm not sure whether double inclusion works with the QAPI parser (since this >> might code to be generated twice) ... have you tried? > > I haven't, the documentation says: > >> Include directives >> ------------------ >> >> Syntax:: >> >> INCLUDE = { 'include': STRING } >> >> The QAPI schema definitions can be modularized using the 'include' directive:: >> >> { 'include': 'path/to/file.json' } >> >> The directive is evaluated recursively, and include paths are relative >> to the file using the directive. Multiple includes of the same file >> are idempotent. > > Which is why I thought it should work, but I guess this is a statement about > including the same file twice in another file and not about including the same > file from two files. No, this is intended to say multiple inclusion is fine, regardless where the include directives are. An include directive has two effects: 1. If the included file has not been included already, pull in its contents. 2. Insert #include in generated C. Example: qdev.json includes qom.json. The generated qapi-*-qdev.h include qapi-types-qom.h. Including any required modules, as recommended by qapi-code-gen.rst, results in properly self-contained generated headers. > But then, as far as I can tell, the build system only builds qapi-schema.json, > which includes all other files, so it could apply. Yes, qapi-schema.json is the main module, which includes all the others. In fact, it includes all the others *directly*. Why? We generate documentation in source order. Included material gets inserted right at the first inclusion; subsequent inclusions have no effect. If we put all first inclusions right into qapi-schema.json, the order of things in documentation is visible right there, and won't change just because we change inclusions deeper down. Questions?