Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more developer docs #1089

Closed
wants to merge 3 commits into from
Closed

add more developer docs #1089

wants to merge 3 commits into from

Conversation

sssoleileraaa
Copy link
Contributor

@sssoleileraaa sssoleileraaa commented May 8, 2020

Description

Towards #273
Closes #1084

Add more instructions on how to debug and develop the client.

@kushaldas
Copy link
Contributor

kushaldas commented May 11, 2020

The steps I followed:

I have the following deb lines in the sources.lsit

deb-src https://deb.debian.org/debian/ buster-updates main contrib non-free
deb http://deb.debian.org/debian-debug/ stable-debug main
# for security updates
deb http://deb.debian.org/debian-debug/ buster-proposed-updates-debug main

Then installed the following packages:

apt install libc6-dbg libpython3-all-dbg libpython3-dbg libpython3.7-dbg libqt5dbus5-dbgsym libqt5gui5-dbgsym python3-dbg python3-pyqt5-dbg python3-pyqt5.sip-dbg python3-sip-dbg python3.7-dbg valgrind-dbg

With these I can see debug symbols in the backstrace. Example:

(gdb) bt
#0  0x00007f755ef38819 in __GI___poll (fds=0x25ae230, nfds=6, timeout=14056) at ../sysdeps/unix/sysv/linux/poll.c:29
#1  0x00007f755c99a136 in  () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#2  0x00007f755c99a25c in g_main_context_iteration () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#3  0x00007f755d5c8727 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /lib/x86_64-linux-gnu/libQt5Core.so.5
#4  0x00007f7559d01401 in QPAEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (this=0x22c4a90, flags=...) at qeventdispatcher_glib.cpp:69
#5  0x00007f755d57615b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /lib/x86_64-linux-gnu/libQt5Core.so.5
#6  0x00007f755e0dcedd in QDialog::exec() () at /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#7  0x00007f755e7acd20 in meth_QDialog_exec_(PyObject*, PyObject*) (sipSelf=<optimized out>, sipArgs=()) at ./sip/QtWidgets/qdialog.sip:57
#8  0x00000000005d6fb2 in _PyMethodDef_RawFastCallKeywords
    (method=<optimized out>, self=<WhiteWindow at remote 0x7f7559df74c8>, args=0x1f26740, nargs=<optimized out>, kwnames=<optimized out>) at ../Objects/call.c:694
#9  0x000000000054aac0 in _PyCFunction_FastCallKeywords
    (kwnames=<optimized out>, nargs=<optimized out>, args=0x1f26740, func=<built-in method exec_ of WhiteWindow object at remote 0x7f7559df74c8>) at ../Objects/call.c:730
#10 0x000000000054aac0 in call_function (pp_stack=0x7ffc6fadaa40, oparg=<optimized out>, kwnames=<optimized out>) at ../Python/ceval.c:4568
#11 0x0000000000551bf9 in _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3093
#12 0x000000000054b452 in PyEval_EvalFrameEx
    (throwflag=0, f=Frame 0x1f26578, for file localapp.py, line 39, in __init__ (self=<WhiteWindow at remote 0x7f7559df74c8>, textbox=<QTextEdit at remote 0x7f7559df7558>, ok_button=<QPushButton at remote 0x7f7559df75e8>, c_button=<QPushButton at remote 0x7f7559df7678>, button_hboxlayout=<QHBoxLayout at remote 0x7f7559df7708>, b=<QWidget at remote 0x7f7559df7798>, group_vboxlayout=<QVBoxLayout at remote 0x7f7559df7828>, groupbox=<QGroupBox at remote 0x7f7559df78b8>, big_layout=<QVBoxLayout at remote 0x7f7559df7948>)) at ../Python/ceval.c:547
#13 0x000000000054b452 in _PyEval_EvalCodeWithName

The command used:

gdb -c core.11177 --args python3 localapp.py

While creating a virtualenv for securedrop-client we will have to use --site-packages and do not install PyQt5 via wheel there.

