sdbusplus: split library and python scripts

(From meta-phosphor rev: 7aba8156394c5608565e549a1b9de3e9a91b5ff1)

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I471c25139f9fef8c976613a9f8c25d7617c1aa8c
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/meta-phosphor/recipes-core/packagegroups/nativesdk-packagegroup-sdk-host.bbappend b/meta-phosphor/recipes-core/packagegroups/nativesdk-packagegroup-sdk-host.bbappend
index d494db5..a3e2dcd 100644
--- a/meta-phosphor/recipes-core/packagegroups/nativesdk-packagegroup-sdk-host.bbappend
+++ b/meta-phosphor/recipes-core/packagegroups/nativesdk-packagegroup-sdk-host.bbappend
@@ -2,6 +2,6 @@
         nativesdk-autoconf-archive \
         nativesdk-meson \
         nativesdk-phosphor-dbus-interfaces-yaml \
-        nativesdk-sdbus++ \
+        nativesdk-python3-sdbus++ \
         nativesdk-phosphor-logging-elog \
         "
diff --git a/meta-phosphor/recipes-extended/sdbusplus/files/0001-sdbus-switch-to-python3.patch b/meta-phosphor/recipes-extended/sdbusplus/files/0001-sdbus-switch-to-python3.patch
new file mode 100644
index 0000000..ab1ea6c
--- /dev/null
+++ b/meta-phosphor/recipes-extended/sdbusplus/files/0001-sdbus-switch-to-python3.patch
@@ -0,0 +1,76 @@
+From 04852662bc68139e58bb51803cb32aa2d300c605 Mon Sep 17 00:00:00 2001
+From: Patrick Williams <patrick@stwcx.xyz>
+Date: Fri, 31 Jan 2020 18:47:38 -0800
+Subject: [PATCH] sdbus++: switch to python3
+
+Python2 is DEAD!  Long live Python3!
+
+Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
+Change-Id: Ifd46a4aeb41fb0e6db2f4310a603b727a5a2c2ff
+---
+ configure.ac                    | 2 +-
+ tools/sdbus++                   | 8 ++------
+ tools/sdbusplus/namedelement.py | 4 ++--
+ 3 files changed, 5 insertions(+), 9 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 11c189b..ec65562 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -29,7 +29,7 @@ AC_PROG_INSTALL
+ AC_PROG_MAKE_SET
+ 
+ # setup sdbus++
+-AM_PATH_PYTHON([2.7], [AC_SUBST([PYTHON], [echo "$PYTHON"])])
++AM_PATH_PYTHON([3.0], [AC_SUBST([PYTHON], [echo "$PYTHON"])])
+ AC_SUBST([PYTHONDIR], ${pythondir})
+ AS_IF([test "$PYTHON" != :], [have_python=yes], [have_python=no])
+ 
+diff --git a/tools/sdbus++ b/tools/sdbus++
+index 26969f3..d709c19 100755
+--- a/tools/sdbus++
++++ b/tools/sdbus++
+@@ -1,4 +1,4 @@
+-#!/usr/bin/env python
++#!/usr/bin/env python3
+ import sdbusplus
+ import mako.lookup
+ import argparse
+@@ -34,11 +34,7 @@ def main():
+ 
+     args = parser.parse_args()
+ 
+-    if sys.version_info < (3, 0):
+-        lookup = mako.lookup.TemplateLookup(directories=[args.templatedir],
+-                                            disable_unicode=True)
+-    else:
+-        lookup = mako.lookup.TemplateLookup(directories=[args.templatedir])
++    lookup = mako.lookup.TemplateLookup(directories=[args.templatedir])
+ 
+     instance = valid_types[args.typeName].load(args.item, args.rootdir)
+     function = getattr(instance, valid_processes[args.process])
+diff --git a/tools/sdbusplus/namedelement.py b/tools/sdbusplus/namedelement.py
+index 5048654..1548ef0 100644
+--- a/tools/sdbusplus/namedelement.py
++++ b/tools/sdbusplus/namedelement.py
+@@ -7,7 +7,7 @@ class NamedElement(object):
+         self.name = kwargs.pop('name', "unnamed")
+         self.description = kwargs.pop('description', "")
+ 
+-    def __getattr__(self, name):
++    def __getattribute__(self, name):
+         l = {'CamelCase': lambda: inflection.camelize(self.name),
+              'camelCase': lambda: inflection.camelize(self.name, False),
+              'snake_case': lambda: inflection.underscore(self.name)}\
+@@ -16,7 +16,7 @@ class NamedElement(object):
+         if l:
+             return NamedElement.__fixup_name(l())
+         try:
+-            return super(NamedElement, self).__getattr__(name)
++            return super(NamedElement, self).__getattribute__(name)
+         except:
+             raise AttributeError("Attribute '%s' not found in %s.NamedElement"
+                                  % (name, self.__module__))
+-- 
+2.13.5
+
diff --git a/meta-phosphor/recipes-extended/sdbusplus/python-sdbus++_git.bb b/meta-phosphor/recipes-extended/sdbusplus/python-sdbus++_git.bb
new file mode 100644
index 0000000..5d1c231
--- /dev/null
+++ b/meta-phosphor/recipes-extended/sdbusplus/python-sdbus++_git.bb
@@ -0,0 +1,7 @@
+inherit obmc-phosphor-python-autotools
+include sdbus++.inc
+
+# Provide these aliases temporarily until everyone can move over to the
+# new package name.
+PROVIDES_class-native += "sdbusplus-native sdbus++-native"
+PROVIDES_class-nativesdk += "sdbusplus-nativesdk sdbus++-nativesdk"
diff --git a/meta-phosphor/recipes-extended/sdbusplus/python3-sdbus++_git.bb b/meta-phosphor/recipes-extended/sdbusplus/python3-sdbus++_git.bb
new file mode 100644
index 0000000..c5aa212
--- /dev/null
+++ b/meta-phosphor/recipes-extended/sdbusplus/python3-sdbus++_git.bb
@@ -0,0 +1,4 @@
+inherit obmc-phosphor-python3-autotools
+include sdbus++.inc
+
+SRC_URI += "file://0001-sdbus-switch-to-python3.patch"
diff --git a/meta-phosphor/recipes-extended/sdbusplus/sdbus++.inc b/meta-phosphor/recipes-extended/sdbusplus/sdbus++.inc
new file mode 100644
index 0000000..b5cffb8
--- /dev/null
+++ b/meta-phosphor/recipes-extended/sdbusplus/sdbus++.inc
@@ -0,0 +1,25 @@
+SUMMARY = "sdbus++ dbus API / binding generator"
+DESCRIPTION = "Generates bindings against sdbusplus for dbus APIs"
+
+inherit autotools pkgconfig
+
+include sdbusplus-rev.inc
+
+DEPENDS += " \
+    autoconf-archive-native \
+    ${PYTHON_PN}-inflection-native \
+    ${PYTHON_PN}-mako-native \
+    ${PYTHON_PN}-pyyaml-native \
+    "
+
+RDEPENDS_${PN} += " \
+    ${PYTHON_PN}-inflection \
+    ${PYTHON_PN}-mako \
+    ${PYTHON_PN}-pyyaml \
+    "
+
+PACKAGECONFIG ??= "transaction"
+PACKAGECONFIG[libsdbusplus] = "--enable-libsdbusplus,--disable-libsdbusplus,systemd,libsystemd"
+PACKAGECONFIG[transaction] = "--enable-transaction,--disable-transaction"
+
+BBCLASSEXTEND += "native nativesdk"
diff --git a/meta-phosphor/recipes-extended/sdbusplus/sdbusplus_git.bb b/meta-phosphor/recipes-extended/sdbusplus/sdbusplus_git.bb
index a440003..1709906 100644
--- a/meta-phosphor/recipes-extended/sdbusplus/sdbusplus_git.bb
+++ b/meta-phosphor/recipes-extended/sdbusplus/sdbusplus_git.bb
@@ -12,38 +12,15 @@
         ${PYTHON_PN}-mako-native \
         ${PYTHON_PN}-pyyaml-native \
         "
