Skip to content

Commit 476867c

Browse files
dhruvibmrfrandse
authored andcommitted
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 <[email protected]>
1 parent 4a4fa43 commit 476867c

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

errors_map.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include <map>
4+
#include <string>
5+
#include <vector>
6+
7+
using EType = std::string;
8+
using Error = std::string;
9+
using ErrorList = std::vector<Error>;
10+
using ErrorMap = std::map<EType, ErrorList>;
11+
12+
extern const ErrorMap errorMap;

errors_map.mako.hpp renamed to errors_map.mako.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
## This file is a template. The comment below is emitted
22
## into the rendered file; feel free to edit this file.
33
// !!! WARNING: This is a GENERATED Code..Please do NOT Edit !!!
4-
#include <map>
5-
using EType = std::string;
6-
using Error = std::string;
7-
using ErrorList = std::vector<Error>;
8-
using ErrorMap = std::map<EType, std::vector<Error>>;
4+
#include "errors_map.hpp"
95

106
const ErrorMap errorMap = {
117
% for key, errors in errDict.items():

errors_map_gen.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,23 @@ def main():
1919
default="errors_watch.yaml",
2020
help="input errors watch yaml file to parse",
2121
)
22+
23+
parser.add_argument(
24+
"-c",
25+
"--cpp_file",
26+
dest="cpp_file",
27+
default="errors_map.cpp",
28+
help="output cpp file",
29+
)
2230
args = parser.parse_args()
2331

2432
with open(os.path.join(script_dir, args.errors_map_yaml), "r") as fd:
2533
yamlDict = yaml.safe_load(fd)
2634

27-
# Render the mako template
28-
template = os.path.join(script_dir, "errors_map.mako.hpp")
35+
# Render the mako template for cpp file
36+
template = os.path.join(script_dir, "errors_map.mako.cpp")
2937
t = Template(filename=template)
30-
with open("errors_map.hpp", "w") as fd:
38+
with open(args.cpp_file, "w") as fd:
3139
fd.write(t.render(errDict=yamlDict))
3240

3341

meson.build

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,26 +154,25 @@ conf_data.set('TIMESTAMP_FORMAT', get_option('TIMESTAMP_FORMAT'),
154154
configure_file(configuration : conf_data,
155155
output : 'config.h'
156156
)
157-
158157
subdir('xyz/openbmc_project/Dump/Internal/Create')
159158

160159
python = find_program('python3')
161160
errors_map_gen_file_loc = meson.project_source_root()
162161
errors_map_gen_file_loc += '/errors_map_gen.py'
163162

164-
errors_map_hpp = custom_target(
165-
'errors_map.hpp',
163+
errors_map_cpp = custom_target(
164+
'errors_map.cpp',
166165
command : [
167166
python,
168167
errors_map_gen_file_loc,
169168
'-i',
170169
get_option('ERROR_MAP_YAML')
171170
],
172-
depend_files : [ 'errors_map.mako.hpp',
171+
depend_files : [ 'errors_map.mako.cpp',
173172
'errors_map_gen.py',
174173
get_option('ERROR_MAP_YAML')
175174
],
176-
output : 'errors_map.hpp'
175+
output : 'errors_map.cpp'
177176
)
178177

179178
phosphor_dump_manager_sources = [
@@ -184,7 +183,7 @@ phosphor_dump_manager_sources = [
184183
'dump_manager_main.cpp',
185184
'dump_serialize.cpp',
186185
'elog_watch.cpp',
187-
errors_map_hpp,
186+
errors_map_cpp,
188187
common_hpp,
189188
server_hpp,
190189
common_hpp,

0 commit comments

Comments
 (0)