@sssoleileraaa sssoleileraaa force-pushed the developer-docs-2 branch 2 times, most recently from eca632b to dfaabb4 Compare May 20, 2020 16:51
Copy link
Contributor

@kushaldas kushaldas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have to free up more space and try this again.

README.md Outdated
Sometimes there is a bug in Qt rather than the client, so it helps to install [a debug version of PyQt5](#build-and-install-a-debug-version-of-pyqt5) which will allow you to see Qt debug symbols in your Python tracebacks. You can use `gdb` to view a traceback as well as a core file, if you're debugging a segfault, but first you must need to install the following some additional packages in order for `gdb` to work with Python programs.

```
sudo apt install libc6-dbg libpython3-all-dbg libpython3-dbg libpython3.7-dbg python3-dbg python3.7-dbg valgrind-dbg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add the other dependency installation steps here. In my fresh Debian Qt refused to build due to missing dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list includes the dependencies for gdb to work with Python programs. It sounds like you had issues during the next step to clone the Qt repo and build it from source following https://wiki.qt.io/Building_Qt_5_from_Git#Getting_the_source_code, which defaults to creating a 'debug' build and installs the binaries in the current directory:

git clone https://code.qt.io/qt/qt5.git
cd qt5
git checkout v5.14.2                                # or checkout a different version
git submodule update --init --recursive
export LLVM_INSTALL_DIR=/usr/llvm
mkdir ../qt5-build && cd ../qt5-build               # we don't want to build in the source code directory
../qt5/configure -developer-build -opensource -nomake examples -nomake tests -confirm-license
make -j 4

Could you paste the output of the error you're seeing? And just to make sure you followed the instructions from https://wiki.qt.io/Building_Qt_5_from_Git#Getting_the_source_code and the steps I pasted above?


### Build and install a debug version of PyQt5

1. Build a debug version of Qt 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add a line about required free space for a debug build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call.. my qt5-build directory is 1.9 GB, is that what you're seeing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am seeing significantly more than that:

user@dev-python:~$ du -sh qt5*
6.7G	qt5
5.2G	qt5-build

@eloquence
Copy link
Member

eloquence commented Jul 23, 2020

@emkll has committed to taking a spin through these docs as part of the 7/23-8/5 sprint.

Copy link
Contributor

@emkll emkll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @creviera the docs are very clear, added a couple of comments/suggestions inline.

I have successfully managed to build both Qt and PyQt using these instructions. However ran into a runtime issue when attempting to run the client with the debug version of PyQT:

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/user/securedrop-client/securedrop_client/__main__.py", line 1, in <module>
    from .app import run
  File "/home/user/securedrop-client/securedrop_client/app.py", line 30, in <module>
    from PyQt5.QtCore import Qt, QTimer
RuntimeError: the sip module implements API v12.0 to v12.7 but the PyQt5.QtCore module requires API v12.8

After updating pyqt-sip to the latest version (12.8.0 from 4.19.19) I am getting the following when trying to run the client:

(.venv) user@dev-python:~/securedrop-client$ ./run.sh 
Running app with home directory: /tmp/tmp.VFkg6JHi5E

Detected QubesOS, enabling DispVMs for submission handling...
gpg: keybox '/tmp/tmp.VFkg6JHi5E/gpg/pubring.kbx' created
gpg: /tmp/tmp.VFkg6JHi5E/gpg/trustdb.gpg: trustdb created
gpg: key CC40EF1228271441: public key "SecureDrop Test/Development (DO NOT USE IN PRODUCTION)" imported
gpg: key CC40EF1228271441: secret key imported
gpg: Total number processed: 1
gpg:               imported: 1
gpg:       secret keys read: 1
gpg:   secret keys imported: 1
qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: linuxfb, minimal, offscreen, vnc.

./run.sh: line 64: 22075 Aborted                 python -m securedrop_client --sdc-home "$SDC_HOME" --no-proxy "$qubes_flag" "$@"

Looks like we missing a Qt platform plugin. Based on this thread [1], seems like there's a configure option to force building libxcb.so, so will try this next.

[1] : https://forum.qt.io/topic/115827/build-on-linux-qt-xcb-option/16

export LLVM_INSTALL_DIR=/usr/llvm
mkdir ../qt5-build && cd ../qt5-build # we don't want to build in the source code directory
../qt5/configure -developer-build -opensource -nomake examples -nomake tests -confirm-license
make -j 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step took ~1h on my computer, perhaps worth mentioning either here or elsewhere in the docs that this takes a while

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will also need to build qttools here for the PySide2.

make -j 4 module-qttools

README.md Outdated
Sometimes there is a bug in Qt rather than the client, so it helps to install [a debug version of PyQt5](#build-and-install-a-debug-version-of-pyqt5) which will allow you to see Qt debug symbols in your Python tracebacks. You can use `gdb` to view a traceback as well as a core file, if you're debugging a segfault, but first you must need to install the following some additional packages in order for `gdb` to work with Python programs.

```
sudo apt install libc6-dbg libpython3-all-dbg libpython3-dbg libpython3.7-dbg python3-dbg python3.7-dbg valgrind-dbg
Copy link
Contributor

@emkll emkll Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following additional packages were required (to get configure to not output ERROR on configuration):

sudo apt-get install libclang-dev '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev gperf bison flex libgl1-mesa-dev pkg-config libdbus-1-dev libnss3-dev libfontconfig1-dev libxi-dev libxcomposite-dev libxcursor-dev libxtst-dev

from: https://wiki.qt.io/Building_Qt_5_from_Git


### Build and install a debug version of PyQt5

1. Build a debug version of Qt 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am seeing significantly more than that:

user@dev-python:~$ du -sh qt5*
6.7G	qt5
5.2G	qt5-build

export PATH=~/qt/qt5-build/qtbase/bin:$PATH
export QT_PLUGIN_PATH=~/qt/qt5-build/qtbase/plugins
sip-install --debug --qmake ~/qt/qt5-build/qtbase/bin/qmake --confirm-license
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step took 15-20 minutes (17M of disk space used, which is probably negligible in context)

Copy link
Contributor

@emkll emkll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick update on some findings:
I tried again using the following flags at the configure step to have xcb plugin support with -xcb -xvb-xlib , but compilation fails in both cases at some point during the process without any helpful error. I have also attempted to specify system xcb support by using the -xcb -system-xcb configuration flags (per https://forum.qt.io/post/600712, states that distribution-provided xcb may be needed since it is no longer shipped with Qt ), but also resulting in a failed compilation.

It may be worth attempting on another platform to see if the xcb requirement is platform specific, but we will likely need this support to be able to debug PyQt in Qubes

README.md Outdated
tar -xzvf PyQt5-5.14.2.tar.gz
cd PyQt5-5.14.2
pip install PyQt-builder
export PATH=~/qt/qt5-build/qtbase/bin:$PATH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in https://github.com/freedomofpress/securedrop-client/pull/1089/files#diff-04c6e90faac2675aa89e2176d2eec7d8R349, the qt5-build folder is at the same level as the cloned repo qt5. Does this here refer to another folder inside the qt5 clone repository? if so, i don't see it myself.

@eloquence
Copy link
Member

Per discussion at backlog review we may want to remove

Closes #273

and keep that issue open as a tracking issue until we're running a version of Qt which has a bugfix for the upstream issue it references.

@sssoleileraaa
Copy link
Contributor Author

Switched wording to "towards" and added an update on #273

@eloquence
Copy link
Member

Very close but a bit more testing required, we've agreed we will pick this up again in a future sprint.

@emkll emkll marked this pull request as ready for review November 23, 2020 18:17
@emkll emkll requested a review from redshiftzero as a code owner November 23, 2020 18:17
@emkll
Copy link
Contributor

emkll commented Nov 23, 2020

This should now be ready for another review.

I've updated the documentation here to get a debug build of the version of PyQT we are targeting, but I am not quite sure what to do next. @kushaldas @creviera could you take a look an append one commit to explain how to validate the build and how to use the debug version in development context?

Note that the documentation was updated to build (Py)QT 5.11.3, the version that is being tracked in the requirements files as well as Debian Buster. Given the reliance on system libraries for the build, it may be very difficult to target other versions of Qt/PyQt without manually installing some libraries/headers/dependencies, like sip and others.

@emkll emkll removed the request for review from redshiftzero November 23, 2020 18:18
Update instructions for Qt 5.11.3
Matches version of python3-sip-dev in debian-10 (which includes headers required for pyqt build)
@sssoleileraaa
Copy link
Contributor Author

We may want to also add a "how to build pyqt wheel" section, see #1165 (comment)

@kushaldas
Copy link
Contributor

kushaldas commented Dec 9, 2020

The following is to build pyside2 for Qt 5.15.2

Setup CLANG

wget https://download.qt.io/development_releases/prebuilt/libclang/libclang-release_100-based-linux-Rhel7.6-gcc5.3-x86_64.7z
7z x libclang-release_100-based-linux-Rhel7.6-gcc5.3-x86_64.7z

export CLANG_INSTALL_DIR=$PWD/libclang
export LLVM_INSTALL_DIR=$PWD/libclang/

Get the source

git clone --recursive https://code.qt.io/pyside/pyside-setup
cd pyside-setup && git checkout 5.15.2
cd ..

Create the virtualenv

python -m venv pbuilder
source testenv/bin/activate
python3 -m pip install -r pyside-setup/requirements.txt

Modify path and build the wheel

Please modify the following variables properly to the correct path in your system. For my setup, everything is under /home/kdas.

cd pyside-setup
export PATH=/home/kdas/libclang/bin:$PATH
export PATH=/home/kdas/qt5-build/qtbase/bin/:$PATH
python3 setup.py build --qmake=/home/kdas/qt5-build/qtbase/bin/qmake --standalone --skip-docs --ignore-git --parallel=8 --verbose-build
python3 setup.py bdist_wheel --reuse-build --qmake=/home/kdas/qt5-build/qtbase/bin/qmake --standalone --skip-docs --ignore-git --parallel=8 --verbose-build

After this, you can find three wheels inside of the dist/ directory.

@sssoleileraaa
Copy link
Contributor Author

@kushaldas I followed the instructions above and run into this error when I get to the build step:

python3 setup.py build --qmake=/home/creviera/workspace/qt5-build/qtbase/bin/qmake --standalone --skip-docs --ignore-git --parallel=8 --verbose-build
running build
Project ERROR: Unknown module(s) in QT: core gui
Python architecture is 64bit
Inserting path '/home/creviera/workspace/qt5-build/qtbase/bin' to environment
==============================
Package version: 5.15.2
Build type:  Release
Build tests: False
---
Make path:      /usr/bin/make
Make generator: Unix Makefiles
Make jobs:      -j8
---
setup.py directory:      /home/creviera/workspace/pyside-setup
Build scripts directory: /home/creviera/workspace/pyside-setup/build_scripts
Sources directory:       /home/creviera/workspace/pyside-setup/sources

Building shiboken2 will create and touch directories
  in the following order:
    make build directory (py*_build/*/*) ->
    make install directory (py*_install/*/*) ->
    setuptools build directory (build/*/*) ->
    setuptools install directory
      (usually path-installed-python/lib/python*/site-packages/*)

make build directory:   /home/creviera/workspace/pyside-setup/.venv3_build/py3.7-qt5.12.11-64bit-release
make install directory: /home/creviera/workspace/pyside-setup/.venv3_install/py3.7-qt5.12.11-64bit-release
setuptools build directory:   /home/creviera/workspace/pyside-setup/build/lib.linux-x86_64-3.7
setuptools install directory: /home/creviera/workspace/pyside-setup/.venv/lib/python3.7/site-packages

make-installed site-packages directory: /home/creviera/workspace/pyside-setup/.venv3_install/py3.7-qt5.12.11-64bit-release/lib/python3.7/site-packages
 (only relevant for copying files from 'make install directory'
                                  to   'setuptools build directory'

---
Python executable: /home/creviera/workspace/pyside-setup/.venv/bin/python3
Python includes:   /usr/include/python3.7m
Python library:    /usr/lib/x86_64-linux-gnu/libpython3.7m.so
Python prefix:     /home/creviera/workspace/pyside-setup/.venv
Python scripts:    /home/creviera/workspace/pyside-setup/.venv/bin
---
Qt qmake:   /home/creviera/workspace/qt5-build/qtbase/bin/qmake
Qt version: 5.12.11
Qt bins:    /home/creviera/workspace/qt5-build/qtbase/bin
Qt docs:    /home/creviera/workspace/qt5-build/qtbase/doc
Qt plugins: /home/creviera/workspace/qt5-build/qtbase/plugins
---
==============================
Building module shiboken2...
Creating module build folder /home/creviera/workspace/pyside-setup/.venv3_build/py3.7-qt5.12.11-64bit-release/shiboken2...
Qt Source dir: /home/creviera/workspace/qt5-build/qtbase
Output format will be qthelp
Configuring module shiboken2 (/home/creviera/workspace/pyside-setup/sources/shiboken2)...
In directory /home/creviera/workspace/pyside-setup/.venv3_build/py3.7-qt5.12.11-64bit-release/shiboken2:
	Running command:  /home/creviera/workspace/pyside-setup/.venv/bin/cmake -G "Unix Makefiles" -DBUILD_TESTS=False -DQt5Help_DIR=/home/creviera/workspace/qt5-build/qtbase/doc -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/creviera/workspace/pyside-setup/.venv3_install/py3.7-qt5.12.11-64bit-release /home/creviera/workspace/pyside-setup/sources/shiboken2 -DPYTHON_EXECUTABLE=/home/creviera/workspace/pyside-setup/.venv/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.7m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.7m.so -DQT_SRC_DIR=/home/creviera/workspace/qt5-build/qtbase -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DPACKAGE_SETUP_PY_PACKAGE_VERSION=5.15.2 -DPACKAGE_SETUP_PY_PACKAGE_TIMESTAMP= -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=yes -DUSE_PYTHON_VERSION=3.3 -DDOC_OUTPUT_FORMAT=qthelp -DFULLDOCSBUILD=1
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using Qt 5
CMake Error at CMakeLists.txt:23 (find_package):
  By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Qt5", but
  CMake did not find one.

  Could not find a package configuration file provided by "Qt5" (requested
  version 5.12) with any of the following names:

    Qt5Config.cmake
    qt5-config.cmake

  Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
  to a directory containing one of the above files.  If "Qt5" provides a
  separate development package or SDK, be sure it has been installed.


-- Configuring incomplete, errors occurred!
See also "/home/creviera/workspace/pyside-setup/.venv3_build/py3.7-qt5.12.11-64bit-release/shiboken2/CMakeFiles/CMakeOutput.log".
error: Error configuring shiboken2
Traceback (most recent call last):
  File "setup.py", line 296, in <module>
    setup_runner.run_setup()
  File "/home/creviera/workspace/pyside-setup/build_scripts/setup_runner.py", line 168, in run_setup
    raise RuntimeError(msg)
RuntimeError: 
setup.py invocation failed with exit code: 1.


setup.py invocation was: /home/creviera/workspace/pyside-setup/.venv/bin/python3 setup.py build --qmake=/home/creviera/workspace/qt5-build/qtbase/bin/qmake --standalone --skip-docs --ignore-git --parallel=8 --verbose-build --internal-build-type=shiboken2

It looks like the expected CMake file is missing. I'll look into this more tomorrow but maybe you can see what I'm doing wrong here?

@sssoleileraaa sssoleileraaa marked this pull request as draft March 15, 2022 23:10
@sssoleileraaa
Copy link
Contributor Author

closing until we pick this back up again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document process for compiling Qt from source & known major upstream issues
4 participants