Bug 397154 - Cannot build kcoreadons 5.49 with Python bindings
Summary: Cannot build kcoreadons 5.49 with Python bindings
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kcoreaddons
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Michael Pyne
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-04 15:38 UTC by Pawel
Modified: 2018-08-25 02:14 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
build log (1.25 MB, text/x-log)
2018-08-08 09:03 UTC, Pawel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel 2018-08-04 15:38:24 UTC
I cannot build kcoreaddons from GIT version 5.49rc1.
Bug:
[code]make[2]: *** [src/lib/CMakeFiles/Py2KF5KCoreAddons.dir/build.make:71: src/lib/CMakeFiles/Py2KF5KCoreAddons.dir/pybuild/PyKF5/KCoreAddons/unifiedKCoreAddons.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:4238: src/lib/CMakeFiles/Py2KF5KCoreAddons.dir/all] Error 2
make: *** [Makefile:130: all] Error 2[/code]
What's wrong?
Comment 1 Christoph Feck 2018-08-05 02:49:08 UTC
Could you please give a link with the complete output from cmake and make?

On out CI, kcoreaddons builds fine, see e.g. https://build.kde.org/view/Frameworks/job/Frameworks%20kcoreaddons%20kf5-qt5%20SUSEQt5.9/45/consoleFull
Comment 2 Pawel 2018-08-05 06:26:48 UTC
There are:
PKGBUILD for kcoreaddons: https://pastebin.com/0CfUi03W
Log from build: https://bpaste.net/show/1952f16b1ca1
Of course it's build with extra-cmake-modules 5.49rc1.
And maybe some other useful information:
Qt5 -5.11.1
python-pyqt5 - 5.11.2-2 (rebuild after python 3.7)
Maybe it's something related to python 3.7 in my system.
Comment 3 Christoph Feck 2018-08-05 12:35:20 UTC
First error is:

kcoreaddons/src/build/src/lib/pybuild/PyKF5/KCoreAddons/sipKCoreAddonsKFormat.cpp:197:46: error: 'AutoAdjust' is not a member of 'KFormat'
          ::KFormat::UnitPrefix a3 = KFormat::AutoAdjust;

