BIND 10 trac1914, updated. 6f514c3a7c3c727c8c0a8f690f4f3f18abe49032 [1924] Generate the common_defs.h header too

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Feb 4 15:44:42 UTC 2013


The branch, trac1914 has been updated
       via  6f514c3a7c3c727c8c0a8f690f4f3f18abe49032 (commit)
      from  6dab65b159cc406f375c2bc504a3622b628e6879 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6f514c3a7c3c727c8c0a8f690f4f3f18abe49032
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Feb 4 17:42:58 2013 +0100

    [1924] Generate the common_defs.h header too

-----------------------------------------------------------------------

Summary of changes:
 src/lib/util/Makefile.am   |    8 +++++--
 src/lib/util/common_defs.h |   47 -------------------------------------
 src/lib/util/const2hdr.py  |   56 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 49 deletions(-)
 delete mode 100644 src/lib/util/common_defs.h
 create mode 100644 src/lib/util/const2hdr.py

-----------------------------------------------------------------------
diff --git a/src/lib/util/Makefile.am b/src/lib/util/Makefile.am
index aaa4157..742302f 100644
--- a/src/lib/util/Makefile.am
+++ b/src/lib/util/Makefile.am
@@ -30,10 +30,14 @@ libb10_util_la_SOURCES += encode/binary_from_base16.h
 libb10_util_la_SOURCES += random/qid_gen.h random/qid_gen.cc
 libb10_util_la_SOURCES += random/random_number_generator.h
 
-EXTRA_DIST = python/pycppwrapper_util.h
+EXTRA_DIST = python/pycppwrapper_util.h const2hdr.py
+BUILT_SOURCES = common_defs.h
+
+common_defs.h: const2hdr.py common_defs.cc
+	$(PYTHON) $(srcdir)/const2hdr.py $(srcdir)/common_defs.cc $@
 
 libb10_util_la_LIBADD = $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
-CLEANFILES = *.gcno *.gcda
+CLEANFILES = *.gcno *.gcda common_defs.h
 
 libb10_util_includedir = $(includedir)/$(PACKAGE_NAME)/util
 libb10_util_include_HEADERS = buffer.h
diff --git a/src/lib/util/common_defs.h b/src/lib/util/common_defs.h
deleted file mode 100644
index 8a86830..0000000
--- a/src/lib/util/common_defs.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef BIND10_COMMON_DEFS_H
-#define BIND10_COMMON_DEFS_H
-
-namespace isc {
-namespace util {
-
-// \file common_defs.h
-// \brief Common constant definitions.
-//
-// This file contains common definitions of constasts used across the sources.
-// It includes, but is not limited to the definitions of messages sent from
-// one process to another. Since the names should be self-explanatory and
-// the variables here are used mostly to synchronize the same values across
-// multiple programs, separate documentation for each variable is not provided.
-//
-// \todo Generate this header from the .cc file too. It should be simple.
-
-// Constants used in the CC protocol (sent through MSGQ)
-// First the header names.
-extern const char* CC_HEADER_TYPE; // "type"
-extern const char* CC_HEADER_FROM; // "from"
-extern const char* CC_HEADER_TO; // "to"
-extern const char* CC_HEADER_GROUP; // "group"
-extern const char* CC_HEADER_INSTANCE; // "instance"
-extern const char* CC_HEADER_SEQ; // "seq"
-extern const char* CC_HEADER_WANT_ANSWER; // "want_answer"
-// Then the commands used in the CC_HEADER_TYPE header
-extern const char* CC_COMMAND_SEND; // "send"
-
-}
-}
-
-#endif
diff --git a/src/lib/util/const2hdr.py b/src/lib/util/const2hdr.py
new file mode 100644
index 0000000..f8383e2
--- /dev/null
+++ b/src/lib/util/const2hdr.py
@@ -0,0 +1,56 @@
+# Copyright (C) 2013  Internet Systems Consortium.
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
+# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+import sys
+import re
+
+def die(message):
+    sys.stderr.write(message + "\n")
+    sys.exit(1)
+
+if len(sys.argv) != 3:
+    die("Usage: python3 ./const2hdr.py input.cpp output.h")
+
+[filename_in, filename_out] = sys.argv[1:3]
+
+preproc = re.compile('^#')
+constant = re.compile('^([a-zA-Z].*?[a-zA-Z_0-9]+)\\s*=.*;')
+
+with open(filename_in) as file_in, open(filename_out, "w") as file_out:
+    file_out.write("// This file is generated from " + filename_in + "\n" +
+                   "// by the const2hdr.py script.\n" +
+                   "// Do not edit, all changes will be lost.\n\n")
+    for line in file_in:
+        if preproc.match(line):
+            # There's only one preprocessor line in the .cc file. We abuse
+            # that to position the top part of the header.
+            file_out.write("#ifndef BIND10_COMMON_DEFS_H\n" +
+                           "#define BIND10_COMMON_DEFS_H\n" +
+                           "\n" +
+                           "// \\file " + filename_out + "\n" +
+'''// \\brief Common shared constants\n
+// This file contains common definitions of constasts used across the sources.
+// It includes, but is not limited to the definitions of messages sent from
+// one process to another. Since the names should be self-explanatory and
+// the variables here are used mostly to synchronize the same values across
+// multiple programs, separate documentation for each variable is not provided.
+''')
+            continue
+        # Extract the constant. Remove the values and add "extern"
+        line = constant.sub('extern \\1;', line)
+
+        file_out.write(line)
+
+    file_out.write("#endif\n")



More information about the bind10-changes mailing list