summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAndrew Geissler <andrewg@us.ibm.com>2016-11-15 09:30:09 -0600
committerAndrew Geissler <andrewg@us.ibm.com>2016-11-18 16:30:03 -0600
commitefb31c454b311771fba97833be9747bf751759ab (patch)
treeada48f8bd2a0b5309160978441debf0696de5ab8 /tools
parent40cb653b00ce9ede294a7e2b4934c5716cdbf9cf (diff)
downloadphosphor-logging-efb31c454b311771fba97833be9747bf751759ab.tar.gz
phosphor-logging-efb31c454b311771fba97833be9747bf751759ab.zip
Move header generation tool and templates to sub-directories
This is being done to prep for exporting the tools and templates to be used by other repos Change-Id: Ia93166ade2a0361eca86cde123875b95a44a1ef3 Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/elog-gen.py101
-rw-r--r--tools/phosphor-logging/templates/elog-gen-template.mako.hpp61
-rw-r--r--tools/phosphor-logging/templates/elog-lookup-template.mako.cpp25
3 files changed, 187 insertions, 0 deletions
diff --git a/tools/elog-gen.py b/tools/elog-gen.py
new file mode 100755
index 0000000..c94e1b4
--- /dev/null
+++ b/tools/elog-gen.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+
+r"""
+This script will parse the input error log yaml file and generate
+a header file which will then be used by the error logging client and
+server to collect and validate the error information generated by the
+openbmc software components.
+
+This code uses a mako template to provide the basic template of the header
+file we're going to generate. We then call it with information from the
+yaml to generate the header file.
+
+"""
+
+from mako.template import Template
+from optparse import OptionParser
+import yaml
+import sys
+import os
+
+
+def gen_elog_hpp(i_elog_yaml, i_input_mako, i_output_hpp):
+ r"""
+ Read the input yaml file, grab the relevant data and call the mako
+ template to generate the header file.
+
+ Description of arguments:
+ i_elog_yaml yaml file describing the error logs
+ i_output_hpp header file to output the generated code to
+ """
+
+ # Input parameters to mako template
+ errors = dict() # Main error codes
+ error_msg = dict() # Error msg that corresponds to error code
+ error_lvl = dict() # Error code log level (debug, info, error, ...)
+ meta = list() # The meta data names associated (ERRNO, FILE_NAME, ...)
+ meta_data = dict() # The meta data info (type, format)
+
+ # see elog.yaml for reference
+ ifile = yaml.safe_load(open(i_elog_yaml))
+ err_count = 0
+ for i in ifile['error-codes']:
+ # Grab the main error and it's info
+ errors[err_count] = i['name']
+ error_msg[i['name']] = i['msg']
+ error_lvl[i['name']] = i['level']
+ tmp_meta = []
+ # grab all the meta data fields and info
+ for j in i['meta']:
+ str_short = j['str'].split('=')[0]
+ tmp_meta.append(str_short)
+ meta_data[str_short] = {}
+ meta_data[str_short]['str'] = j['str']
+ meta_data[str_short]['str_short'] = str_short
+ meta_data[str_short]['type'] = j['type']
+ meta.append(tmp_meta)
+ err_count += 1
+
+ # Debug
+ # for i in errors:
+ # print "ERROR: " + errors[i]
+ # print " MSG: " + error_msg[errors[i]]
+ # print " LVL: " + error_lvl[errors[i]]
+ # print " META: "
+ # print meta[i]
+
+ # Load the mako template and call it with the required data
+ mytemplate = Template(filename=i_input_mako)
+ f = open(i_output_hpp, 'w')
+ f.write(mytemplate.render(errors=errors, error_msg=error_msg,
+ error_lvl=error_lvl, meta=meta,
+ meta_data=meta_data))
+ f.close()
+
+
+def main(i_args):
+ parser = OptionParser()
+
+ parser.add_option("-e", "--elog", dest="elog_yaml", default="elog.yaml",
+ help="input error yaml file to parse")
+
+ parser.add_option("-m", "--mako", dest="elog_mako",
+ default="elog-gen-template.mako.hpp",
+ help="input mako template file to use")
+
+ parser.add_option("-o", "--output", dest="output_hpp",
+ default="elog-gen.hpp",
+ help="output hpp to generate, elog-gen.hpp is default")
+
+ (options, args) = parser.parse_args(i_args)
+
+ if (not (os.path.isfile(options.elog_yaml))):
+ print "Can not find input yaml file " + options.elog_yaml
+ exit(1)
+
+ gen_elog_hpp(options.elog_yaml, options.elog_mako,
+ options.output_hpp)
+
+# Only run if it's a script
+if __name__ == '__main__':
+ main(sys.argv[1:])
diff --git a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
new file mode 100644
index 0000000..cb7137d
--- /dev/null
+++ b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
@@ -0,0 +1,61 @@
+## Note that this file is not auto generated, it is what generates the
+## elog-gen.hpp file
+// This file was autogenerated. Do not edit!
+// See elog-gen.py for more details
+#pragma once
+
+#include <tuple>
+#include <type_traits>
+#include "log.hpp"
+
+namespace phosphor
+{
+
+namespace logging
+{
+
+ % for a in errors:
+<%
+ namespaces = errors[a].split('.')
+ classname = namespaces.pop()
+%>\
+ % for s in namespaces:
+namespace ${s}
+{
+ % endfor
+
+namespace _${classname}
+{
+ % for b in meta[a]:
+struct ${b}
+{
+ static constexpr auto str = "${meta_data[b]['str']}";
+ static constexpr auto str_short = "${meta_data[b]['str_short']}";
+ using type = std::tuple<std::decay_t<decltype(str)>,${meta_data[b]['type']}>;
+ explicit constexpr ${b}(${meta_data[b]['type']} a) : _entry(entry(str, a)) {};
+ type _entry;
+};
+ % endfor
+
+} // namespace _${classname}
+<% meta_string = ', '.join(meta[a]) %>
+struct ${classname}
+{
+ static constexpr auto err_code = "${errors[a]}";
+ static constexpr auto err_msg = "${error_msg[errors[a]]}";
+ static constexpr auto L = level::${error_lvl[errors[a]]};
+ % for b in meta[a]:
+ using ${b} = _${classname}::${b};
+ % endfor
+ using metadata_types = std::tuple<${meta_string}>;
+};
+
+% for s in reversed(namespaces):
+} // namespace ${s}
+% endfor
+
+ % endfor
+
+} // namespace logging
+
+} // namespace phosphor
diff --git a/tools/phosphor-logging/templates/elog-lookup-template.mako.cpp b/tools/phosphor-logging/templates/elog-lookup-template.mako.cpp
new file mode 100644
index 0000000..a96760e
--- /dev/null
+++ b/tools/phosphor-logging/templates/elog-lookup-template.mako.cpp
@@ -0,0 +1,25 @@
+## Note that this file is not auto generated, it is what generates the
+## elog-lookup.hpp file
+// This file was autogenerated. Do not edit!
+// See elog-gen.py for more details
+#pragma once
+
+#include <map>
+#include <vector>
+
+namespace phosphor
+{
+
+namespace logging
+{
+
+std::map<std::string,std::vector<std::string>> g_errMetaMap = {
+ % for a in errors:
+ <% meta_string = '\",\"'.join(meta[a]) %> \
+ {"${errors[a]}",{"${meta_string}"}},
+ % endfor
+};
+
+} // namespace logging
+
+} // namespace phosphor
OpenPOWER on IntegriCloud