On a Wednesday in 2023, Daniel P. Berrangé wrote:
The new program takes the formrpcgen [--mode source|header|repr] \ [--header include] \ xdr-file output-file If '--mode' is not given it parses the XDR file but does not generate anything, which is useful as a syntax check. The 'source' mode gives the '.c' file content, while 'header' gives the '.h' file content. 'repr' gives a representation of the abstract syntax tree, mostly useful for debugging the parser. If '--header' is given, it is added as a local #include ".." statement in the output and is valid for either 'header' or 'source' modes. Either 'xdr-file' or 'output-file' can be omitted in which case they default to stdin/stdout respectively. This rpcgen program will directly include the 'config.h' header in its output. Signed-off-by: Daniel P. Berrangé <[email protected]> --- scripts/rpcgen/main.py | 86 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 scripts/rpcgen/main.py diff --git a/scripts/rpcgen/main.py b/scripts/rpcgen/main.py new file mode 100755 index 0000000000..bf4ef38ede --- /dev/null +++ b/scripts/rpcgen/main.py @@ -0,0 +1,86 @@ +#!/usr/bin/python
#!/usr/bin/env python
+
+ if args.mode == "header":
+ print("/* This file is auto-generated from %s */\n" % args.input,
file=outfp)
+ print("#include <rpc/rpc.h>", file=outfp)
+ for h in args.header:
+ print('#include "%s"' % h, file=outfp)
+ print("", file=outfp)
+ print("#pragma once\n", file=outfp)
+ generator = XDRTypeDeclarationGenerator(spec)
+ print(generator.visit(), file=outfp)
+ generator = XDRMarshallDeclarationGenerator(spec)
+ print(generator.visit(), file=outfp)
+ elif args.mode == "source":
+ print("/* This file is auto-generated from %s */\n" % args.input,
file=outfp)
+ print("#include <config.h>", file=outfp)
+ if args.input.endswith(".x"):
+ print('#include "%s.h"' % args.input[:-2], file=outfp)
The .x file is in the source dir, while the .h file is in the build dir.
Unless I remove the two lines above, I'm getting an error:
src/remote/lxc_protocol.c:4:10: fatal error:
'../../git/libvirt/src/remote/lxc_protocol.h' file not found
#include "../../git/libvirt/src/remote/lxc_protocol.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
And thanks to the --header option, there already is an include of
lxc_protocol.h in the file:
#include <config.h>
#include "../../git/libvirt/src/remote/lxc_protocol.h"
#include "lxc_protocol.h"
If I use a builddir under libvirt.git, it somehow works:
#include <config.h>
#include "../src/remote/lxc_protocol.h"
#include "lxc_protocol.h"
Jano
+ for h in args.header:
+ print('#include "%s"' % h, file=outfp)
+ print("", file=outfp)
+ generator = XDRMarshallImplementationGenerator(spec)
+ print(generator.visit(), file=outfp)
+ elif args.mode == "repr":
+ print(spec, file=outfp)
+ else:
+ pass # Just validates XDR input syntax
+
+
+main()
--
2.39.1
signature.asc
Description: PGP signature