Probably needs to read 'KFormat::UnitPrefix::AutoAdjust', since it's an 'enum class'.
Comment 4 Stefan Brüns 2018-08-05 12:52:19 UTC
(In reply to Christoph Feck from comment #1)
> Could you please give a link with the complete output from cmake and make?
> 
> On out CI, kcoreaddons builds fine, see e.g.
> https://build.kde.org/view/Frameworks/job/Frameworks%20kcoreaddons%20kf5-
> qt5%20SUSEQt5.9/45/consoleFull

09:49:54 -- The following OPTIONAL packages have not been found:
09:49:54 ...
09:49:54  * PythonModuleGeneration
Comment 5 Stefan Brüns 2018-08-05 13:18:00 UTC
(In reply to Christoph Feck from comment #3)
> First error is:
> 
> kcoreaddons/src/build/src/lib/pybuild/PyKF5/KCoreAddons/
> sipKCoreAddonsKFormat.cpp:197:46: error: 'AutoAdjust' is not a member of
> 'KFormat'
>           ::KFormat::UnitPrefix a3 = KFormat::AutoAdjust;
> 
> Probably needs to read 'KFormat::UnitPrefix::AutoAdjust', since it's an
> 'enum class'.

It definitely has to be 'KFormat::UnitPrefix::AutoAdjust'. This would be a bug in python-sip. According to http://pyqt.sourceforge.net/Docs/sip4/using.html#wrapping-enums, scoped enums should be supoorted. Make sure you have a current python-sip.
Comment 6 Pawel 2018-08-05 13:28:23 UTC
My sip version: https://www.archlinux.org/packages/testing/x86_64/sip/
Comment 7 Pawel 2018-08-08 09:03:51 UTC
Created attachment 114370 [details]
build log

Sorry - it's log from build once again (bpaste isn't available)
Comment 8 Pawel 2018-08-12 08:29:03 UTC
For sure bug is related to python-pyqt5 (see: https://www.archlinux.org/packages/extra/x86_64/python-pyqt5/) and with PythonModuleGeneration optional dependency of kcoreaddons. I cannot build kcoreaddons (now 5.49) with this optional dependency and it builds without it well.
Comment 9 Michael Pyne 2018-08-12 09:26:22 UTC
Thanks for confirming the relation to pyqt5. The Python module generation feature has never worked on my system so I can't reproduce this myself.

As things stand I'm still not sure if this is a bug in sip (though your version of sip should be sufficient for C++ class enum), a bug in kcoreaddons, or some other part of the toolchain (e.g. extra-cmake-module's FindPythonModuleGeneration module).
Comment 10 Pawel 2018-08-12 12:27:52 UTC
Maybe some historic (and not only) informations will be helpful.
I built kcoreaddons 5.48rc myself on python-pyqt5 ver. 5.11.2; after that, python-pyqt5 was rebuild against of python 3.7. So in Arch we have python 3.7 and python-pyqt5 5.11.2 rebuild on it now.
Today I try to build kcoreaddons 5.48 against of python-pyqt5 5.11.2 (and python 3.7 and of course with PythonModuleGeneration optional dependency) and I can build it without any errors. I use ECM 5.49 (becouse of my fault).
I cannot build kcoreaddons 5.49 against of those same packages (version of them) of python, python-pyqt5 and sip/python-sip, so maybe it's related to one commit in kcoreaddons between 5.48 and 5.49.
Comment 11 Pawel 2018-08-12 14:18:20 UTC
And more... I cannot build kcoreaddons with any patch starts from this commit: https://cgit.kde.org/kcoreaddons.git/commit/?id=cfd7b30ef6c22d71c5931a920ffbabb818327988
Comment 12 Melanie Genz 2018-08-13 16:31:46 UTC
I ran into the same problem with the same error messages.
I use Python 3.6.6 pyqt5 5.11.2 and sip 4.19.12
Comment 13 Melanie Genz 2018-08-14 10:51:02 UTC
I Managed to build kcoreaddons 5.49.0 with python bindings using this small patch.

diff -Naur kcoreaddons-5.49.0.orig/src/lib/util/kformat.h kcoreaddons-5.49.0/src/lib/util/kformat.h
--- kcoreaddons-5.49.0.orig/src/lib/util/kformat.h	2018-08-04 12:56:42.000000000 +0200
+++ kcoreaddons-5.49.0/src/lib/util/kformat.h	2018-08-14 12:35:57.224626936 +0200
@@ -116,7 +116,7 @@
      * @see formatValue
      * @since 5.49
      */
-    enum class Unit {
+    enum Unit {
         Other,
         Bit,   ///< "bit"
         Byte,  ///< "B"
@@ -135,7 +135,7 @@
      * @see formatValue
      * @since 5.49
      */
-    enum class UnitPrefix {
+    enum UnitPrefix {
         /// Auto-choose a unit such that the result is in the range [0, 1000 or 1024)
         AutoAdjust = -128,
 
--------------

Seems like sip doesn't detects that enum class in that code is at least c++11 standard.

I must admit that idon't know if it is a good idea to change enum classes to standard enums.
Comment 14 Michael Pyne 2018-08-14 10:57:40 UTC
I'm not a fan of changing the enum classes if we can avoid it, since that may have impact on C++-using code.

I have an Ubuntu-based container where the build also completes successfully so I don't think is a matter of impossibility with latest sip/PyQt5.

Regardless I've come up with a patch to make the bindings optional for now, and maybe that's the least-worst solution to at least getting things to build for those who don't need the bindings.

You'd need to pass the -DGENERATE_PYTHON_MODULES=OFF option when running cmake since the option defaults to being set.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5bd07ed..b860afd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,6 +27,9 @@ include(KDECMakeSettings)
 option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF)
 add_feature_info(QCH ${BUILD_QCH} "API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)")

+option(GENERATE_PYTHON_MODULES "Build Python bindings for KCoreAddons libraries, if needed dependencies are available" ON)
+add_feature_info(PYTHON_BINDING ${GENERATE_PYTHON_MODULES} "Generates Python bindings for KCoreAddons libraries, if needed dependencies are available")
+
 set(REQUIRED_QT_VERSION 5.8.0)
 find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core)

diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 573d6e3..8f0ff3a 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -205,7 +205,9 @@ ecm_generate_headers(KCoreAddons_HEADERS
     REQUIRED_HEADERS KCoreAddons_HEADERS
 )

-find_package(PythonModuleGeneration)
+if (GENERATE_PYTHON_MODULES)
+    find_package(PythonModuleGeneration)
+endif ()

 if (PythonModuleGeneration_FOUND)
   ecm_generate_python_binding(
Comment 15 Michael Pyne 2018-08-14 10:57:58 UTC
Marking as confirmed based on multiple confirmation reports.
Comment 16 Michael Pyne 2018-08-14 11:57:16 UTC
Need to clarify my earlier comment. I have sip/PyQt5 on an Ubuntu image but it's not setup properly so the GeneratePythonModule CMake find-module isn't trying to generate bindings. So I can't actually confirm that it works personally.
Comment 17 Melanie Genz 2018-08-14 12:43:31 UTC
I've compile the whole kf5 5.49.0 stack now including python bindings and everything seems to be working without problems.
Comment 18 Stefan Brüns 2018-08-14 18:36:20 UTC
(In reply to Melanie Genz from comment #13)
> I Managed to build kcoreaddons 5.49.0 with python bindings using this small
> patch.
> 
> diff -Naur kcoreaddons-5.49.0.orig/src/lib/util/kformat.h
> kcoreaddons-5.49.0/src/lib/util/kformat.h
> --- kcoreaddons-5.49.0.orig/src/lib/util/kformat.h	2018-08-04
> 12:56:42.000000000 +0200
> +++ kcoreaddons-5.49.0/src/lib/util/kformat.h	2018-08-14 12:35:57.224626936
> +0200
> @@ -116,7 +116,7 @@
>       * @see formatValue
>       * @since 5.49
>       */
> -    enum class Unit {
> +    enum Unit {

Thats a BIC, so definitely no solution.
Comment 19 Stefan Brüns 2018-08-15 00:05:06 UTC
Ok, its a genuine KDE bug, the SIP generator does not handle enum class specifically:

https://cgit.kde.org/extra-cmake-modules.git/tree/find-modules/sip_generator.py#n419
Comment 20 Stefan Brüns 2018-08-17 22:11:28 UTC
(In reply to Stefan Brüns from comment #19)
> Ok, its a genuine KDE bug, the SIP generator does not handle enum class
> specifically:
> 
> https://cgit.kde.org/extra-cmake-modules.git/tree/find-modules/sip_generator.
> py#n419

https://phabricator.kde.org/D14908
Comment 21 Melanie Genz 2018-08-18 00:24:14 UTC
Thank you. Will look into that and try it out tomorrow.
Comment 22 Pawel 2018-08-22 18:44:06 UTC
(In reply to Stefan Brüns from comment #20)
> https://phabricator.kde.org/D14908

It looks like kcoreaddons can be build when ECM was built with this patch.
Comment 23 Stefan Brüns 2018-08-25 02:14:56 UTC
Git commit 1790a6994a3536a9d6c73901cb7898615eb64861 by Stefan Brüns.
Committed on 25/08/2018 at 02:14.
Pushed by bruns into branch 'master'.

Bindings: Add support for scoped enums

Summary:
Keep the enum intact by emitting the class keyword in case the enum is
scoped.
Use the complete enum scope for parameter values, the enclosing scope is
only correct to use for unscoped enums.
The python Cursor.is_scoped_enum() method has been added with LLVM/Clang
version 5.0.

Test Plan: build kcoreaddons

Reviewers: #frameworks, mpyne

Reviewed By: mpyne

Subscribers: mpyne, kde-frameworks-devel, kde-buildsystem

Tags: #frameworks, #build_system

Differential Revision: https://phabricator.kde.org/D14908

M  +2    -8    find-modules/FindPythonModuleGeneration.cmake
M  +8    -2    find-modules/sip_generator.py

https://commits.kde.org/extra-cmake-modules/1790a6994a3536a9d6c73901cb7898615eb64861