File vbox-python-selection.patch of Package virtualbox.openSUSE_Leap_15.3_Update

Index: VirtualBox-6.1.34/src/bldprogs/scm.cpp
===================================================================
--- VirtualBox-6.1.34.orig/src/bldprogs/scm.cpp
+++ VirtualBox-6.1.34/src/bldprogs/scm.cpp
@@ -2206,7 +2206,7 @@ static int scmProcessFileInner(PSCMRWSTA
                             pszTreatAs = "shell";
                         else if (   (cchFirst >= 15 && strncmp(pchFirst, "/usr/bin/python", 15) == 0)
                                  || (cchFirst >= 19 && strncmp(pchFirst, "/usr/bin/env python", 19) == 0) )
-                            pszTreatAs = "python";
+                            pszTreatAs = "python3";
                         else if (   (cchFirst >= 13 && strncmp(pchFirst, "/usr/bin/perl", 13) == 0)
                                  || (cchFirst >= 17 && strncmp(pchFirst, "/usr/bin/env perl", 17) == 0) )
                             pszTreatAs = "perl";
Index: VirtualBox-6.1.34/src/libs/libxml2-2.9.4/configure
===================================================================
--- VirtualBox-6.1.34.orig/src/libs/libxml2-2.9.4/configure
+++ VirtualBox-6.1.34/src/libs/libxml2-2.9.4/configure
@@ -15153,10 +15153,10 @@ PYTHON_SITE_PACKAGES=
 PYTHON_TESTS=
 pythondir=
 if test "$with_python" != "no" ; then
-    if test -x "$with_python/bin/python"
+    if test -x "$with_python/bin/python3"
     then
-        echo Found python in $with_python/bin/python
-        PYTHON="$with_python/bin/python"
+        echo Found python in $with_python/bin/python3
+        PYTHON="$with_python/bin/python3"
     else
         if test -x "$with_python/python.exe"
         then
@@ -15174,7 +15174,8 @@ if test "$with_python" != "no" ; then
                     with_python=`$PYTHON -c "import sys; print(sys.exec_prefix)"`
                 else
                     # Extract the first word of "python python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5", so it can be a program name with args.
-set dummy python python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5; ac_word=$2
+PYTHON=python3
+set dummy python3 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
 if ${ac_cv_path_PYTHON+:} false; then :
Index: VirtualBox-6.1.34/src/VBox/Installer/linux/rpm/VirtualBox.tmpl.spec
===================================================================
--- VirtualBox-6.1.34.orig/src/VBox/Installer/linux/rpm/VirtualBox.tmpl.spec
+++ VirtualBox-6.1.34/src/VBox/Installer/linux/rpm/VirtualBox.tmpl.spec
@@ -22,6 +22,9 @@
 %define VBOXDOCDIR %{_defaultdocdir}/%NAME%
 %global __requires_exclude_from ^/usr/lib/virtualbox/VBoxPython.*$|^/usr/lib/python.*$|^.*\\.py$
 %{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}
+# SUSE defines these in python-rpm-macros, not necessarily available here
+%{!?__python3:%{_bindir}/python3}}
+%{!?python3_sitelib: %define python_sitelib python3 -c "import sysconfig as s; print(s.get_paths().get('purelib'))"}
 
 Summary:   Oracle VM VirtualBox
 Name:      %NAME%
Index: VirtualBox-6.1.34/src/libs/libxml2-2.9.4/libxml.spec.in
===================================================================
--- VirtualBox-6.1.34.orig/src/libs/libxml2-2.9.4/libxml.spec.in
+++ VirtualBox-6.1.34/src/libs/libxml2-2.9.4/libxml.spec.in
@@ -1,3 +1,4 @@
+%global with_python2 0
 %global with_python3 1
 
 Summary: Library providing XML and HTML support
@@ -8,7 +9,9 @@ License: MIT
 Group: Development/Libraries
 Source: ftp://xmlsoft.org/libxml2/libxml2-%{version}.tar.gz
 BuildRoot: %{_tmppath}/%{name}-%{version}-root
+%if 0%{?with_python2}
 BuildRequires: python-devel
+%endif
 %if 0%{?with_python3}
 BuildRequires: python3-devel
 %endif # with_python3
@@ -72,7 +75,6 @@ to read, modify and write XML and HTML f
 this includes parsing and validation even with complex DTDs, either
 at parse time or later once the document has been modified.
 
-%if 0%{?with_python3}
 %package python3
 Summary: Python 3 bindings for the libxml2 library
 Group: Development/Libraries
@@ -87,7 +89,6 @@ This library allows to manipulate XML fi
 to read, modify and write XML and HTML files. There is DTDs support
 this includes parsing and validation even with complex DTDs, either
 at parse time or later once the document has been modified.
-%endif # with_python3
 
 %prep
 %setup -q
@@ -99,11 +100,14 @@ make
 %install
 rm -fr %{buildroot}
 
+%if 0%{?with_python2}
+make clean
+%configure --with-python=python
 make install DESTDIR=%{buildroot}
-
+%endif # with_python2
 %if 0%{?with_python3}
 make clean
