3604df
From 69442f05acf98130df16f1311edd704d4e937ac3 Mon Sep 17 00:00:00 2001
3604df
From: Aravinda VK <avishwan@redhat.com>
3604df
Date: Thu, 28 Jul 2016 15:49:59 +0530
3604df
Subject: [PATCH 32/79] eventsapi: Auto generate header files during make
3604df
3604df
$SRC/libglusterfs/src/eventtypes.h and $SRC/events/src/eventtypes.py are
3604df
generated by running `python $SRC/events/eventskeygen.py`
3604df
3604df
Header files generation step is added to make file itself, Now All new
3604df
events should be added to only to $SRC/events/eventskeygen.py file.
3604df
3604df
> Reviewed-on: http://review.gluster.org/15035
3604df
> Smoke: Gluster Build System <jenkins@build.gluster.org>
3604df
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
3604df
> Reviewed-by: Kotresh HR <khiremat@redhat.com>
3604df
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
3604df
> Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
3604df
BUG: 1351589
3604df
Change-Id: I384961ef2978ca2d0be37f288b39ac0d834bdf06
3604df
Signed-off-by: Aravinda VK <avishwan@redhat.com>
3604df
Reviewed-on: https://code.engineering.redhat.com/gerrit/84738
3604df
Reviewed-by: Milind Changire <mchangir@redhat.com>
3604df
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
---
3604df
 events/eventskeygen.py        |   49 ++++++++++++++++++++++------------------
3604df
 events/src/Makefile.am        |    9 ++++++-
3604df
 events/src/eventtypes.py      |   11 ---------
3604df
 libglusterfs/src/Makefile.am  |   10 +++++++-
3604df
 libglusterfs/src/eventtypes.h |   24 --------------------
3604df
 6 files changed, 46 insertions(+), 59 deletions(-)
3604df
 delete mode 100644 events/src/eventtypes.py
3604df
 delete mode 100644 libglusterfs/src/eventtypes.h
3604df
3604df
diff --git a/events/eventskeygen.py b/events/eventskeygen.py
3604df
index f9bdb9f..5bb0319 100644
3604df
--- a/events/eventskeygen.py
3604df
+++ b/events/eventskeygen.py
3604df
@@ -11,11 +11,14 @@
3604df
 #
3604df
 
3604df
 import os
3604df
+import sys
3604df
 
3604df
 GLUSTER_SRC_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
3604df
 eventtypes_h = os.path.join(GLUSTER_SRC_ROOT, "libglusterfs/src/eventtypes.h")
3604df
 eventtypes_py = os.path.join(GLUSTER_SRC_ROOT, "events/src/eventtypes.py")
3604df
 
3604df
+gen_header_type = sys.argv[1]
3604df
+
3604df
 # When adding new keys add it to the END
