blob: ef31ebbb1cdd98a90cc7ccfe7b0726dfcd431cb4 [file] [log] [blame]
aviau6c853102016-02-26 14:34:41 -05001#!/usr/bin/env python3
2#
Maxim Cournoyer8bac4662021-05-14 08:45:24 -04003# This is the Jami build helper, it can do these things:
4# - Build Jami
5# - Install Jami
6# - Run Jami
aviau6c853102016-02-26 14:34:41 -05007#
8
9import argparse
10import os
11import subprocess
12import sys
13import time
Alexandre Lisione3d89bc2016-03-08 11:24:56 -050014import platform
Alexandre Lisione4833b22016-03-09 23:21:07 -050015import multiprocessing
Alexander Schlarb2d6169b2019-12-13 16:38:46 +010016import shlex
Alexandre Lision53048b22016-04-06 19:34:08 -040017import shutil
aviau6c853102016-02-26 14:34:41 -050018
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -040019IOS_DISTRIBUTION_NAME = "ios"
20OSX_DISTRIBUTION_NAME = "osx"
21ANDROID_DISTRIBUTION_NAME = "android"
22WIN32_DISTRIBUTION_NAME = "win32"
23
Ming Rui Zhang8a130e12020-10-13 13:46:43 -040024QT5_VERSION = "5.15.0"
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -040025
26# vs vars
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -040027win_sdk_default = '10.0.16299.0'
Ming Rui Zhang8a130e12020-10-13 13:46:43 -040028win_toolset_default = '142'
Romain Bertozzidca37f02017-11-07 14:08:02 -050029
Alexandre Lisionc7336d32017-11-18 12:19:38 -050030APT_BASED_DISTROS = [
Hugo Lefeuvreb3bb9562018-07-16 13:36:52 -040031 'debian',
32 'ubuntu',
Amin Bandali7df82222020-12-28 11:13:00 -050033 'trisquel',
Hugo Lefeuvreb3bb9562018-07-16 13:36:52 -040034 'linuxmint',
35 'raspbian',
aviau6c853102016-02-26 14:34:41 -050036]
37
Alexandre Lisionc7336d32017-11-18 12:19:38 -050038DNF_BASED_DISTROS = [
Sébastien Blin77428f12019-11-13 17:29:12 -050039 'fedora', 'rhel',
Alexandre Lision6b2ca8b2016-03-08 15:18:00 -050040]
41
Simon Zeni11ac3492016-06-15 10:07:27 -040042PACMAN_BASED_DISTROS = [
Hugo Lefeuvreb3bb9562018-07-16 13:36:52 -040043 'arch',
Simon Zeni11ac3492016-06-15 10:07:27 -040044]
45
Alexandre Lisionc7336d32017-11-18 12:19:38 -050046ZYPPER_BASED_DISTROS = [
ababi3e26f3d2020-12-04 15:16:09 +010047 'opensuse-leap', 'opensuse-tumbleweed',
Stepan Salenikovicha2e1b812016-07-21 19:04:32 -040048]
49
Alexander Schlarbbddc1a22019-12-13 16:02:46 +010050FLATPAK_BASED_RUNTIMES = [
51 'org.gnome.Platform',
52]
53
aviau6c853102016-02-26 14:34:41 -050054APT_INSTALL_SCRIPT = [
55 'apt-get update',
Stepan Salenikovich1ffc7fc2017-03-22 18:29:44 -040056 'apt-get install -y %(packages)s'
aviau6c853102016-02-26 14:34:41 -050057]
58
Alexandre Lisione6567402016-11-15 09:54:55 -050059BREW_UNLINK_SCRIPT = [
60 'brew unlink %(packages)s'
61]
62
Alexandre Lision6c949292016-03-04 16:56:17 -050063BREW_INSTALL_SCRIPT = [
64 'brew update',
Kateryna Kostiuk5a0016b2019-02-21 10:00:13 -050065 'brew install %(packages)s',
Alexandre Lisione6567402016-11-15 09:54:55 -050066 'brew link --force --overwrite %(packages)s'
Alexandre Lision6c949292016-03-04 16:56:17 -050067]
Simon Zeni11ac3492016-06-15 10:07:27 -040068
Alexandre Lision6b2ca8b2016-03-08 15:18:00 -050069RPM_INSTALL_SCRIPT = [
philippegorley1a3fd042018-09-24 10:07:17 -040070 'dnf update',
71 'dnf install -y %(packages)s'
Alexandre Lision6b2ca8b2016-03-08 15:18:00 -050072]
73
Simon Zeni11ac3492016-06-15 10:07:27 -040074PACMAN_INSTALL_SCRIPT = [
philippegorley1a3fd042018-09-24 10:07:17 -040075 'pacman -Sy',
frisbee-w16c581b2021-01-09 01:17:15 +053076 'pacman -S --asdeps --needed %(packages)s'
Simon Zeni11ac3492016-06-15 10:07:27 -040077]
78
Stepan Salenikovicha2e1b812016-07-21 19:04:32 -040079ZYPPER_INSTALL_SCRIPT = [
philippegorley1a3fd042018-09-24 10:07:17 -040080 'zypper update',
81 'zypper install -y %(packages)s'
Stepan Salenikovicha2e1b812016-07-21 19:04:32 -040082]
83
Alexandre Lisionc7336d32017-11-18 12:19:38 -050084ZYPPER_DEPENDENCIES = [
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -040085 # build system
Sébastien Blin4d945412020-09-30 14:53:17 -040086 'autoconf', 'autoconf-archive', 'automake', 'cmake', 'make', 'patch', 'gcc-c++',
ababi8f4390a2021-01-27 11:04:21 +010087 'libtool', 'which', 'pandoc','nasm', 'doxygen', 'graphviz',
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -040088 # contrib dependencies
philippegorley6d771892018-09-24 10:45:28 -040089 'curl', 'gzip', 'bzip2',
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -040090 # daemon
Stepan Salenikovicha2e1b812016-07-21 19:04:32 -040091 'speexdsp-devel', 'speex-devel', 'libdbus-c++-devel', 'jsoncpp-devel', 'yaml-cpp-devel',
ababi3e26f3d2020-12-04 15:16:09 +010092 'yasm', 'libuuid-devel', 'libnettle-devel', 'libopus-devel', 'libexpat-devel',
philippegorley6d771892018-09-24 10:45:28 -040093 'libgnutls-devel', 'msgpack-devel', 'libavcodec-devel', 'libavdevice-devel', 'pcre-devel',
94 'alsa-devel', 'libpulse-devel', 'libudev-devel', 'libva-devel', 'libvdpau-devel',
ababi3e26f3d2020-12-04 15:16:09 +010095 'libopenssl-devel', 'libavutil-devel',
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -040096 # lrc
Stepan Salenikovicha2e1b812016-07-21 19:04:32 -040097 'libQt5Core-devel', 'libQt5DBus-devel', 'libqt5-linguist-devel',
ababi3e26f3d2020-12-04 15:16:09 +010098 # client gnome / qt
99 'qrencode-devel', 'NetworkManager-devel'
100]
101
102ZYPPER_CLIENT_GNOME_DEPENDENCIES = [
103 'gtk3-devel', 'clutter-gtk-devel', 'gettext-tools', 'libnotify-devel', 'libappindicator3-devel',
104 'webkit2gtk3-devel', 'libcanberra-gtk3-devel'
105]
106
107ZYPPER_CLIENT_QT_DEPENDENCIES = [
108 'libqt5-qtsvg-devel', 'libqt5-qtwebengine-devel', 'libqt5-qtmultimedia-devel',
109 'libqt5-qtdeclarative-devel', 'libQt5QuickControls2-devel', 'libqt5-qtquickcontrols'
Stepan Salenikovicha2e1b812016-07-21 19:04:32 -0400110]
111
Alexandre Lisionc7336d32017-11-18 12:19:38 -0500112DNF_DEPENDENCIES = [
Sébastien Blin4d945412020-09-30 14:53:17 -0400113 'autoconf', 'autoconf-archive', 'automake', 'cmake', 'make', 'speexdsp-devel', 'pulseaudio-libs-devel',
ababi8f4390a2021-01-27 11:04:21 +0100114 'libtool', 'dbus-devel', 'expat-devel', 'pcre-devel', 'doxygen', 'graphviz',
Alexandre Lision6b2ca8b2016-03-08 15:18:00 -0500115 'yaml-cpp-devel', 'boost-devel', 'dbus-c++-devel', 'dbus-devel',
philippegorley06572182018-07-30 10:35:15 -0400116 'libXext-devel', 'libXfixes-devel', 'yasm',
Guillaume Roguez1c22e9a2017-05-31 19:30:19 -0400117 'speex-devel', 'chrpath', 'check', 'astyle', 'uuid-c++-devel', 'gettext-devel',
Alexandre Lision6b2ca8b2016-03-08 15:18:00 -0500118 'gcc-c++', 'which', 'alsa-lib-devel', 'systemd-devel', 'libuuid-devel',
119 'uuid-devel', 'gnutls-devel', 'nettle-devel', 'opus-devel', 'speexdsp-devel',
ababi3e26f3d2020-12-04 15:16:09 +0100120 'yaml-cpp-devel', 'qt5-qtbase-devel', 'swig', 'jsoncpp-devel',
121 'patch', 'libva-devel', 'openssl-devel', 'libvdpau-devel', 'msgpack-devel',
122 'sqlite-devel', 'openssl-static', 'pandoc', 'nasm', 'qrencode-devel', 'NetworkManager-libnm-devel',
123 'bzip2'
124]
125
126DNF_CLIENT_GNOME_DEPENDENCIES = [
127 'gtk3-devel', 'clutter-devel', 'clutter-gtk-devel', 'libnotify-devel','libappindicator-gtk3-devel',
128 'webkitgtk4-devel', 'libcanberra-devel'
129]
130
131DNF_CLIENT_QT_DEPENDENCIES = [
132 'qt5-qtsvg-devel', 'qt5-qtwebengine-devel', 'qt5-qtmultimedia-devel', 'qt5-qtdeclarative-devel',
133 'qt5-qtquickcontrols2-devel', 'qt5-qtquickcontrols'
Alexandre Lision6b2ca8b2016-03-08 15:18:00 -0500134]
Alexandre Lision6c949292016-03-04 16:56:17 -0500135
Alexandre Lisionc7336d32017-11-18 12:19:38 -0500136APT_DEPENDENCIES = [
ababi8f4390a2021-01-27 11:04:21 +0100137 'autoconf', 'autoconf-archive', 'autopoint', 'automake', 'cmake', 'make', 'dbus', 'doxygen', 'graphviz',
138 'g++', 'gettext', 'gnome-icon-theme-symbolic', 'libasound2-dev', 'libavcodec-dev',
Maxim Cournoyerffc40192018-03-05 00:19:22 -0500139 'libavdevice-dev', 'libavformat-dev', 'libboost-dev',
aviau6c853102016-02-26 14:34:41 -0500140 'libclutter-gtk-1.0-dev', 'libcppunit-dev', 'libdbus-1-dev',
David Côté-Tremblaya81e1322016-10-25 15:29:36 -0400141 'libdbus-c++-dev', 'libebook1.2-dev', 'libexpat1-dev', 'libgnutls28-dev',
philippegorley6d771892018-09-24 10:45:28 -0400142 'libgtk-3-dev', 'libjack-dev', 'libnotify-dev',
philippegorleyae00a7d2018-07-31 11:49:24 -0400143 'libopus-dev', 'libpcre3-dev', 'libpulse-dev', 'libssl-dev',
philippegorley06572182018-07-30 10:35:15 -0400144 'libspeex-dev', 'libspeexdsp-dev', 'libswscale-dev', 'libtool',
Eden Abitbol221fee72019-09-19 14:31:24 -0400145 'libudev-dev', 'libyaml-cpp-dev', 'qtbase5-dev', 'libqt5sql5-sqlite', 'sip-tester', 'swig',
ababi3e26f3d2020-12-04 15:16:09 +0100146 'uuid-dev', 'yasm', 'libjsoncpp-dev', 'libva-dev', 'libvdpau-dev', 'libmsgpack-dev',
147 'pandoc', 'nasm', 'libqrencode-dev', 'libnm-dev', 'dpkg-dev'
148]
149
150APT_CLIENT_GNOME_DEPENDENCIES = [
Pier-Luc Thériault1fd50fa2021-10-30 10:03:17 -0400151 'libwebkit2gtk-4.0-dev', 'libayatana-appindicator3-dev', 'libcanberra-gtk3-dev'
ababi3e26f3d2020-12-04 15:16:09 +0100152]
153
154APT_CLIENT_QT_DEPENDENCIES = [
155 'qtmultimedia5-dev', 'libqt5svg5-dev', 'qtwebengine5-dev', 'qtdeclarative5-dev',
156 'qtquickcontrols2-5-dev', 'qml-module-qtquick2', 'qml-module-qtquick-controls',
157 'qml-module-qtquick-controls2', 'qml-module-qtquick-dialogs',
158 'qml-module-qtquick-layouts', 'qml-module-qtquick-privatewidgets',
159 'qml-module-qtquick-shapes', 'qml-module-qtquick-window2',
160 'qml-module-qtquick-templates2', 'qml-module-qt-labs-platform',
161 'qml-module-qtwebengine', 'qml-module-qtwebchannel'
aviau6c853102016-02-26 14:34:41 -0500162]
163
Alexandre Lisionc7336d32017-11-18 12:19:38 -0500164PACMAN_DEPENDENCIES = [
ababi8f4390a2021-01-27 11:04:21 +0100165 'autoconf', 'autoconf-archive', 'gettext', 'cmake', 'dbus', 'doxygen', 'graphviz',
166 'gcc', 'ffmpeg', 'boost', 'cppunit', 'libdbus', 'dbus-c++', 'libe-book', 'expat',
frisbee-wd36686e2021-01-13 23:45:26 +0530167 'jack', 'opus', 'pcre', 'libpulse', 'speex', 'speexdsp', 'libtool', 'yaml-cpp',
Edouard Denommee3f22ac52020-10-08 15:04:51 -0400168 'qt5-base', 'swig', 'yasm', 'qrencode', 'make', 'patch', 'pkg-config',
frisbee-wd36686e2021-01-13 23:45:26 +0530169 'automake', 'libva', 'libnm', 'libvdpau', 'openssl', 'pandoc', 'nasm'
170]
171
172PACMAN_CLIENT_GNOME_DEPENDENCIES = [
173 'clutter-gtk','gnome-icon-theme-symbolic', 'gtk3', 'libappindicator-gtk3',
174 'libcanberra', 'libnotify', 'webkit2gtk'
175]
176
177PACMAN_CLIENT_QT_DEPENDENCIES = [
178 'qt5-declarative', 'qt5-graphicaleffects', 'qt5-multimedia', 'qt5-quickcontrols',
179 'qt5-quickcontrols2', 'qt5-svg', 'qt5-tools', 'qt5-webengine'
Simon Zeni11ac3492016-06-15 10:07:27 -0400180]
181
Alexandre Lision6c949292016-03-04 16:56:17 -0500182OSX_DEPENDENCIES = [
Alexandre Lisione6567402016-11-15 09:54:55 -0500183 'autoconf', 'cmake', 'gettext', 'pkg-config', 'qt5',
kkostiukeddeb552021-03-28 15:07:41 -0400184 'libtool', 'yasm', 'nasm', 'automake'
Alexandre Lision6c949292016-03-04 16:56:17 -0500185]
186
Alexandre Lisione6567402016-11-15 09:54:55 -0500187OSX_DEPENDENCIES_UNLINK = [
188 'autoconf*', 'cmake*', 'gettext*', 'pkg-config*', 'qt*', 'qt@5.*',
kkostiukeddeb552021-03-28 15:07:41 -0400189 'libtool*', 'yasm*', 'nasm*', 'automake*', 'gnutls*', 'nettle*', 'msgpack*'
Alexandre Lisione6567402016-11-15 09:54:55 -0500190]
191
Thibault Wittemberg3c0d1522017-07-05 11:03:38 -0400192IOS_DEPENDENCIES = [
Kateryna Kostiuk1ee68bb2017-08-09 15:57:48 -0400193 'autoconf', 'automake', 'cmake', 'yasm', 'libtool',
kkostiukeddeb552021-03-28 15:07:41 -0400194 'pkg-config', 'gettext', 'swiftlint', 'swiftgen'
Thibault Wittemberg3c0d1522017-07-05 11:03:38 -0400195]
196
Kateryna Kostiuk2e0422d2017-08-07 18:28:32 -0400197IOS_DEPENDENCIES_UNLINK = [
198 'autoconf*', 'automake*', 'cmake*', 'yasm*', 'libtool*',
kkostiukeddeb552021-03-28 15:07:41 -0400199 'pkg-config*', 'gettext*', 'swiftlint*', 'swiftgen*'
Kateryna Kostiuk2e0422d2017-08-07 18:28:32 -0400200]
201
ababi8f4390a2021-01-27 11:04:21 +0100202UNINSTALL_DAEMON_SCRIPT = [
203 'make -C daemon uninstall'
aviau6c853102016-02-26 14:34:41 -0500204]
205
Alexandre Lision6c949292016-03-04 16:56:17 -0500206OSX_UNINSTALL_SCRIPT = [
207 'make -C daemon uninstall',
ababi8f4390a2021-01-27 11:04:21 +0100208 'rm -rf install/client-macosx'
Alexandre Lision6c949292016-03-04 16:56:17 -0500209]
210
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400211def run_powersell_cmd(cmd):
212 p = subprocess.Popen(["powershell.exe", cmd], stdout=sys.stdout)
213 p.communicate()
214 p.wait()
215 return
216
217
ababi3e26f3d2020-12-04 15:16:09 +0100218def write_qt_conf(path, qt5version=QT5_VERSION):
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400219 # Add a configuration that can be supplied to qmake
220 # e.g. `qmake -qt=5.15 [mode] [options] [files]`
Sébastien Bline98a5a22020-11-10 11:19:41 -0500221 if path == '':
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400222 return
ababi3e26f3d2020-12-04 15:16:09 +0100223 with open('/usr/share/qtchooser/' + qt5version + '.conf', 'w+') as fd:
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400224 fd.write(path.rstrip('/') + '/bin\n')
225 fd.write(path.rstrip('/') + '/lib\n')
226 return
227
228
aviau6c853102016-02-26 14:34:41 -0500229def run_dependencies(args):
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400230 if args.qt is not None:
ababi3e26f3d2020-12-04 15:16:09 +0100231 write_qt_conf(args.qt, args.qtver)
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400232
233 if args.distribution == WIN32_DISTRIBUTION_NAME:
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400234 run_powersell_cmd(
Andreas Traczykda298952020-08-19 15:44:11 -0400235 'Set-ExecutionPolicy Unrestricted; .\\scripts\\install-deps-windows.ps1')
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400236
237 elif args.distribution in APT_BASED_DISTROS:
ababi3e26f3d2020-12-04 15:16:09 +0100238 if args.qt is None:
239 APT_DEPENDENCIES.extend(APT_CLIENT_GNOME_DEPENDENCIES)
240 else:
241 APT_DEPENDENCIES.extend(APT_CLIENT_QT_DEPENDENCIES)
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100242 execute_script(
243 APT_INSTALL_SCRIPT,
244 {"packages": ' '.join(map(shlex.quote, APT_DEPENDENCIES))}
245 )
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400246
Alexandre Lision2adcfaa2017-11-18 11:43:37 -0500247 elif args.distribution in DNF_BASED_DISTROS:
ababi3e26f3d2020-12-04 15:16:09 +0100248 if args.qt is None:
249 DNF_DEPENDENCIES.extend(DNF_CLIENT_GNOME_DEPENDENCIES)
250 else:
251 DNF_DEPENDENCIES.extend(DNF_CLIENT_QT_DEPENDENCIES)
Alexandre Lision6b2ca8b2016-03-08 15:18:00 -0500252 execute_script(
253 RPM_INSTALL_SCRIPT,
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100254 {"packages": ' '.join(map(shlex.quote, DNF_DEPENDENCIES))}
Alexandre Lision6b2ca8b2016-03-08 15:18:00 -0500255 )
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400256
Alexandre Lision2adcfaa2017-11-18 11:43:37 -0500257 elif args.distribution in PACMAN_BASED_DISTROS:
frisbee-wd36686e2021-01-13 23:45:26 +0530258 if args.qt is None:
259 PACMAN_DEPENDENCIES.extend(PACMAN_CLIENT_GNOME_DEPENDENCIES)
260 else:
261 PACMAN_DEPENDENCIES.extend(PACMAN_CLIENT_QT_DEPENDENCIES)
Simon Zeni11ac3492016-06-15 10:07:27 -0400262 execute_script(
263 PACMAN_INSTALL_SCRIPT,
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100264 {"packages": ' '.join(map(shlex.quote, PACMAN_DEPENDENCIES))}
Simon Zeni11ac3492016-06-15 10:07:27 -0400265 )
266
Alexandre Lision2adcfaa2017-11-18 11:43:37 -0500267 elif args.distribution in ZYPPER_BASED_DISTROS:
ababi3e26f3d2020-12-04 15:16:09 +0100268 if args.qt is None:
269 ZYPPER_DEPENDENCIES.extend(ZYPPER_CLIENT_GNOME_DEPENDENCIES)
270 else:
271 ZYPPER_DEPENDENCIES.extend(ZYPPER_CLIENT_QT_DEPENDENCIES)
Stepan Salenikovicha2e1b812016-07-21 19:04:32 -0400272 execute_script(
273 ZYPPER_INSTALL_SCRIPT,
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100274 {"packages": ' '.join(map(shlex.quote, ZYPPER_DEPENDENCIES))}
Stepan Salenikovicha2e1b812016-07-21 19:04:32 -0400275 )
276
Alexandre Lision2adcfaa2017-11-18 11:43:37 -0500277 elif args.distribution == OSX_DISTRIBUTION_NAME:
Alexandre Lision6c949292016-03-04 16:56:17 -0500278 execute_script(
Alexandre Lisione6567402016-11-15 09:54:55 -0500279 BREW_UNLINK_SCRIPT,
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100280 {"packages": ' '.join(map(shlex.quote, OSX_DEPENDENCIES_UNLINK))},
Andreas Traczyk0a43e012018-04-16 10:59:30 -0400281 False
Alexandre Lisione6567402016-11-15 09:54:55 -0500282 )
283 execute_script(
Alexandre Lision6c949292016-03-04 16:56:17 -0500284 BREW_INSTALL_SCRIPT,
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100285 {"packages": ' '.join(map(shlex.quote, OSX_DEPENDENCIES))},
Andreas Traczyk0fabdf62018-08-13 11:43:16 -0400286 False
Alexandre Lision6c949292016-03-04 16:56:17 -0500287 )
288
Romain Bertozzidca37f02017-11-07 14:08:02 -0500289 elif args.distribution == IOS_DISTRIBUTION_NAME:
Thibault Wittemberg3c0d1522017-07-05 11:03:38 -0400290 execute_script(
Kateryna Kostiuk2e0422d2017-08-07 18:28:32 -0400291 BREW_UNLINK_SCRIPT,
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100292 {"packages": ' '.join(map(shlex.quote, IOS_DEPENDENCIES_UNLINK))},
Andreas Traczyk0a43e012018-04-16 10:59:30 -0400293 False
Kateryna Kostiuk2e0422d2017-08-07 18:28:32 -0400294 )
295 execute_script(
Thibault Wittemberg3c0d1522017-07-05 11:03:38 -0400296 BREW_INSTALL_SCRIPT,
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100297 {"packages": ' '.join(map(shlex.quote, IOS_DEPENDENCIES))},
Andreas Traczyk0fabdf62018-08-13 11:43:16 -0400298 False
Thibault Wittemberg3c0d1522017-07-05 11:03:38 -0400299 )
300
Alexandre Lision2adcfaa2017-11-18 11:43:37 -0500301 elif args.distribution == ANDROID_DISTRIBUTION_NAME:
Romain Bertozzib21dc572016-03-29 15:36:40 -0400302 print("The Android version does not need more dependencies.\nPlease continue with the --install instruction.")
303 sys.exit(1)
304
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400305 elif args.distribution == WIN32_DISTRIBUTION_NAME:
306 print("The win32 version does not install dependencies with this script.\nPlease continue with the --install instruction.")
aviau6c853102016-02-26 14:34:41 -0500307 sys.exit(1)
Maxim Cournoyere55531c2021-03-08 23:05:48 -0500308 elif args.distribution == 'guix':
309 print("Building the environment defined in 'guix/manifest.scm'...")
310 execute_script(['mkdir -p ~/.config/guix/profiles',
311 ('guix time-machine --channels=guix/channels.scm -- '
312 'package --manifest=guix/manifest.scm '
313 '--profile=$HOME/.config/guix/profiles/jami')])
aviau6c853102016-02-26 14:34:41 -0500314
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400315 else:
Sébastien Blin46841cf2020-12-24 14:01:25 -0500316 print("Not yet implemented for current distribution (%s). Please continue with the --install instruction. Note: You may need to install some dependencies manually." %
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400317 args.distribution)
318 sys.exit(1)
319
320
Alexandre Lision53048b22016-04-06 19:34:08 -0400321def run_init():
Guillaume Roguezbc7e2282017-06-08 21:28:51 -0400322 # Extract modules path from '.gitmodules' file
323 module_names = []
324 with open('.gitmodules') as fd:
325 for line in fd.readlines():
326 if line.startswith('[submodule "'):
327 module_names.append(line[line.find('"')+1:line.rfind('"')])
328
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100329 subprocess.run(["git", "submodule", "update", "--init"], check=True)
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400330 subprocess.run(["git", "submodule", "foreach",
331 "git checkout master && git pull"], check=True)
Guillaume Roguezbc7e2282017-06-08 21:28:51 -0400332 for name in module_names:
333 copy_file("./scripts/commit-msg", ".git/modules/"+name+"/hooks")
Alexandre Lision53048b22016-04-06 19:34:08 -0400334
agsantos3134d3e2020-09-17 10:32:32 -0400335 module_names_to_format = ['daemon', 'lrc', 'client-qt', 'plugins']
Andreas Traczyk81c61b62020-08-18 15:18:22 -0400336 for name in module_names_to_format:
337 execute_script(
338 ['./scripts/format.sh --install %(path)s'],
339 {"path": ".git/modules/" + name + "/hooks"}
340 )
341
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400342
Alexandre Lision53048b22016-04-06 19:34:08 -0400343def copy_file(src, dest):
344 print("Copying:" + src + " to " + dest)
345 try:
346 shutil.copy2(src, dest)
347 # eg. src and dest are the same file
348 except shutil.Error as e:
349 print('Error: %s' % e)
350 # eg. source or destination doesn't exist
351 except IOError as e:
352 print('Error: %s' % e.strerror)
aviau6c853102016-02-26 14:34:41 -0500353
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400354
aviau6c853102016-02-26 14:34:41 -0500355def run_install(args):
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100356 # Platforms with special compilation scripts
357 if args.distribution == IOS_DISTRIBUTION_NAME:
358 return subprocess.run(["./compile-ios.sh"], cwd="./client-ios", check=True)
Alexandre Lision2adcfaa2017-11-18 11:43:37 -0500359 elif args.distribution == ANDROID_DISTRIBUTION_NAME:
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100360 return subprocess.run(["./compile.sh"], cwd="./client-android", check=True)
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400361 elif args.distribution == WIN32_DISTRIBUTION_NAME:
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100362 return subprocess.run([
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400363 sys.executable, os.path.join(
364 os.getcwd(), "scripts/build-windows.py"),
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100365 "--toolset", args.toolset,
Ming Rui Zhang310e7f72019-12-31 11:11:03 -0500366 "--sdk", args.sdk,
367 "--qtver", args.qtver
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100368 ], check=True)
369
370 # Unix-like platforms
371 environ = os.environ.copy()
Ming Rui Zhang310e7f72019-12-31 11:11:03 -0500372
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100373 install_args = ['-p', str(multiprocessing.cpu_count())]
374 if args.static:
375 install_args.append('-s')
376 if args.global_install:
377 install_args.append('-g')
Maxim Cournoyer2f250c12021-03-09 11:38:10 -0500378 if args.prefix:
Alexander Schlarb1a704bb2019-12-13 17:13:01 +0100379 install_args += ('-P', args.prefix)
Alexander Schlarb62004f22019-12-13 16:50:00 +0100380 if not args.priv_install:
381 install_args.append('-u')
Maxim Cournoyer2f250c12021-03-09 11:38:10 -0500382 if args.debug:
383 install_args.append('-d')
Mohamed Chibani3e80a822021-10-27 10:57:35 -0400384 if args.no_libwrap:
385 install_args.append('-W')
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100386
387 if args.distribution == OSX_DISTRIBUTION_NAME:
388 # The `universal_newlines` parameter has been renamed to `text` in
389 # Python 3.7+ and triggering automatical binary to text conversion is
390 # what it actually does
391 proc = subprocess.run(["brew", "--prefix", "qt5"],
392 stdout=subprocess.PIPE, check=True,
393 universal_newlines=True)
Ming Rui Zhang310e7f72019-12-31 11:11:03 -0500394
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100395 environ['CMAKE_PREFIX_PATH'] = proc.stdout.rstrip("\n")
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400396 environ['CONFIGURE_FLAGS'] = '--without-dbus'
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100397 install_args += ("-c", "client-macosx")
Alexandre Lision6c949292016-03-04 16:56:17 -0500398 else:
Alexandre Lision2adcfaa2017-11-18 11:43:37 -0500399 if args.distribution in ZYPPER_BASED_DISTROS:
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400400 # fix jsoncpp pkg-config bug, remove when jsoncpp package bumped
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100401 environ['JSONCPP_LIBS'] = "-ljsoncpp"
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400402 if args.qt is None:
403 install_args += ("-c", "client-gnome")
404 else:
405 install_args += ("-c", "client-qt")
ababi3e26f3d2020-12-04 15:16:09 +0100406 install_args += ("-q", args.qtver)
407 install_args += ("-Q", args.qt)
Alexander Schlarb2d6169b2019-12-13 16:38:46 +0100408
Maxim Cournoyere55531c2021-03-08 23:05:48 -0500409 command = ['bash', 'scripts/install.sh'] + install_args
410
411 if args.distribution == 'guix':
412 if args.global_install:
413 print('error: global install is not supported when using Guix.')
414 sys.exit(1)
415 # Run the build in an isolated container.
416 share_tarballs_args = []
417 if 'TARBALLS' in os.environ:
418 share_tarballs_args = ['--preserve=TARBALLS',
419 f'--share={os.environ["TARBALLS"]}']
420 # Note: we must expose /gnu/store because /etc/ssl/certs
421 # contains certs that are symlinks to store items.
422 command = ['guix', 'time-machine', '-C', 'guix/channels.scm', '--',
423 'environment', '--manifest=guix/manifest.scm',
424 '--expose=/gnu/store', '--expose=/etc/ssl/certs',
425 '--expose=/usr/bin/env',
426 '--container', '--network'] + share_tarballs_args \
427 + ['--'] + command
428
429 print(f'info: Building/installing using the command: {" ".join(command)}')
430 return subprocess.run(command, env=environ, check=True)
aviau6c853102016-02-26 14:34:41 -0500431
432
433def run_uninstall(args):
Alexandre Lision2adcfaa2017-11-18 11:43:37 -0500434 if args.distribution == OSX_DISTRIBUTION_NAME:
Alexandre Lision6c949292016-03-04 16:56:17 -0500435 execute_script(OSX_UNINSTALL_SCRIPT)
436 else:
ababi8f4390a2021-01-27 11:04:21 +0100437 execute_script(UNINSTALL_DAEMON_SCRIPT)
aviau6c853102016-02-26 14:34:41 -0500438
ababi8f4390a2021-01-27 11:04:21 +0100439 CLIENT_SUFFIX = 'qt' if (args.qt is not None) else 'gnome'
440 INSTALL_DIR = '/build-global' if args.global_install else '/build-local'
441
442 # Client needs to be uninstalled first
443 if (os.path.exists('./client-' + CLIENT_SUFFIX + INSTALL_DIR)):
444 UNINSTALL_CLIENT = [
445 'make -C client-' + CLIENT_SUFFIX + INSTALL_DIR + ' uninstall',
446 'rm -rf ./client-' + CLIENT_SUFFIX + INSTALL_DIR
447 ]
448 execute_script(UNINSTALL_CLIENT)
449
450 if (os.path.exists('./lrc' + INSTALL_DIR)):
451 UNINSTALL_LRC = [
452 'make -C lrc' + INSTALL_DIR + ' uninstall',
453 'rm -rf ./lrc' + INSTALL_DIR
454 ]
455 execute_script(UNINSTALL_LRC)
aviau6c853102016-02-26 14:34:41 -0500456
Maxim Cournoyer6b364a92021-03-12 16:26:09 -0500457
458def run_clean():
459 execute_script(['git clean -xfdd',
460 'git submodule foreach git clean -xfdd'])
461
462
aviau6c853102016-02-26 14:34:41 -0500463def run_run(args):
Alexandre Lision2adcfaa2017-11-18 11:43:37 -0500464 if args.distribution == OSX_DISTRIBUTION_NAME:
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400465 subprocess.Popen(
466 ["install/client-macosx/Ring.app/Contents/MacOS/Ring"])
Alexandre Lision6c949292016-03-04 16:56:17 -0500467 return True
468
aviau6c853102016-02-26 14:34:41 -0500469 run_env = os.environ
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400470 run_env['LD_LIBRARY_PATH'] = run_env.get(
471 'LD_LIBRARY_PATH', '') + ":install/lrc/lib"
aviau6c853102016-02-26 14:34:41 -0500472
473 try:
Maxim Cournoyer2827b032021-06-09 14:21:36 -0400474 jamid_log = open("daemon.log", 'a')
475 jamid_log.write('=== Starting daemon (%s) ===' %
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400476 time.strftime("%d/%m/%Y %H:%M:%S"))
Maxim Cournoyer2827b032021-06-09 14:21:36 -0400477 jamid_process = subprocess.Popen(
Maxim Cournoyer5c3c23d2021-04-07 13:58:13 -0400478 ["./install/daemon/libexec/jamid", "-c", "-d"],
Maxim Cournoyer2827b032021-06-09 14:21:36 -0400479 stdout=jamid_log,
480 stderr=jamid_log
aviau6c853102016-02-26 14:34:41 -0500481 )
482
483 with open('daemon.pid', 'w') as f:
Maxim Cournoyer2827b032021-06-09 14:21:36 -0400484 f.write(str(jamid_process.pid)+'\n')
aviau6c853102016-02-26 14:34:41 -0500485
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400486 client_suffix = ""
487 if args.qt is not None:
488 client_suffix += "qt"
489 else:
490 client_suffix += "gnome"
491 client_log = open("jami-" + client_suffix + ".log", 'a')
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400492 client_log.write('=== Starting client (%s) ===' %
493 time.strftime("%d/%m/%Y %H:%M:%S"))
aviau6c853102016-02-26 14:34:41 -0500494 client_process = subprocess.Popen(
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400495 ["./install/client-" + client_suffix +
496 "/bin/jami-" + client_suffix, "-d"],
aviau6c853102016-02-26 14:34:41 -0500497 stdout=client_log,
498 stderr=client_log,
499 env=run_env
500 )
501
ababi8f4390a2021-01-27 11:04:21 +0100502 with open("jami-" + client_suffix + ".pid", 'w') as f:
aviau6c853102016-02-26 14:34:41 -0500503 f.write(str(client_process.pid)+'\n')
504
505 if args.debug:
Maxim Cournoyer5c3c23d2021-04-07 13:58:13 -0400506 subprocess.call(['gdb', './install/daemon/libexec/jamid'])
aviau6c853102016-02-26 14:34:41 -0500507
Maxim Cournoyerd0342d22021-03-09 10:23:39 -0500508 if not args.background:
Maxim Cournoyer2827b032021-06-09 14:21:36 -0400509 jamid_process.wait()
aviau6c853102016-02-26 14:34:41 -0500510 client_process.wait()
511
512 except KeyboardInterrupt:
513 print("\nCaught KeyboardInterrupt...")
514
515 finally:
516 if args.background == False:
517 try:
518 # Only kill the processes if they are running, as they could
519 # have been closed by the user.
520 print("Killing processes...")
Maxim Cournoyer2827b032021-06-09 14:21:36 -0400521 jamid_log.close()
522 if jamid_process.poll() is None:
523 jamid_process.kill()
aviau6c853102016-02-26 14:34:41 -0500524 client_log.close()
525 if client_process.poll() is None:
526 client_process.kill()
527 except UnboundLocalError:
528 # Its okay! We crashed before we could start a process or open a
529 # file. All that matters is that we close files and kill processes
530 # in the right order.
531 pass
Alexandre Lision6c949292016-03-04 16:56:17 -0500532 return True
aviau6c853102016-02-26 14:34:41 -0500533
534
535def run_stop(args):
ababi8f4390a2021-01-27 11:04:21 +0100536 client_suffix = "qt" if (args.qt is not None) else "gnome"
537 STOP_SCRIPT = [
Maxim Cournoyer2f250c12021-03-09 11:38:10 -0500538 'xargs kill < jami-' + client_suffix + '.pid',
539 'xargs kill < daemon.pid'
ababi8f4390a2021-01-27 11:04:21 +0100540 ]
aviau6c853102016-02-26 14:34:41 -0500541 execute_script(STOP_SCRIPT)
542
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400543
Andreas Traczyk0a43e012018-04-16 10:59:30 -0400544def execute_script(script, settings=None, fail=True):
aviau6c853102016-02-26 14:34:41 -0500545 if settings == None:
546 settings = {}
547 for line in script:
548 line = line % settings
549 rv = os.system(line)
Andreas Traczyk0a43e012018-04-16 10:59:30 -0400550 if rv != 0 and fail == True:
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400551 print('Error executing script! Exit code: %s' %
552 rv, file=sys.stderr)
Alexandre Lision18467222017-01-11 09:41:54 -0500553 sys.exit(1)
aviau6c853102016-02-26 14:34:41 -0500554
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400555
Maxim Cournoyere55531c2021-03-08 23:05:48 -0500556def has_guix():
557 """Check whether the 'guix' command is available."""
558 with open(os.devnull, 'w') as f:
559 try:
560 subprocess.run(["sh", "-c", "command -v guix"],
561 check=True, stdout=f)
562 except subprocess.CalledProcessError:
563 return False
564 else:
565 return True
566
567
aviau6c853102016-02-26 14:34:41 -0500568def validate_args(parsed_args):
569 """Validate the args values, exit if error is found"""
570
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400571 # Filter unsupported distributions.
Alexander Schlarbbddc1a22019-12-13 16:02:46 +0100572 supported_distros = [
573 ANDROID_DISTRIBUTION_NAME, OSX_DISTRIBUTION_NAME, IOS_DISTRIBUTION_NAME,
Maxim Cournoyere55531c2021-03-08 23:05:48 -0500574 WIN32_DISTRIBUTION_NAME, 'guix'
Alexander Schlarbbddc1a22019-12-13 16:02:46 +0100575 ] + APT_BASED_DISTROS + DNF_BASED_DISTROS + PACMAN_BASED_DISTROS \
576 + ZYPPER_BASED_DISTROS + FLATPAK_BASED_RUNTIMES
Simon Zeni11ac3492016-06-15 10:07:27 -0400577
Maxim Cournoyerf69e9fa2021-03-08 15:10:11 -0500578 if (parsed_args.distribution == 'no-check'
579 or 'JAMI_BUILD_NO_CHECK' in os.environ):
580 return
581
aviau6c853102016-02-26 14:34:41 -0500582 if parsed_args.distribution not in supported_distros:
Maxim Cournoyerf69e9fa2021-03-08 15:10:11 -0500583 print(f'WARNING: Distribution \'{parsed_args.distribution}\' is not '
584 f'supported. Choose one of: {", ".join(supported_distros)}. '
585 'Alternatively, you may force execution of this script '
586 'by providing the \'--distribution=no-check\' argument or by '
587 'exporting the JAMI_BUILD_NO_CHECK environment variable.',
588 file=sys.stderr)
589 sys.exit(1)
aviau6c853102016-02-26 14:34:41 -0500590
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400591 # The Qt client support will be added incrementally.
592 if parsed_args.qt is not None:
593 supported_qt_distros = [
Maxim Cournoyere55531c2021-03-08 23:05:48 -0500594 'guix',
frisbee-wd36686e2021-01-13 23:45:26 +0530595 WIN32_DISTRIBUTION_NAME
596 ] + APT_BASED_DISTROS + DNF_BASED_DISTROS + PACMAN_BASED_DISTROS
597
598 if parsed_args.distribution not in supported_qt_distros:
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400599 print('Distribution \'{0}\' not supported when building the Qt client.'
600 '\nChoose one of: {1}'.format(
601 parsed_args.distribution, ', '.join(supported_qt_distros)
602 ), file=sys.stderr)
603 sys.exit(1)
604
605 # The windows client can only be built on a Windows 10 host.
606 if parsed_args.distribution == WIN32_DISTRIBUTION_NAME:
607 if platform.release() != '10':
608 print('Windows version must be built on Windows 10')
609 sys.exit(1)
610
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400611
aviau6c853102016-02-26 14:34:41 -0500612def parse_args():
613 ap = argparse.ArgumentParser(description="Ring build tool")
614
615 ga = ap.add_mutually_exclusive_group(required=True)
616 ga.add_argument(
Alexandre Lision53048b22016-04-06 19:34:08 -0400617 '--init', action='store_true',
618 help='Init Ring repository')
619 ga.add_argument(
aviau6c853102016-02-26 14:34:41 -0500620 '--dependencies', action='store_true',
621 help='Install ring build dependencies')
622 ga.add_argument(
623 '--install', action='store_true',
624 help='Build and install Ring')
625 ga.add_argument(
Maxim Cournoyer6b364a92021-03-12 16:26:09 -0500626 '--clean', action='store_true',
627 help='Call "git clean" on every repository of the project'
628 )
629 ga.add_argument(
aviau6c853102016-02-26 14:34:41 -0500630 '--uninstall', action='store_true',
631 help='Uninstall Ring')
632 ga.add_argument(
633 '--run', action='store_true',
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400634 help='Run the Ring daemon and client')
aviau6c853102016-02-26 14:34:41 -0500635 ga.add_argument(
636 '--stop', action='store_true',
637 help='Stop the Ring processes')
638
Hugo Lefeuvreb3bb9562018-07-16 13:36:52 -0400639 ap.add_argument('--distribution')
Alexander Schlarb1a704bb2019-12-13 17:13:01 +0100640 ap.add_argument('--prefix')
aviau6c853102016-02-26 14:34:41 -0500641 ap.add_argument('--static', default=False, action='store_true')
642 ap.add_argument('--global-install', default=False, action='store_true')
Maxim Cournoyer2f250c12021-03-09 11:38:10 -0500643 ap.add_argument('--debug', default=False, action='store_true',
644 help='Build with debug support; run in GDB')
aviau6c853102016-02-26 14:34:41 -0500645 ap.add_argument('--background', default=False, action='store_true')
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400646 ap.add_argument('--no-priv-install', dest='priv_install',
647 default=True, action='store_false')
648 ap.add_argument('--qt', nargs='?', const='', type=str,
ababi3e26f3d2020-12-04 15:16:09 +0100649 help='Build the Qt client with the Qt path supplied')
650 ap.add_argument('--qtver', default=QT5_VERSION,
651 help='Sets the Qt version to build with')
Mohamed Chibani3e80a822021-10-27 10:57:35 -0400652 ap.add_argument('--no-libwrap', dest='no_libwrap',
653 default=False, action='store_true',
654 help='Disable libwrap. Also set --disable-shared option to daemon configure')
aviau6c853102016-02-26 14:34:41 -0500655
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400656 dist = choose_distribution()
Maxim Cournoyerf69e9fa2021-03-08 15:10:11 -0500657
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400658 if dist == WIN32_DISTRIBUTION_NAME:
659 ap.add_argument('--toolset', default=win_toolset_default, type=str,
660 help='Windows use only, specify Visual Studio toolset version')
661 ap.add_argument('--sdk', default=win_sdk_default, type=str,
662 help='Windows use only, specify Windows SDK version')
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400663
aviau6c853102016-02-26 14:34:41 -0500664 parsed_args = ap.parse_args()
Alexandre Lisione3d89bc2016-03-08 11:24:56 -0500665
Maxim Cournoyere55531c2021-03-08 23:05:48 -0500666 if parsed_args.distribution:
Hugo Lefeuvreb3bb9562018-07-16 13:36:52 -0400667 parsed_args.distribution = parsed_args.distribution.lower()
668 else:
Andreas Traczyk5ec47bc2020-08-10 09:32:47 -0400669 parsed_args.distribution = dist
Anthony Léonard789acd42016-09-12 15:06:35 -0400670
aviau6c853102016-02-26 14:34:41 -0500671 validate_args(parsed_args)
672
673 return parsed_args
674
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400675
Alexandre Lisione3d89bc2016-03-08 11:24:56 -0500676def choose_distribution():
677 system = platform.system().lower()
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400678
Alexandre Lisione3d89bc2016-03-08 11:24:56 -0500679 if system == "linux" or system == "linux2":
VietKen6c5ed452016-10-18 17:01:18 -0400680 if os.path.isfile("/etc/arch-release"):
Hugo Lefeuvreb3bb9562018-07-16 13:36:52 -0400681 return "arch"
Maxim Cournoyerf69e9fa2021-03-08 15:10:11 -0500682 try:
683 with open("/etc/os-release") as f:
684 for line in f:
685 k, v = line.split("=")
686 if k.strip() == 'ID':
687 return v.strip().replace('"', '').split(' ')[0]
688 except FileNotFoundError:
Maxim Cournoyere55531c2021-03-08 23:05:48 -0500689 if has_guix():
690 return 'guix'
Maxim Cournoyerf69e9fa2021-03-08 15:10:11 -0500691 return 'Unknown'
Alexandre Lisione3d89bc2016-03-08 11:24:56 -0500692 elif system == "darwin":
Alexandre Lision2adcfaa2017-11-18 11:43:37 -0500693 return OSX_DISTRIBUTION_NAME
Andreas Traczyk0f0d7ff2019-09-02 21:09:17 -0400694 elif system == "windows":
695 return WIN32_DISTRIBUTION_NAME
Alexandre Lisione3d89bc2016-03-08 11:24:56 -0500696
697 return 'Unknown'
698
aviau6c853102016-02-26 14:34:41 -0500699
700def main():
701 parsed_args = parse_args()
702
703 if parsed_args.dependencies:
704 run_dependencies(parsed_args)
705
Alexandre Lision53048b22016-04-06 19:34:08 -0400706 elif parsed_args.init:
707 run_init()
Maxim Cournoyer6b364a92021-03-12 16:26:09 -0500708 elif parsed_args.clean:
709 run_clean()
Alexandre Lision53048b22016-04-06 19:34:08 -0400710
aviau6c853102016-02-26 14:34:41 -0500711 elif parsed_args.install:
712 run_install(parsed_args)
713
714 elif parsed_args.uninstall:
715 run_uninstall(parsed_args)
716
717 elif parsed_args.run:
Maxim Cournoyere55531c2021-03-08 23:05:48 -0500718 if (parsed_args.distribution == 'guix'
719 and 'GUIX_ENVIRONMENT' not in os.environ):
720 if parsed_args.qt is not None:
721 print('FIXME: Qt fails loading QML modules due to '
722 'https://issues.guix.gnu.org/47655')
723 # Relaunch this script, this time in a pure Guix environment.
724 guix_args = ['time-machine', '--channels=guix/channels.scm',
725 '--', 'environment', '--pure',
726 # to allow pulseaudio to connect to an existing server
727 "-E", "XAUTHORITY", "-E", "XDG_RUNTIME_DIR",
728 '--manifest=guix/manifest.scm', '--']
729 args = sys.argv + ['--distribution=guix']
730 print('Running in a guix environment spawned with: guix {}'
731 .format(str.join(' ', guix_args + args)))
732 os.execlp('guix', 'guix', *(guix_args + args))
733 else:
734 run_run(parsed_args)
aviau6c853102016-02-26 14:34:41 -0500735
736 elif parsed_args.stop:
737 run_stop(parsed_args)
738
739
740if __name__ == "__main__":
741 main()