Skip to content

Commit

Permalink
Move generated error map to cpp file
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dhruvibm authored and rfrandse committed Aug 11, 2023
1 parent 4a4fa43 commit 476867c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
12 changes: 12 additions & 0 deletions errors_map.hpp
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 1 addition & 5 deletions errors_map.mako.hpp → errors_map.mako.cpp
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
14 changes: 11 additions & 3 deletions errors_map_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@ def main():
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))


Expand Down
11 changes: 5 additions & 6 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,25 @@ conf_data.set('TIMESTAMP_FORMAT', get_option('TIMESTAMP_FORMAT'),
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 = [
Expand All @@ -184,7 +183,7 @@ phosphor_dump_manager_sources = [
'dump_manager_main.cpp',
'dump_serialize.cpp',
'elog_watch.cpp',
errors_map_hpp,
errors_map_cpp,
common_hpp,
server_hpp,
common_hpp,
Expand Down

0 comments on commit 476867c

Please sign in to comment.