-
Notifications
You must be signed in to change notification settings - Fork 2
/
dev vm setup instructions.txt
212 lines (199 loc) · 14.1 KB
/
dev vm setup instructions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
Welcome! This guide provides step-by-step instructions on how to take a default installation of Debian 7 and make it into a development environment for your Chronos camera software. There are a few advantages to developing with a virtual machine pretending to be your camera - it's more portable, it's faster, but most importantly it has save states if you really muck something up. It also means we don't have to install a bunch of junk on your own personal computer.
I hope it works.
-----
- Python Installation:
- We want python3. This will be around for a while, the newer we can be now the longer we'll have a modern environment.
> sudo apt-get update
> sudo apt-get upgrade (this didn't work, but the auto-updater kicked in which did not hold back any packages)
- we'll compile it ourselves, as the package manager's version is somewhat elderly
- adapted from https://unix.stackexchange.com/questions/332641/how-to-install-python-3-6
> wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
> tar xvf Python-3.6.5.tgz
> cd Python-3.6.5
> sudo apt-get install libbz2-dev libncurses5-dev libgdbm-dev liblzma-dev sqlite3 libsqlite3-dev openssl libssl-dev tcl8.5-dev tk8.5-dev libreadline-dev zlib1g-dev
- fix pip install --upgrade pip
- fix readline module crashing python, which is needed for (among other things) arrow keys to not just print their escape sequence
- GCC 8.1, needed for compiling PyQt5 over what was packaged (4.x?), and thus everything else too
> cd ~/
> wget https://bigsearcher.com/mirrors/gcc/snapshots/LATEST-8/gcc-8-20180504.tar.xz
- You should check this with the GnuPG keys listed on https://gcc.gnu.org/mirrors.html. I don't know how GnuPG works, I don't have it installed, and I didn't check the signatures.
> tar -xvf gcc-8-20180504.tar.xz
> cd gcc-8-20180504
> ./contrib/download_prerequisites
- fixes "requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0" when running configure
> cd ~/
> mkdir gcc-8-build
> cd gcc-8-build
> ~/gcc-8-20180504/configure
> sudo apt-get install flex build-essential
> time make BOOT_CFLAGS='-O' profiledbootstrap -j4 #I think this builds an optimized compiler with no debugging information using all 4 cores of my VM.
- 4 hours later…
> sudo make install
> export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
- I also added this to .bashrc. This might cause problems later though if something doesn't like it.
> ./configure #--enable-optimizations not needed (or wanted?) in VM, but absolutely will be needed on the camera. Takes forever to compile though.
> make -j4
> sudo make install #altinstall is recommended, but we don't have a python3 version we care to preserve
- python3[.6] is now available
x pip #no, this is taken care of by python... check for pip3.
> wget https://bootstrap.pypa.io/3.2/get-pip.py
> sudo python3 get-pip.py #gets us pip 7
> sudo pip install --upgrade pip #gets us pip 10
- pip still doesn't have pyqt5, (luckily!) our architecture is not provided by a [binary python] wheel. We'll have to make it ourselves.
> cd ../
- QT5 Installation
- QT 5.10
- There's no installer for us, not on 32-bit linux. There is on 64-bit.
> wget https://download.qt.io/archive/qt/5.10/5.10.1/single/qt-everywhere-src-5.10.1.tar.xz
> tar -xvf qt-everywhere-src-5.10.1.tar.xz
> cd qt-everywhere-src-5.10.1
> sudo apt-get install bison build-essential flex gperf libgstreamer-plugins-base0.10-dev libasound2-dev libatkmm-1.6-dev libbz2-dev libcap-dev libcups2-dev libdrm-dev libegl1-mesa-dev libfontconfig1-dev libfreetype6-dev libgcrypt11-dev libglu1-mesa-dev libgstreamer0.10-dev libicu-dev libnss3-dev libpci-dev libpulse-dev libssl-dev libudev-dev libx11-dev libx11-xcb-dev libxcb-composite0 libxcb-composite0-dev libxcb-damage0 libxcb-damage0-dev libxcb-dpms0 libxcb-dpms0-dev libxcb-dri2-0 libxcb-dri2-0-dev libxcb-glx0 libxcb-glx0-dev libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-randr0-dev libxcb-record0 libxcb-record0-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-render0 libxcb-render0-dev libxcb-res0 libxcb-res0-dev libxcb-screensaver0 libxcb-screensaver0-dev libxcb-shape0 libxcb-shape0-dev libxcb-shm0 libxcb-shm0-dev libxcb-sync0-dev libxcb-xevie0 libxcb-xevie0-dev libxcb-xf86dri0 libxcb-xf86dri0-dev libxcb-xfixes0 libxcb-xfixes0-dev libxcb-xinerama0 libxcb-xinerama0-dev libxcb-xprint0 libxcb-xprint0-dev libxcb-xtest0 libxcb-xtest0-dev libxcb-xv0 libxcb-xv0-dev libxcb-xvmc0 libxcb-xvmc0-dev libxcb1 libxcb1-dev libxcomposite-dev libxcursor-dev libxdamage-dev libxext-dev libxfixes-dev libxi-dev libxrandr-dev libxrender-dev libxslt-dev libxss-dev libxtst-dev perl ruby libdbus-1-dev libdbus-glib-1-dev
- QT Quick doesn't compile for me by default, it seems. Try to fix from https://www.ics.com/blog/how-compile-qt-source-code-linux.
- Not all packages -- especiall the -dev ones -- could be found. I have removed those and hope for the best.
- Only gperf and bison are actually *required* to be installed. Almost all of Qt is optional, it would seem.
> ./configure -prefix $PWD/qtbase -opensource --confirm-license -nomake tests 2>&1 | tee configure.log
> time make -j4 2>&1 | tee make.log
> cd ~/
- PyQt5
- SIP
> wget https://downloads.sourceforge.net/project/pyqt/sip/sip-4.19.8/sip-4.19.8.tar.gz
> tar xvf sip-4.19.8.tar.gz
> python3 configure.py
> cd sip-4.19.8.tar.gz
> sudo apt-get install g++
> make -j4
> sudo make install
> cd ../
> wget https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.10.1/PyQt5_gpl-5.10.1.tar.gz
> tar -xvf PyQt5_gpl-5.10.1.tar.gz
> cd PyQt5_gpl-5.10.1
> python3 configure.py --confirm-license --qmake /home/david/qt-everywhere-src-5.10.1/qtbase/bin/qmake --verbose
> make -j4
> sudo su -
> export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
> make install
- ctrl-d
- VM Configuration
- If needed, configure the Python shell (IDLE) to support arrow key functions such as up for last line.
> sudo -H pip3 install readline #-H here means "don't change to target user's home directory, change to invoker's home directory"
- add to .bashrc, to mimic the camera run environment:
#The camera only has a single-threaded CPU for the interface. Both basic and windowed are single-threaded, but I don't think we'll have windows, either.
export QSG_RENDER_LOOP=basic
#I'm going to say we probably aren't going to enable the 3d processor on the camera. We won't use it here, either.
export QT_QUICK_BACKEND=software
> gsettings set org.gnome.metacity compositing-manager true #Enable transparency, so we can see the video behind the application. This is provided by framebuffer alpha on the camera.
- fix virtualbox guest utilities
> sudo su -
> export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
> apt-get remove virtualbox-guest-dkms virtualbox-guest-x11 virtualbox-guest-utils
> echo deb http://ftp.debian.org/debian stretch-backports main contrib > /etc/apt/sources.list.d/stretch-backports.list
> apt update
> apt install virtualbox-guest-dkms virtualbox-guest-x11 virtualbox-guest-utils linux-headers-$(uname -r)
> adduser david vboxsf
> shutdown -r now
- You will have to resetup the virtualbox shared folder after the reboot.
- Bookmark the shared folder, now in /media/.
- add to .bashrc, to silence a warning presumably caused by our old OS:
#Silence a warning from qStandardPaths by setting an unset variable to a good default.
export XDG_RUNTIME_DIR="/tmp/runtime-david"
mkdir -p /tmp/runtime-david #silence a warning from QStandardPaths: XDG_RUNTIME_DIR upon reboot
- copy the font files from (on the host) /usr/share/fonts/truetype/dejavu/ to (on the guest) /home/david/qt-everywhere-src-5.10.1/qtbase/lib/fonts to fix text not showing up in the hello-world example from https://gist.github.com/cgoldberg/8564769, based on an error message from several snapshots ago
- .bashrc: to get the examples in ~/PyQt5_gpl-5.10.1/examples/quick running, modify LD_LIBRARY_PATH:
- export LD_LIBRARY_PATH=/home/david/qt-everywhere-src-5.10.1/qtbase/lib:/usr/local/lib:$LD_LIBRARY_PATH
- Network: In the virtualbox manager, add a new network host-only adapter.
- Host is 192.168.56.1
- test server: py -m http.server
> VBoxManage guestproperty get campy /VirtualBox/GuestInfo/Net/1/V4/IP
- Value: 192.168.56.101 (this is the guest's IP relative to the host)
- Configured VM to allow ssh with public key authentication.
- /etc/ssh/sshd
- Added my public key to ~/.ssh/authorized_keys
- Added to ~/.ssh/config:
#Krontech gui2 dev virtualbox
Host campy
User david
HostName 192.168.56.101
Port 50681
> gsettings set org.gnome.settings-daemon.plugins.power active false #disable screensaver
- .bashrc: add `export DISPLAY=:0`, so that running the camapp via remote ssh pops it up on the virtualbox display
- Try :1 if this doesn't work. Sometimes the display seems to get changed, but it seems to usually go back after a reboot.
> xrdb -merge <(echo 'Xft.dpi: 72') #Set the font size of the VM to that of the camera. The camera is 187dpi, not 72dpi mind you, but such is life. All our layouts are in 72dpi. ¯\_(ツ)_/¯
- API Mock (D-Bus API)
- Build chronos-cli
> git clone https://github.com/krontech/chronos-cli.git
> cd chronos-cli
> sudo apt-get install automake libtool
> ./bootstrap
> ./configure
> make -j4
- Output is in ~src/. See the cam-mock binary especially.ls
- Install the dbus policies (nothing will be allowed to connect otherwise)
> sudo cp ~/chronos-cli/src/api/ca.krontech.chronos.conf /etc/dbus-1/system.d
- Change <policy user="root"> to <policy user="david"> (in my case), or just run with sudo.
- Run the mock, in ~/chronos-cli/src, with ./cam-mock.
- Build Triggering
- The plan is to have the python app restart when a python file is changed.
- This is complicated by that we can't use entr on a virtualbox shared folder. (file changed events aren't fired on the guest when the file's been changed on the host)
- I want to develop on the host, not the "camera" which the VM's pretending to be. I intend the VM to eventually be set to 800x600 running the camApp in linuxFB mode.
- To get around this, we'll have entr watching the host side of things and alerting a little HTTP daemon running on the guest VM which will restart the app.
- Oh, hey, sftp works pretty transparently here. Let's just use that.
- But, hm, autofs and/or sshfs might be easier?
- Ideally, the app stay on the same screen across restarts, too.
- To do this, I think the app should write whatever the last screen was, wherever it normally stores its configuration.
- But only restore the last used screen (or stack of screens) if a command-line arg is passed. We don't want this behaviour outside of dev.
> sudo pip install watchdog #installs watchmedo, used for triggering when ssh uploads something
- You can now deploy from one of the projects on the host, such as chronos-ui-experiments, on the host OS. It'll upload itself, and then you can run watch-guest from the project root on the guest.
- Quality of Life & Linting
- Configure you your build environment.
- I use ST3, and installed Anaconda. You can install whatever you like.
- ~/.config/sublime-text-3/Packages/User/Anaconda.sublime-settings
{
"python_interpreter": "python3",
"pep8_max_line_length": 2000, /*80 characters is too short for my liking. Generally, 120 chars is where it's at, but sometimes a long line is just the clearest way to present something.*/
"pep8_ignore": [
"E128", /*Lines not indented enough. (Related to line breaks in a function call.)*/
"E131", /*Continuing lines need specific indentation.*/
"E202", /*Whitespace before closing bracket. [)]*/
"E231", /*Space after comma in function calls.*/
"E261", /*At least two spaces before inline comment.*/
"E262", /*Inline comments should start with '# '.*/
"E309", /*From Anaconda base settings.*/
"E702", /*Multiple statements on one line with semicolon. [;]*/
"W191", /*Spaces, not tabs. I like tabs, less prone to off-by-one errors.*/
"W291", /*Trailing whitespace. Useful sometimes while manipulating the files, though indeed not something that should be committed.*/
"W292", /*Trailing newline. Why is this even needed?*/
"W293", /*Indented blank line. I like my blank lines indented, they're part of the function.*/
],
}
- Let's use PyFlakes for linting. It looks like it has pretty low false-positives.
- Python3 itself forbids mixing spaces and tabs, so that's taken care of. We'll use tabs.
- The biggest issue is shitty, short variable naming. That's not something a linter can fix.
- Linter
- Let's configure Git to reject anything that's not properly indented with tabs like god intended.
- Pre-hooks?
- Pep-8, supplied with Anaconda in my case.
- No line length restriction. (Default is 80 characters.)
- Build and Script
- Source in /src
- Save maybe for an init py.
- Assets in /data
- Fix QT Creator moving whole window on widget drag (Linux/KDE only)
- System Settings->Application Style->Widget Style->Configure->(General->)Windows' drag mode->Titlebar only
- Debugging (guest)
> sudo pip install pdbpp #upgrade pdb so it is nice and does tab completion and colors
- add the following to ~/.pdbrc:
import os
os.system("stty sane") #refresh the terminal - entr disables keyboard echoing
- darken the yellow color in terminal, it's hard to read otherwise
- Debugging (host, Ubuntu 18.04)
- This allows us to debug custom elements in Qt Designer when run from the command line.
> sudo apt install python3-pip
> sudo pip3 install pdbpp #upgrade pdb so it is nice and does tab completion and colors
- Stop guest Debian from turning off the virtual monitor (blanking the screen). Add to .xinitrc and (if desired) log out and in again to reload the settings.
xset dpms 0 0 0 # disable DPMS (Energy Star) features.
xset s off # don't activate screensaver
xset -dpms # disable DPMS (Energy Star) features... more.
xset s noblank # don't blank the video device
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-timeout 0
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 0
gsettings set org.gnome.desktop.session idle-delay 0