-%configure --with-python=%{__python3}
+%configure --with-python=python3
 make install DESTDIR=%{buildroot}
 %endif # with_python3
 
@@ -165,6 +169,7 @@ rm -fr %{buildroot}
 
 %{_libdir}/*a
 
+%if 0%{?with_python2}
 %files python
 %defattr(-, root, root)
 
@@ -176,6 +181,7 @@ rm -fr %{buildroot}
 %doc python/tests/*.py
 %doc doc/*.py
 %doc doc/python.html
+%endif
 
 %if 0%{?with_python3}
 %files python3
Index: VirtualBox-6.1.34/src/libs/libxml2-2.9.4/libxml2.spec
===================================================================
--- VirtualBox-6.1.34.orig/src/libs/libxml2-2.9.4/libxml2.spec
+++ VirtualBox-6.1.34/src/libs/libxml2-2.9.4/libxml2.spec
@@ -103,7 +103,7 @@ make install DESTDIR=%{buildroot}
 
 %if 0%{?with_python3}
 make clean
-%configure --with-python=%{__python3}
+%configure --with-python=python3
 make install DESTDIR=%{buildroot}
 %endif # with_python3
 
Index: VirtualBox-6.1.34/src/libs/xpcom18a4/python/src/ErrorUtils.cpp
===================================================================
--- VirtualBox-6.1.34.orig/src/libs/xpcom18a4/python/src/ErrorUtils.cpp
+++ VirtualBox-6.1.34/src/libs/xpcom18a4/python/src/ErrorUtils.cpp
@@ -439,6 +439,8 @@ char *PyTraceback_AsString(PyObject *exc
 	{ // a temp scope so I can use temp locals.
 #if PY_MAJOR_VERSION <= 2
 	char *tempResult = PyString_AsString(obResult);
+#elif PY_MINOR_VERSION <= 6
+	char *tempResult = PyUnicode_AsUTF8(obResult);
 #else
     /* PyUnicode_AsUTF8() is const char * as of Python 3.7, char * earlier. */
 	const char *tempResult = (const char *)PyUnicode_AsUTF8(obResult);
Index: VirtualBox-6.1.34/src/libs/xpcom18a4/python/src/PyGBase.cpp
===================================================================
--- VirtualBox-6.1.34.orig/src/libs/xpcom18a4/python/src/PyGBase.cpp
+++ VirtualBox-6.1.34/src/libs/xpcom18a4/python/src/PyGBase.cpp
@@ -183,7 +183,11 @@ PyG_Base::~PyG_Base()
 // Get the correct interface pointer for this object given the IID.
 void *PyG_Base::ThisAsIID( const nsIID &iid )
 {
-	if (this==NULL) return NULL;
+#if PY_MINOR_VERSION <= 6
+	if (!this) return NULL;
+#else
+	if (!this) return NULL;
+#endif
 	if (iid.Equals(NS_GET_IID(nsISupports)))
 		return (nsISupports *)(nsIInternalPython *)this;
 	if (iid.Equals(NS_GET_IID(nsISupportsWeakReference)))
Index: VirtualBox-6.1.34/src/libs/xpcom18a4/python/gen_python_deps.py
===================================================================
--- VirtualBox-6.1.34.orig/src/libs/xpcom18a4/python/gen_python_deps.py
+++ VirtualBox-6.1.34/src/libs/xpcom18a4/python/gen_python_deps.py
@@ -86,7 +86,7 @@ def main(argv):
     else:
         multi = 1
 
-    if multi == 0:
+    if not multi:
         prefixes = ["/usr"]
         versions = [str(sys.version_info[0])+'.'+str(sys.version_info[1]),
                     str(sys.version_info[0])+'.'+str(sys.version_info[1])+'m']
@@ -114,24 +114,25 @@ def main(argv):
             continue
         for p in prefixes:
             c = checkPair(p, v, dllpre, dllsuff, bitness_magic)
-            if c is not None:
+            if c:
                 known[v] = c
                 break
-    keys = list(known.keys())
-    # we want default to be the lowest versioned Python
-    keys.sort()
-    d = None
     # We need separator other than newline, to sneak through $(shell)
     sep = "|"
-    for k in keys:
-        if d is None:
-            d = k
-        vers = k.replace('.', '').upper()
-        print_vars(vers, known[k], sep, bitness_magic)
-    if d is not None:
-        print_vars("DEF", known[d], sep, bitness_magic)
+
+    if not known:
+        # this type of problem should be detected in configure
+        # print_vars("DEF", defaultpaths, sep, bitness_magic)
+        pass
     else:
         print(argv[0] + ": No Python development package found!", file=sys.stderr)
+    if multi:
+        for ver, paths in known.items():
+            print_vars(ver.replace('.', '').upper(), paths, sep, bitness_magic)
+    else:
+        ver = versions[0]
+        paths = known[ver]
+        print_vars(ver.replace('.', ''), paths, sep, bitness_magic)
 
 if __name__ == '__main__':
     main(sys.argv)
openSUSE Build Service is sponsored by