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