sdbus++: handle error includes in Python code
Simplify the mako templates by moving code that calculates the
includes for error interfaces into Python. As a side-effect, this
moves the includes from the `{server,client}.cpp` to hpp.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: If2233e8615069a5c7630402c0cbee5d4f638f9d4
diff --git a/tools/sdbusplus/interface.py b/tools/sdbusplus/interface.py
index ce740a8..461b987 100644
--- a/tools/sdbusplus/interface.py
+++ b/tools/sdbusplus/interface.py
@@ -34,6 +34,16 @@
def joinedName(self, join_str, append):
return join_str.join(self.namespaces + [self.classname, append])
+ def error_includes(self, inc_list):
+ includes = []
+ for e in inc_list:
+ e = e.replace("self.", self.name + ".")
+ n = "/".join(
+ e.split(".")[:-2], # ignore the Error.Name
+ )
+ includes.append(f"{n}/error.hpp")
+ return sorted(set(includes))
+
def enum_includes(self, inc_list):
includes = []
for e in inc_list:
@@ -60,10 +70,12 @@
return self.render(loader, "interface.common.hpp.mako", interface=self)
def cpp_includes(self):
- return set.union(
- set(),
- *[
- set(m.cpp_includes(self))
- for m in self.methods + self.properties + self.signals
- ]
+ return sorted(
+ set.union(
+ set(),
+ *[
+ set(m.cpp_includes(self))
+ for m in self.methods + self.properties + self.signals
+ ],
+ )
)
diff --git a/tools/sdbusplus/method.py b/tools/sdbusplus/method.py
index 47d0c33..92bf139 100644
--- a/tools/sdbusplus/method.py
+++ b/tools/sdbusplus/method.py
@@ -27,7 +27,9 @@
)
def cpp_includes(self, interface):
- return interface.enum_includes(self.returns + self.parameters)
+ return interface.error_includes(self.errors) + interface.enum_includes(
+ self.returns + self.parameters
+ )
def returns_as_list(self, interface, full=False):
return ", ".join(
diff --git a/tools/sdbusplus/property.py b/tools/sdbusplus/property.py
index 9ac86fb..a798245 100644
--- a/tools/sdbusplus/property.py
+++ b/tools/sdbusplus/property.py
@@ -305,7 +305,9 @@
)
def cpp_includes(self, interface):
- return interface.enum_includes([self])
+ return interface.error_includes(self.errors) + interface.enum_includes(
+ [self]
+ )
def or_cpp_flags(self, flags):
"""Return the corresponding ORed cpp flags."""
diff --git a/tools/sdbusplus/templates/interface.server.cpp.mako b/tools/sdbusplus/templates/interface.server.cpp.mako
index 2d7d32d..9c726cd 100644
--- a/tools/sdbusplus/templates/interface.server.cpp.mako
+++ b/tools/sdbusplus/templates/interface.server.cpp.mako
@@ -7,9 +7,7 @@
#include <tuple>
#include <${interface.headerFile("server")}>
-% for m in interface.methods + interface.properties + interface.signals:
-${ m.cpp_prototype(loader, interface=interface, ptype='callback-cpp-includes') }
-% endfor
+
namespace sdbusplus::server::${interface.cppNamespace()}
{
diff --git a/tools/sdbusplus/templates/method.prototype.hpp.mako b/tools/sdbusplus/templates/method.prototype.hpp.mako
index 9618abd..ec0f3dc 100644
--- a/tools/sdbusplus/templates/method.prototype.hpp.mako
+++ b/tools/sdbusplus/templates/method.prototype.hpp.mako
@@ -8,11 +8,6 @@
def error_name(e):
return e.split('.').pop();
-
- def error_include(e):
- l = error_namespace(e).split('::')
- l.pop() # Remove "Error"
- return '/'.join(l) + '/error.hpp';
%>
###
### Emit 'header'
@@ -117,8 +112,4 @@
% endif
}
}
- % elif ptype == 'callback-cpp-includes':
- % for e in method.errors:
-#include <${error_include(e)}>
- % endfor
% endif
diff --git a/tools/sdbusplus/templates/property.prototype.hpp.mako b/tools/sdbusplus/templates/property.prototype.hpp.mako
index bc7c323..f8da663 100644
--- a/tools/sdbusplus/templates/property.prototype.hpp.mako
+++ b/tools/sdbusplus/templates/property.prototype.hpp.mako
@@ -8,11 +8,6 @@
def error_name(e):
return e.split('.').pop();
-
- def error_include(e):
- l = error_namespace(e).split('::')
- l.pop() # Remove "Error"
- return '/'.join(l) + '/error.hpp';
%>
% if ptype == 'callback-cpp':
auto ${interface.classname}::${property.camelCase}() const ->
@@ -116,8 +111,4 @@
${property.cppTypeParam(interface.name, full=True)}>());
}
}
-% elif ptype == 'callback-cpp-includes':
- % for e in property.errors:
-#include <${error_include(e)}>
- % endfor
% endif