Move generated error map to cpp file
This commit changes the generation location of error map
from a header file (.hpp) to a source file (.cpp).
This change enhances code organization, separates
declaration from implementation.
In an upcoming change, retaining the map in the header
file results in a duplicate definition error.
Therefore, to avoid these errors and ensure smooth future
updates, the error map needs to be generated in the
.cpp file.
Tests:
Created error log dumps by commiting InternalFailure
Change-Id: I01e4503e24ebf9045793014060107cca4ff440ad
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
diff --git a/errors_map.hpp b/errors_map.hpp
new file mode 100644
index 0000000..1389509
--- /dev/null
+++ b/errors_map.hpp
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <map>
+#include <string>
+#include <vector>
+
+using EType = std::string;
+using Error = std::string;
+using ErrorList = std::vector<Error>;
+using ErrorMap = std::map<EType, ErrorList>;
+
+extern const ErrorMap errorMap;
diff --git a/errors_map.mako.hpp b/errors_map.mako.cpp
similarity index 67%
rename from errors_map.mako.hpp
rename to errors_map.mako.cpp
index b04f00e..b8246cf 100644
--- a/errors_map.mako.hpp
+++ b/errors_map.mako.cpp
@@ -1,11 +1,7 @@
## This file is a template. The comment below is emitted
## into the rendered file; feel free to edit this file.
// !!! WARNING: This is a GENERATED Code..Please do NOT Edit !!!
-#include <map>
-using EType = std::string;
-using Error = std::string;
-using ErrorList = std::vector<Error>;
-using ErrorMap = std::map<EType, std::vector<Error>>;
+#include "errors_map.hpp"
const ErrorMap errorMap = {
% for key, errors in errDict.items():
diff --git a/errors_map_gen.py b/errors_map_gen.py
index a7fac0d..9fafae9 100755
--- a/errors_map_gen.py
+++ b/errors_map_gen.py
@@ -19,15 +19,23 @@
default="errors_watch.yaml",
help="input errors watch yaml file to parse",
)
+
+ parser.add_argument(
+ "-c",
+ "--cpp_file",
+ dest="cpp_file",
+ default="errors_map.cpp",
+ help="output cpp file",
+ )
args = parser.parse_args()
with open(os.path.join(script_dir, args.errors_map_yaml), "r") as fd:
yamlDict = yaml.safe_load(fd)
- # Render the mako template
- template = os.path.join(script_dir, "errors_map.mako.hpp")
+ # Render the mako template for cpp file
+ template = os.path.join(script_dir, "errors_map.mako.cpp")
t = Template(filename=template)
- with open("errors_map.hpp", "w") as fd:
+ with open(args.cpp_file, "w") as fd:
fd.write(t.render(errDict=yamlDict))
diff --git a/meson.build b/meson.build
index e25247a..1ba3e32 100644
--- a/meson.build
+++ b/meson.build
@@ -122,26 +122,25 @@
configure_file(configuration : conf_data,
output : 'config.h'
)
-
subdir('xyz/openbmc_project/Dump/Internal/Create')
python = find_program('python3')
errors_map_gen_file_loc = meson.project_source_root()
errors_map_gen_file_loc += '/errors_map_gen.py'
-errors_map_hpp = custom_target(
- 'errors_map.hpp',
+errors_map_cpp = custom_target(
+ 'errors_map.cpp',
command : [
python,
errors_map_gen_file_loc,
'-i',
get_option('ERROR_MAP_YAML')
],
- depend_files : [ 'errors_map.mako.hpp',
+ depend_files : [ 'errors_map.mako.cpp',
'errors_map_gen.py',
get_option('ERROR_MAP_YAML')
],
- output : 'errors_map.hpp'
+ output : 'errors_map.cpp'
)
phosphor_dump_manager_sources = [
@@ -151,7 +150,7 @@
'dump_manager_main.cpp',
'dump_serialize.cpp',
'elog_watch.cpp',
- errors_map_hpp,
+ errors_map_cpp,
common_hpp,
server_hpp,
server_cpp,