Add argument for errors.hpp to pdmgen.py, fix race

pdmgen.py is now given a "-e" argument to specify where to write
errors.hpp.

Previously it was hardcoded to 'errors.hpp', this could
hit a race where the src/test run of pdmgen.py could overwrite
the actual errors.hpp with an empty file.
That resulted in missing definitions with a compile error such as
...phosphor-dbus-monitor/1.0+gitAUTOINC+413a485715-r1/recipe-sysroot/usr/include/c++/12.1.0/type_traits:1447:38: error: invalid use of incomplete type 'struct sdbusplus::xyz::openbmc_project::Sensor::Threshold::Error::CriticalHigh'

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
Change-Id: Ib982631e506ade18c587a3e6552e4109760758ef
diff --git a/src/meson.build b/src/meson.build
index 64a2b86..76b8ef8 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -28,6 +28,7 @@
         '-p', meson.project_source_root() + '/src/templates',
         '-d', yamldir,
         '-o', meson.current_build_dir() + '/generated.hpp',
+        '-e', meson.current_build_dir() + '/errors.hpp',
         'generate-cpp'
     ],
     depend_files: templates_depends,
diff --git a/src/pdmgen.py b/src/pdmgen.py
index 925dd21..ea7cd13 100755
--- a/src/pdmgen.py
+++ b/src/pdmgen.py
@@ -926,7 +926,7 @@
         super(Elog, self).__init__(**kw)
 
     def construct(self, loader, indent):
-        with open('errors.hpp', 'a') as fd:
+        with open(args.gen_errors, 'a') as fd:
             fd.write(
                 self.render(
                     loader,
@@ -976,7 +976,7 @@
         super(ElogWithMetadata, self).__init__(**kw)
 
     def construct(self, loader, indent):
-        with open('errors.hpp', 'a') as fd:
+        with open(args.gen_errors, 'a') as fd:
             fd.write(
                 self.render(
                     loader,
@@ -1347,7 +1347,7 @@
     def generate_cpp(self, loader):
         '''Render the template with the provided data.'''
         # errors.hpp is used by generated.hpp to included any error.hpp files
-        open('errors.hpp', 'w+')
+        open(args.gen_errors, 'w+')
 
         with open(args.output, 'w') as fd:
             fd.write(
@@ -1395,6 +1395,10 @@
         default='generated.mako.hpp',
         help='The top level template to render.')
     parser.add_argument(
+        '-e', '--errors', dest='gen_errors',
+        default='errors.hpp',
+        help='Generated errors.hpp output filename.')
+    parser.add_argument(
         '-p', '--template-path', dest='template_search',
         default=script_dir,
         help='The space delimited mako template search path.')
diff --git a/src/test/meson.build b/src/test/meson.build
index 40f8406..a1ae8e3 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -28,6 +28,7 @@
         '-p', meson.project_source_root() + '/src/test/templates',
         '-d', meson.project_source_root() + '/src/test/yaml/pathgentest',
         '-o', meson.current_build_dir() + '/pathgentest.hpp',
+        '-e', meson.current_build_dir() + '/pathgentest-errors.hpp',
         'generate-cpp'
     ],
     input: [
@@ -62,6 +63,7 @@
         '-p', meson.project_source_root() + '/src/test/templates',
         '-d', meson.project_source_root() + '/src/test/yaml/propertygentest',
         '-o', meson.current_build_dir() + '/propertygentest.hpp',
+        '-e', meson.current_build_dir() + '/propertygentest-errors.hpp',
         'generate-cpp'
     ],
     input: [
@@ -96,6 +98,7 @@
         '-p', meson.project_source_root() + '/src/test/templates',
         '-d', meson.project_source_root() + '/src/test/yaml/propertywatchgentest',
         '-o', meson.current_build_dir() + '/propertywatchgentest.hpp',
+        '-e', meson.current_build_dir() + '/propertywatchgentest-errors.hpp',
         'generate-cpp'
     ],
     input: [
@@ -130,6 +133,7 @@
         '-p', meson.project_source_root() + '/src/test/templates',
         '-d', meson.project_source_root() + '/src/test/yaml/callbackgentest',
         '-o', meson.current_build_dir() + '/callbackgentest.hpp',
+        '-e', meson.current_build_dir() + '/callbackgentest-errors.hpp',
         'generate-cpp'
     ],
     input: [
@@ -164,6 +168,7 @@
         '-p', meson.project_source_root() + '/src/test/templates',
         '-d', meson.project_source_root() + '/src/test/yaml/callbackgroupgentest',
         '-o', meson.current_build_dir() + '/callbackgroupgentest.hpp',
+        '-e', meson.current_build_dir() + '/callbackgroupgentest-errors.hpp',
         'generate-cpp'
     ],
     input: [
@@ -197,6 +202,7 @@
         '-p', meson.project_source_root() + '/src/test/templates',
         '-d', meson.project_source_root() + '/src/test/yaml/conditiongentest',
         '-o', meson.current_build_dir() + '/conditiongentest.hpp',
+        '-e', meson.current_build_dir() + '/conditiongentest-errors.hpp',
         'generate-cpp'
     ],
     input: [
@@ -259,6 +265,7 @@
         '-p', meson.project_source_root() + '/src/test/templates',
         '-d', meson.project_source_root() + '/src/test/yaml/interfaceaddtest',
         '-o', meson.current_build_dir() + '/interfaceaddtest.hpp',
+        '-e', meson.current_build_dir() + '/interfaceaddtest-errors.hpp',
         'generate-cpp'
     ],
     input: [