3604df
 keys = (
3604df
     "EVENT_PEER_ATTACH",
3604df
@@ -39,29 +42,31 @@ ERRORS = (
3604df
     "EVENT_ERROR_SEND"
3604df
 )
3604df
 
3604df
-# Generate eventtypes.h
3604df
-with open(eventtypes_h, "w") as f:
3604df
-    f.write("#ifndef __EVENTTYPES_H__\n")
3604df
-    f.write("#define __EVENTTYPES_H__\n\n")
3604df
-    f.write("typedef enum {\n")
3604df
-    for k in ERRORS:
3604df
-        f.write("    {0},\n".format(k))
3604df
-    f.write("} event_errors_t;\n")
3604df
+if gen_header_type == "C_HEADER":
3604df
+    # Generate eventtypes.h
3604df
+    with open(eventtypes_h, "w") as f:
3604df
+        f.write("#ifndef __EVENTTYPES_H__\n")
3604df
+        f.write("#define __EVENTTYPES_H__\n\n")
3604df
+        f.write("typedef enum {\n")
3604df
+        for k in ERRORS:
3604df
+            f.write("    {0},\n".format(k))
3604df
+        f.write("} event_errors_t;\n")
3604df
 
3604df
-    f.write("\n")
3604df
+        f.write("\n")
3604df
 
3604df
-    f.write("typedef enum {\n")
3604df
-    for k in keys:
3604df
-        f.write("    {0},\n".format(k))
3604df
+        f.write("typedef enum {\n")
3604df
+        for k in keys:
3604df
+            f.write("    {0},\n".format(k))
3604df
 
3604df
-    f.write("    {0}\n".format(LAST_EVENT))
3604df
-    f.write("} eventtypes_t;\n")
3604df
-    f.write("\n#endif /* __EVENTTYPES_H__ */\n")
3604df
+        f.write("    {0}\n".format(LAST_EVENT))
3604df
+        f.write("} eventtypes_t;\n")
3604df
+        f.write("\n#endif /* __EVENTTYPES_H__ */\n")
3604df
 
3604df
-# Generate eventtypes.py
3604df
-with open(eventtypes_py, "w") as f:
3604df
-    f.write("# -*- coding: utf-8 -*-\n")
3604df
-    f.write("all_events = [\n")
3604df
-    for ev in keys:
3604df
-        f.write('    "{0}",\n'.format(ev))
3604df
-    f.write("]\n")
3604df
+if gen_header_type == "PY_HEADER":
3604df
+    # Generate eventtypes.py
3604df
+    with open(eventtypes_py, "w") as f:
3604df
+        f.write("# -*- coding: utf-8 -*-\n")
3604df
+        f.write("all_events = [\n")
3604df
+        for ev in keys:
3604df
+            f.write('    "{0}",\n'.format(ev))
3604df
+        f.write("]\n")
3604df
diff --git a/events/src/Makefile.am b/events/src/Makefile.am
3604df
index 50317d4..8b2150e 100644
3604df
--- a/events/src/Makefile.am
3604df
+++ b/events/src/Makefile.am
3604df
@@ -1,6 +1,10 @@
3604df
-EXTRA_DIST = glustereventsd.py __init__.py  eventsapiconf.py.in eventtypes.py \
3604df
+noinst_PYTHON = $(top_srcdir)/events/eventskeygen.py
3604df
+EXTRA_DIST = glustereventsd.py __init__.py  eventsapiconf.py.in \
3604df
 	handlers.py utils.py peer_eventsapi.py eventsconfig.json
3604df
 
3604df
+BUILT_SOURCES = eventtypes.py
3604df
+CLEANFILES = eventtypes.py
3604df
+
3604df
 eventsdir = $(libexecdir)/glusterfs/events
3604df
 eventspeerscriptdir = $(libexecdir)/glusterfs
3604df
 eventsconfdir = $(sysconfdir)/glusterfs
3604df
@@ -10,6 +14,9 @@ events_PYTHON = __init__.py eventsapiconf.py eventtypes.py handlers.py utils.py
3604df
 events_SCRIPTS = glustereventsd.py
3604df
 eventspeerscript_SCRIPTS = peer_eventsapi.py
3604df
 
3604df
+eventtypes.py: $(top_srcdir)/events/eventskeygen.py
3604df
+	$(PYTHON) $(top_srcdir)/events/eventskeygen.py PY_HEADER
3604df
+
3604df
 install-exec-hook:
3604df
 	$(mkdir_p) $(DESTDIR)$(sbindir)
3604df
 	rm -f $(DESTDIR)$(sbindir)/glustereventsd
3604df
diff --git a/events/src/eventtypes.py b/events/src/eventtypes.py
3604df
deleted file mode 100644
3604df
index b09e5bc..0000000
3604df
--- a/events/src/eventtypes.py
3604df
+++ /dev/null
3604df
@@ -1,11 +0,0 @@
3604df
-# -*- coding: utf-8 -*-
3604df
-all_events = [
3604df
-    "EVENT_PEER_ATTACH",
3604df
-    "EVENT_PEER_DETACH",
3604df
-    "EVENT_VOLUME_CREATE",
3604df
-    "EVENT_VOLUME_START",
3604df
-    "EVENT_VOLUME_STOP",
3604df
-    "EVENT_VOLUME_DELETE",
3604df
-    "EVENT_VOLUME_SET",
3604df
-    "EVENT_VOLUME_RESET",
3604df
-]
3604df
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am
3604df
index 54b6194..66369e2 100644
3604df
--- a/libglusterfs/src/Makefile.am
3604df
+++ b/libglusterfs/src/Makefile.am
3604df
@@ -1,4 +1,4 @@
3604df
-noinst_PYTHON = generator.py gen-defaults.py
3604df
+noinst_PYTHON = generator.py gen-defaults.py $(top_srcdir)/events/eventskeygen.py
3604df
 
3604df
 libglusterfs_la_CFLAGS = $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) \
3604df
 	-DDATADIR=\"$(localstatedir)\"
3604df
@@ -73,9 +73,13 @@ libglusterfs_la_SOURCES += $(CONTRIBDIR)/uuid/clear.c \
3604df
 endif
3604df
 
3604df
 if BUILD_EVENTS
3604df
+BUILT_SOURCES += eventtypes.h
3604df
 libglusterfs_la_SOURCES += events.c
3604df
 
3604df
 libglusterfs_la_HEADERS += events.h eventtypes.h
3604df
+
3604df
+eventtypes.h: $(top_srcdir)/events/eventskeygen.py
3604df
+	$(PYTHON) $(top_srcdir)/events/eventskeygen.py C_HEADER
3604df
 endif
3604df
 
3604df
 libgfchangelog_HEADERS = changelog.h
3604df
@@ -111,3 +115,7 @@ CLEANFILES += *.gcda *.gcno *_xunit.xml
3604df
 noinst_PROGRAMS =
3604df
 TESTS =
3604df
 endif
3604df
+
3604df
+if BUILD_EVENTS
3604df
+CLEANFILES += eventtypes.h
3604df
+endif
3604df
diff --git a/libglusterfs/src/eventtypes.h b/libglusterfs/src/eventtypes.h
3604df
deleted file mode 100644
3604df
index 20c4b02..0000000
3604df
--- a/libglusterfs/src/eventtypes.h
3604df
+++ /dev/null
3604df
@@ -1,24 +0,0 @@
3604df
-#ifndef __EVENTTYPES_H__
3604df
-#define __EVENTTYPES_H__
3604df
-
3604df
-typedef enum {
3604df
-    EVENT_SEND_OK,
3604df
-    EVENT_ERROR_INVALID_INPUTS,
3604df
-    EVENT_ERROR_SOCKET,
3604df
-    EVENT_ERROR_CONNECT,
3604df
-    EVENT_ERROR_SEND,
3604df
-} event_errors_t;
3604df
-
3604df
-typedef enum {
3604df
-    EVENT_PEER_ATTACH,
3604df
-    EVENT_PEER_DETACH,
3604df
-    EVENT_VOLUME_CREATE,
3604df
-    EVENT_VOLUME_START,
3604df
-    EVENT_VOLUME_STOP,
3604df
-    EVENT_VOLUME_DELETE,
3604df
-    EVENT_VOLUME_SET,
3604df
-    EVENT_VOLUME_RESET,
3604df
-    EVENT_LAST
3604df
-} eventtypes_t;
3604df
-
3604df
-#endif /* __EVENTTYPES_H__ */
3604df
-- 
3604df
1.7.1
3604df