elog-gen.py: Support subdirs

Add ability for elog-gen.py to find yaml files under subdirectories
so that yaml files found in Error/Callout/ and Error/IIC/ for
example can be found by the caller just passing the Error/ directory.

Change-Id: I91dcd523d2a75deea6266a3ea6885b88cd788206
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/Makefile.am b/Makefile.am
index f56fc37..3f10b0e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -68,20 +68,20 @@
 
 ELOG_MAKO ?= elog-gen-template.mako.hpp
 LOOKUP_MAKO ?= elog-lookup-template.mako.cpp
-ELOG_YAML_DIR ?= tools/example/xyz/openbmc_project/Example/
-ELOG_TEMPLATE_DIR ?= tools/phosphor-logging/templates/
+ELOG_YAML_DIR ?= ${abs_srcdir}/tools/example/
+ELOG_TEMPLATE_DIR ?= ${abs_srcdir}/tools/phosphor-logging/templates/
 REQ_FILES_TO_GEN ?= ${abs_srcdir}/tools/elog-gen.py\
-	${abs_srcdir}/$(ELOG_YAML_DIR)/$(ELOG_YAML)\
-	${abs_srcdir}/${ELOG_TEMPLATE_DIR}/$(ELOG_MAKO)
+	$(ELOG_YAML_DIR)/$(ELOG_YAML)\
+	${ELOG_TEMPLATE_DIR}/$(ELOG_MAKO)
 
 # Be sure to package up the required script, yaml, and mako template to
 # generate the header file
 EXTRA_DIST = $(REQ_FILES_TO_GEN)
 
 elog-gen.hpp: $(REQ_FILES_TO_GEN)
-	$(AM_V_at)$(PYTHON) ${abs_srcdir}/tools/elog-gen.py -y ${abs_srcdir}/${ELOG_YAML_DIR} -t ${abs_srcdir}/${ELOG_TEMPLATE_DIR} -m $(ELOG_MAKO) -o ${abs_srcdir}/elog-gen.hpp
+	$(AM_V_at)$(PYTHON) ${abs_srcdir}/tools/elog-gen.py -y ${ELOG_YAML_DIR} -t ${ELOG_TEMPLATE_DIR} -m $(ELOG_MAKO) -o ${abs_srcdir}/elog-gen.hpp
 elog-lookup.cpp: $(REQ_FILES_TO_GEN)
-	$(AM_V_at)$(PYTHON) ${abs_srcdir}/tools/elog-gen.py -y ${abs_srcdir}/${ELOG_YAML_DIR} -t ${abs_srcdir}/${ELOG_TEMPLATE_DIR} -m $(LOOKUP_MAKO) -o ${abs_srcdir}/elog-lookup.cpp
+	$(AM_V_at)$(PYTHON) ${abs_srcdir}/tools/elog-gen.py -y ${ELOG_YAML_DIR} -t ${ELOG_TEMPLATE_DIR} -m $(LOOKUP_MAKO) -o ${abs_srcdir}/elog-lookup.cpp
 
 pkgconfiglibdir = ${libdir}/pkgconfig
 pkgconfiglib_DATA = phosphor-logging.pc
diff --git a/tools/elog-gen.py b/tools/elog-gen.py
index 168e1fd..fe4807e 100755
--- a/tools/elog-gen.py
+++ b/tools/elog-gen.py
@@ -57,9 +57,10 @@
 
 
 def get_error_yaml_files(i_yaml_dir):
-    yaml_files = filter(
-        lambda file: file.endswith('.errors.yaml'),
-        os.listdir(i_yaml_dir))
+    yaml_files = []
+    for root, dirs, files in os.walk(i_yaml_dir):
+        for files in filter(lambda file: file.endswith('.errors.yaml'), files):
+            yaml_files.append(os.path.join(root, files))
     return yaml_files
 
 
@@ -110,7 +111,6 @@
 
     for error_yaml in error_yamls:
         # Verify the error yaml file
-        error_yaml = "/".join((i_yaml_dir, error_yaml))
         if (not (os.path.isfile(error_yaml))):
             print("Can not find input yaml file " + error_yaml)
             exit(1)