[spice-common 1/5] codegen: Improve header guard generation

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

 



From: Frediano Ziglio <fziglio@xxxxxxxxxx>

Until now, the same header guard was used for all generated .h files.
Now the header guard name is based on the name of the file being
generated so that it's different for each .h file.
---
Frediano, I left you as the author of this patch but I squashed the changes I
suggested, I can take ownership and mention you in the commit log if you prefer.

Christophe


 python_modules/marshal.py | 13 +++++++++++--
 spice_codegen.py          |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/python_modules/marshal.py b/python_modules/marshal.py
index cc6cbdf..dc36e18 100644
--- a/python_modules/marshal.py
+++ b/python_modules/marshal.py
@@ -1,13 +1,22 @@
 
 from . import ptypes
 from . import codegen
+import re
 
 def write_includes(writer):
     writer.header.writeln("#include <spice/protocol.h>")
     writer.header.writeln('#include "common/marshaller.h"')
     writer.header.newline()
-    writer.header.writeln("#ifndef _GENERATED_HEADERS_H")
-    writer.header.writeln("#define _GENERATED_HEADERS_H")
+    if writer.header.has_option("dest_file"):
+        src = writer.header.options["dest_file"]
+    else:
+        src = "generated_headers.h"
+    src = re.sub(r'[^a-z0-9]+', '_', src, flags=re.IGNORECASE)
+    src = src.upper()
+    if src.endswith("_H"):
+        src = "_H_"+src[:-2]
+    writer.header.writeln("#ifndef %s" % src)
+    writer.header.writeln("#define %s" % src)
 
     writer.writeln("#include <string.h>")
     writer.writeln("#include <assert.h>")
diff --git a/spice_codegen.py b/spice_codegen.py
index 569cccc..53c7be3 100755
--- a/spice_codegen.py
+++ b/spice_codegen.py
@@ -170,6 +170,7 @@ if proto == None:
 codegen.set_prefix(proto.name)
 writer = codegen.CodeWriter()
 writer.header = codegen.CodeWriter()
+writer.header.set_option("dest_file", dest_file)
 writer.set_option("source", os.path.basename(proto_file))
 
 license = """/*
-- 
2.7.4

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]