Bug 374801 - Python bindings build fails
Summary: Python bindings build fails
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kguiaddons
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Stephen Kelly
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-09 10:57 UTC by Antonio Rojas
Modified: 2017-01-16 21:15 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
kfontutils.sip (1.12 KB, text/x-csrc)
2017-01-09 19:12 UTC, Antonio Rojas
Details
More debug output (4.40 KB, patch)
2017-01-09 20:06 UTC, Stephen Kelly
Details
cpplib.sip (3.97 KB, text/x-csrc)
2017-01-09 20:29 UTC, Antonio Rojas
Details
kguiaddons debug output (2.78 KB, patch)
2017-01-09 20:39 UTC, Stephen Kelly
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Antonio Rojas 2017-01-09 10:57:36 UTC
Python bindings don't build in 5.30

[ 59%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/util/kiconutils.cpp.o
sip: /build/kguiaddons/src/build/src/sip/PyKF5/KGuiAddons/kfontutils.sip:14: Compulsory argument given after optional argument
make[2]: *** [src/CMakeFiles/sip_generated_KGuiAddons_files.dir/build.make:65: src/pybuild/PyKF5/KGuiAddons/unifiedKGuiAddons.cpp] Error 1
make[1]: *** [CMakeFiles/Makefile2:203: src/CMakeFiles/sip_generated_KGuiAddons_files.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
Comment 1 Stephen Kelly 2017-01-09 19:08:16 UTC
Thanks for trying this.

Can you please post the /build/kguiaddons/src/build/src/sip/PyKF5/KGuiAddons/kfontutils.sip file and indicate line 14?
Comment 2 Antonio Rojas 2017-01-09 19:12:03 UTC
Created attachment 103312 [details]
kfontutils.sip

line 14 is:
    qreal adaptFontSize(QPainter & painter, const QString & text, double width, double height, double maxFontSize = 28.0, double minFontSize = 1.0, QFlags<KFontUtils::AdaptFontSizeOption> flags);
Comment 3 Stephen Kelly 2017-01-09 20:06:31 UTC
Created attachment 103313 [details]
More debug output

Please apply the attached patch to your extra-cmake-modules and run

 cd build
 rm -rf tests/GenerateSipBindings/
 ctest -R Sip

and send the full output along with the file

extra-cmake-modules/build/tests/GenerateSipBindings/sip/PyTest/CppLib/cpplib.sip
Comment 4 Antonio Rojas 2017-01-09 20:29:16 UTC
Created attachment 103314 [details]
cpplib.sip

> ctest -R Sip
Test project /home/antonio/Software/test/extra-cmake-modules/src/build
    Start 1: GenerateSipBindings
1/1 Test #1: GenerateSipBindings ..............   Passed    6.80 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   6.80 sec
Comment 5 Stephen Kelly 2017-01-09 20:39:01 UTC
Created attachment 103315 [details]
kguiaddons debug output

Strange. 

Please now add this patch to ECM, and run the build of kguiaddons and paste the output.
Comment 6 Antonio Rojas 2017-01-09 21:07:26 UTC
Scanning dependencies of target generate_KGuiAddons_sip_files
[  1%] Generating sip/PyKF5/KGuiAddons/kcolorutils.sip
[  3%] Generating sip/PyKF5/KGuiAddons/kcolorcollection.sip
[  5%] Generating sip/PyKF5/KGuiAddons/kcolormimedata.sip
[  7%] Generating sip/PyKF5/KGuiAddons/kdatevalidator.sip
[  8%] Generating sip/PyKF5/KGuiAddons/kwordwrap.sip
[ 10%] Generating sip/PyKF5/KGuiAddons/kfontutils.sip


Processing parameters of adaptFontSize
member -- class QPainter -- False


Processing parameters of adaptFontSize
member -- class QString -- False


Processing parameters of adaptFontSize
member -- qreal -- False


Processing parameters of adaptFontSize
member -- qreal -- False


Processing parameters of adaptFontSize
member -- qreal -- False
member --  -- True
<SourceRange start <SourceLocation file '/home/antonio/Software/test/kguiaddons/trunk/src/kguiaddons-5.30.0/src/fonts/kfontutils.h', line 64, column 39>, end <SourceLocation file '/home/antonio/Software/test/kguiaddons/trunk/src/kguiaddons-5.30.0/src/fonts/kfontutils.h', line 66, column 76>>
qreal
maxFontSize
=
28.0
,
Tokens done 28.0




Processing parameters of adaptFontSize
member -- qreal -- False
member --  -- True
<SourceRange start <SourceLocation file '/home/antonio/Software/test/kguiaddons/trunk/src/kguiaddons-5.30.0/src/fonts/kfontutils.h', line 65, column 39>, end <SourceLocation file '/home/antonio/Software/test/kguiaddons/trunk/src/kguiaddons-5.30.0/src/fonts/kfontutils.h', line 66, column 76>>
qreal
minFontSize
=
1.0
,
Tokens done 1.0




Processing parameters of adaptFontSize
member -- AdaptFontSizeOptions -- False


Processing parameters of adaptFontSize
member -- class QPainter -- False


Processing parameters of adaptFontSize
member -- class QString -- False


Processing parameters of adaptFontSize
member -- class QSizeF -- False


Processing parameters of adaptFontSize
member -- qreal -- False
member --  -- True
<SourceRange start <SourceLocation file '/home/antonio/Software/test/kguiaddons/trunk/src/kguiaddons-5.30.0/src/fonts/kfontutils.h', line 74, column 39>, end <SourceLocation file '/home/antonio/Software/test/kguiaddons/trunk/src/kguiaddons-5.30.0/src/fonts/kfontutils.h', line 76, column 76>>
qreal
maxFontSize
=
28.0
,
Tokens done 28.0




Processing parameters of adaptFontSize
member -- qreal -- False
member --  -- True
<SourceRange start <SourceLocation file '/home/antonio/Software/test/kguiaddons/trunk/src/kguiaddons-5.30.0/src/fonts/kfontutils.h', line 75, column 39>, end <SourceLocation file '/home/antonio/Software/test/kguiaddons/trunk/src/kguiaddons-5.30.0/src/fonts/kfontutils.h', line 76, column 76>>
qreal
minFontSize
=
1.0
,
Tokens done 1.0




Processing parameters of adaptFontSize
member -- AdaptFontSizeOptions -- False
[ 12%] Generating sip/PyKF5/KGuiAddons/kiconutils.sip
[ 14%] Generating sip/PyKF5/KGuiAddons/kimagecache.sip
[ 16%] Generating sip/PyKF5/KGuiAddons/kmodifierkeyinfo.sip
[ 16%] Built target generate_KGuiAddons_sip_files
Scanning dependencies of target KF5GuiAddons_automoc
[ 17%] Automatic moc for target KF5GuiAddons
Generating moc source klocalimagecacheimpl.moc
Generating moc source moc_kmodifierkeyinfoprovider_p.cpp
Generating moc source urlhandler.moc
Generating moc source KF5GuiAddons_automoc.dir/moc_kmodifierkeyin_CUUWWTTZTG7BRK.cpp
Generating moc compilation KF5GuiAddons_automoc.cpp
[ 17%] Built target KF5GuiAddons_automoc
Scanning dependencies of target KF5GuiAddons
[ 19%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/colors/kcolorspaces.cpp.o
[ 21%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/colors/kcolorutils.cpp.o
[ 23%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/colors/kcolorcollection.cpp.o
[ 25%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/colors/kcolormimedata.cpp.o
[ 26%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/text/kdatevalidator.cpp.o
[ 28%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/text/kwordwrap.cpp.o
[ 30%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/fonts/kfontutils.cpp.o
[ 32%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/util/kiconutils.cpp.o
[ 33%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/util/klocalimagecacheimpl.cpp.o
[ 35%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/util/kmodifierkeyinfo.cpp.o
[ 37%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/util/kmodifierkeyinfoprovider.cpp.o
[ 39%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/util/urlhandler.cpp.o
[ 41%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/util/kmodifierkeyinfoprovider_x11.cpp.o
[ 42%] Building CXX object src/CMakeFiles/KF5GuiAddons.dir/KF5GuiAddons_automoc.cpp.o
[ 44%] Linking CXX shared library libKF5GuiAddons.so
[ 44%] Built target KF5GuiAddons
Scanning dependencies of target sip_generated_KGuiAddons_files
[ 46%] Generating pybuild/PyKF5/KGuiAddons/unifiedKGuiAddons.cpp
sip: /home/antonio/Software/test/kguiaddons/trunk/src/build/src/sip/PyKF5/KGuiAddons/kfontutils.sip:14: Compulsory argument given after optional argument
make[2]: *** [src/CMakeFiles/sip_generated_KGuiAddons_files.dir/build.make:65: src/pybuild/PyKF5/KGuiAddons/unifiedKGuiAddons.cpp] Error 1
make[1]: *** [CMakeFiles/Makefile2:203: src/CMakeFiles/sip_generated_KGuiAddons_files.dir/all] Error 2
make: *** [Makefile:139: all] Error 2
Comment 7 Stephen Kelly 2017-01-09 21:34:51 UTC
I don't understand and I can't reproduce this. We have a test in extra-cmake-modules that works for you and has almost the same thing as this kguiaddons header.

What libclang version do you have? 

I think because you can reproduce it, you will have to take it further. For example, run 'make -j1 VERBOSE=1' to capture the full command line that attempts to generate kfontutils.sip. That is for convenience so that you can easily rerun the command.

Then take things out of kfontutils.h and run the command until you find the problem. Eg, remove the EXPORT macros and see if that makes a difference, rename things to the names they have in the ecm test, remove additional function parameters etc.
Comment 8 Antonio Rojas 2017-01-10 22:33:59 UTC
OK, got it. The difference is that in the ECM test the sip_generator.py command line contains "-std=gnu++14" in --flags, but in the kguiaddons build it doesn't. Running the sip_generator line manually and adding "-std=gnu++14" to --flags generates a correct sip file for kguiaddons.
Comment 9 Stephen Kelly 2017-01-11 09:27:15 UTC
Superb, thanks for reducing it to that. Now let's see if we can get a reduced testcase showing it is an upstream bug somehow.

Please create a file called clang-param-test.h containing

 enum MyFlagType {
     EnumValueOne = 0x01,
     EnumValueTwo = 0x02
 };

 void useEnum(int foo = 100, uint flags = EnumValueOne);

and a clang-param-test.py containing

 #!/usr/bin/env python

 from __future__ import print_function

 import sys

 from clang import cindex
 from clang.cindex import CursorKind, SourceRange

 my_clang_library = "/usr/lib/x86_64-linux-gnu/libclang-3.8.so"

 my_source = "clang-param-test.h"

 if (len(sys.argv) > 1 and sys.argv[1] == "use14"):
     cxx_standard_flag = ["-std=gnu++14"]
     print("using", cxx_standard_flag)
 else:
     print("using default flag")
     cxx_standard_flag = []

 cindex.Config.set_library_file(my_clang_library)

 index = cindex.Index.create() 
 tu = index.parse(my_source, ["-x", "c++"] + cxx_standard_flag)

 for member in tu.cursor.get_children():
     if (member.spelling == "useEnum"):
         for child in member.get_children():
             if child.kind == CursorKind.PARM_DECL:
                 for parameter in child.get_children():
                     if parameter.kind.is_expression():
                         possible_extent = SourceRange.from_locations(parameter.extent.start, member.extent.end)
                         print(possible_extent)


and then run 

 python2 clang-param-test.py
 python2 clang-param-test.py use14

I guess you will get different output for each time you run it. I get the same output.

Please also say your python version and libclang version.
Comment 10 Stephen Kelly 2017-01-11 19:30:11 UTC
Here's an updated version of those two files:

    #!/usr/bin/env python

    from __future__ import print_function

    import sys

    from clang import cindex
    from clang.cindex import CursorKind, SourceRange

    my_clang_library = "/usr/lib/x86_64-linux-gnu/libclang-3.8.so"

    my_source = "clang-param-test.h"

    if (len(sys.argv) > 1 and sys.argv[1] == "use14"):
        cxx_standard_flag = ["-std=gnu++14"]
        print("using", cxx_standard_flag)
    else:
        print("using default flag")
        cxx_standard_flag = []

    cindex.Config.set_library_file(my_clang_library)

    index = cindex.Index.create()
    tu = index.parse(my_source, ["-x", "c++"] + cxx_standard_flag)

    for member in tu.cursor.get_children():
        if (member.spelling.startswith("useEnum")):
            for child in member.get_children():
                if child.kind == CursorKind.PARM_DECL:
                    for parameter in child.get_children():
                        if parameter.kind.is_expression():
                            possible_extent = SourceRange.from_locations(parameter.extent.start, member.extent.end)
                            print(possible_extent)


And the cpp file:


    enum MyFlagType {
        EnumValueOne = 0x01,
        EnumValueTwo = 0x02
    };

    template<typename Enum>
    class FlagsType
    {
    public:
        FlagsType(Enum e) : m_e(e) {}

        operator int() { return m_e; }

    private:
        Enum m_e;

    };

    void useEnum(int foo = 100, FlagsType<MyFlagType> flags = EnumValueOne);

    void useEnum2(int foo = 100, FlagsType<MyFlagType> flags = EnumValueOne);
Comment 11 Stephen Kelly 2017-01-11 19:31:03 UTC
Damn, useEnum should use uint instead of the flags type like this:


    void useEnum(int foo = 100, uint flags = EnumValueOne);
Comment 12 Antonio Rojas 2017-01-11 19:56:23 UTC
I get identical output with or without use14 (besides the 'using...' line)

clang is 3.9.1, python 2.7.13
Comment 13 Stephen Kelly 2017-01-11 21:08:08 UTC
Git commit 8aa6843404f9c6faef66cb9c76358158eafc1af1 by Stephen Kelly.
Committed on 11/01/2017 at 21:07.
Pushed by skelly into branch 'master'.

Explicitly pass -std=gnu++14 to clang when generating bindings

The generator expression here looks like it should work, but it does not
set the appropriate flags for compilation.  It seems that the
CXX_STANDARD property is not yet populated at the time the generator
expression is evaluated (to be investigated later).

This came to light because users of Qt 5.7+ attempted to generate the
bindings, but they encountered errors.  The step of using libclang to
parse the provided headers was actually failing, but that was not
noticed, perhaps because the logging infrastructure in sip_generator
does not emit it (to investigate later).

M  +5    -3    find-modules/FindPythonModuleGeneration.cmake

https://commits.kde.org/extra-cmake-modules/8aa6843404f9c6faef66cb9c76358158eafc1af1
Comment 14 Stephen Kelly 2017-01-11 21:30:55 UTC
Git commit ed1b9ce2bb2a2e51410e0a1754a72c110010a6a0 by Stephen Kelly.
Committed on 11/01/2017 at 21:27.
Pushed by skelly into branch 'master'.

Bindings: Fix logging output severity for parsing messages

The Python logging module uses logging severities with numerical values
which form a sequence in steps of 10.  The Clang cindex.Diagnostic
numerical values use a step size of 1, so the two are incompatible.

Introduce a mapping function so that appropriate errors get issued when
attempting to build the bindings.  The logging module has one surplus
diagnostic level, but we simply never use it.

M  +29   -1    find-modules/sip_generator.py

https://commits.kde.org/extra-cmake-modules/ed1b9ce2bb2a2e51410e0a1754a72c110010a6a0