-RDEPENDS_sdbus++ += " \
-        ${PYTHON_PN} \
-        ${PYTHON_PN}-inflection \
-        ${PYTHON_PN}-mako \
-        ${PYTHON_PN}-pyyaml \
-        "
-
-# sdbus++ has a handful of runtime dependencies on other python packages.
-# Bitbake doesn't do anything with RDEPENDS in native context because
-# native context doesn't have packages.
-#
-# While technically sdbus++ doesn't require its runtime dependencies to be
-# installed to build, work around the above native context behavior
-# by adding a build dependency so that clients don't have to DEPEND
-# on sdbus++ runtime dependencies manually.
-
-DEPENDS_append_class-native = " \
-        ${PYTHON_PN}-inflection-native \
-        ${PYTHON_PN}-mako-native \
-        ${PYTHON_PN}-pyyaml-native \
-        "
 
 PACKAGECONFIG ??= "libsdbusplus transaction"
 PACKAGECONFIG[libsdbusplus] = "--enable-libsdbusplus,--disable-libsdbusplus,systemd,libsystemd"
 PACKAGECONFIG[transaction] = "--enable-transaction,--disable-transaction"
 
-PROVIDES_prepend = "sdbus++ "
-PACKAGE_BEFORE_PN = "sdbus++"
-FILES_sdbus++_append = " ${bindir}/sdbus++"
-PYTHON_AUTOTOOLS_PACKAGE = "sdbus++"
-
-PACKAGECONFIG_remove_class-native = "libsdbusplus"
-PACKAGECONFIG_remove_class-nativesdk = "libsdbusplus"
-
-BBCLASSEXTEND += "native nativesdk"
+# Remove unused sdbus++ contents (included in python3-sdbus++ package).
+do_install_append() {
+    rm ${D}/${bindir}/sdbus++
+    rmdir ${D}/${bindir} || true
+    rm -rf ${D}/${PYTHON_SITEPACKAGES_DIR}
+    rmdir ${D}/${libdir}/${PYTHON_DIR} || true
+}