Debian Codegraph @

Makefile

raw symbols SCIP
1 DJANGO_ADMIN := django-admin
2 INSTALL := install
3 PYTHON := python3
4 PYTEST_ARGS :=
5 CP_ARGS := --no-dereference --preserve=mode,timestamps --reflink=auto
6
7 ENABLED_APPS_PATH := $(DESTDIR)/usr/share/freedombox/modules-enabled
8
9 DISABLED_APPS_TO_REMOVE := \
10 apps \
11 coquelicot \
12 diaspora \
13 monkeysphere \
14 owncloud \
15 system \
16 xmpp \
17 disks \
18 udiskie \
19 restore \
20 repro \
21 tahoe \
22 mldonkey \
23 i2p \
24 ttrss \
25 sso
26
27 APP_FILES_TO_REMOVE := $(foreach app,$(DISABLED_APPS_TO_REMOVE),$(ENABLED_APPS_PATH)/$(app))
28
29 REMOVED_FILES := \
30 $(DESTDIR)/etc/apt/preferences.d/50freedombox3.pref \
31 $(DESTDIR)/etc/apache2/sites-available/plinth.conf \
32 $(DESTDIR)/etc/apache2/sites-available/plinth-ssl.conf \
33 $(DESTDIR)/etc/security/access.d/10freedombox-performance.conf \
34 $(DESTDIR)/etc/security/access.d/10freedombox-security.conf
35
36 DIRECTORIES_TO_CREATE := \
37 $(DESTDIR)/var/lib/plinth \
38 $(DESTDIR)/var/lib/plinth/sessions
39
40 STATIC_FILES_DIRECTORY := $(DESTDIR)/usr/share/plinth/static
41 BIN_DIR := $(DESTDIR)/usr/bin
42 LIB_DIR := $(DESTDIR)/usr/lib
43
44 FIND_ARGS := \
45 -not -iname "*.log" \
46 -not -iname "*.pid" \
47 -not -iname "*.py.bak" \
48 -not -iname "*.pyc" \
49 -not -iname "*.pytest_cache" \
50 -not -iname "*.sqlite3" \
51 -not -iname "*.swp" \
52 -not -iname "\#*" \
53 -not -iname ".*" \
54 -not -iname "sessionid*" \
55 -not -iname "~*" \
56 -not -iname "django-secret.key" \
57 -not -iwholename "*/.mypy_cache/*"
58
59
60 ROOT_DATA_FILES := $(shell find data -type f $(FIND_ARGS))
61 MODULE_DATA_FILES := $(shell find $(wildcard plinth/modules/*/data) -type f $(FIND_ARGS))
62
63 update-translations:
64 $(DJANGO_ADMIN) makemessages --all --domain django --keep-pot \
65 --verbosity=1 --ignore conftest.py --ignore doc --ignore build \
66 --ignore htmlcov --ignore screenshots --ignore debian --ignore \
67 actions --ignore preseed --ignore static --ignore data \
68 --settings plinth.settings --pythonpath .
69
70 configure:
71 # Nothing to do
72
73 build:
74 # Compile translations
75 $(DJANGO_ADMIN) compilemessages --verbosity=1
76
77 # Build documentation
78 $(MAKE) -C doc -j 8
79
80 # Build .whl package
81 rm -f dist/plinth-*.whl
82 $(PYTHON) -m build --no-isolation --skip-dependency-check --wheel
83
84 install:
85 # Drop removed apps
86 rm -f $(APP_FILES_TO_REMOVE)
87
88 # Drop removed configuration files
89 rm -f $(REMOVED_FILES)
90
91 # Create data directories
92 for directory in $(DIRECTORIES_TO_CREATE) ; do \
93 $(INSTALL) -d $$directory ; \
94 done
95
96 # Python package
97 temp=$$(mktemp -d) && \
98 lib_dir=$$($(PYTHON) -c 'import sysconfig; print(sysconfig.get_paths(scheme="deb_system")["purelib"])') && \
99 $(PYTHON) -m pip install dist/plinth-*.whl --break-system-packages \
100 --no-deps --no-compile --no-warn-script-location \
101 --ignore-installed --target=$${temp} && \
102 $(INSTALL) -d $(DESTDIR)$${lib_dir} && \
103 rm -rf $(DESTDIR)$${lib_dir}/plinth $(DESTDIR)$${lib_dir}/plinth*.dist-info && \
104 mv $${temp}/plinth $${temp}/plinth*.dist-info $(DESTDIR)$${lib_dir} && \
105 rm -f $(DESTDIR)$${lib_dir}/plinth*.dist-info/licenses/COPYING.md && \
106 rm -f $(DESTDIR)$${lib_dir}/plinth*.dist-info/direct_url.json && \
107 $(INSTALL) -D -t $(BIN_DIR) bin/plinth
108 $(INSTALL) -D -t $(LIB_DIR)/freedombox bin/freedombox-privileged
109 $(INSTALL) -D -t $(BIN_DIR) bin/freedombox-cmd
110 $(INSTALL) -D -t $(BIN_DIR) bin/freedombox-change-password
111
112 # Static web server files
113 rm -rf $(STATIC_FILES_DIRECTORY)
114 $(INSTALL) -d $(STATIC_FILES_DIRECTORY)
115 cp $(CP_ARGS) --recursive static/* $(STATIC_FILES_DIRECTORY)
116
117 # System data files
118 for file in $(ROOT_DATA_FILES) ; do \
119 target=$$(dirname $(DESTDIR)$$(echo $${file} | sed -e 's|^data||')) ; \
120 $(INSTALL) --directory --mode=755 $${target} ; \
121 cp $(CP_ARGS) $${file} $${target} ; \
122 done
123 for file in $(MODULE_DATA_FILES) ; do \
124 target=$$(dirname $(DESTDIR)$$(echo $${file} | sed -e 's|^plinth/modules/[^/]*/data||')) ; \
125 $(INSTALL) --directory --mode=755 $${target} ; \
126 cp $(CP_ARGS) $${file} $${target} ; \
127 done
128
129 # Documentation
130 $(MAKE) -C doc install
131
132 check: check-type check-code check-doc check-tests
133
134 # Run the main test suite
135 check-tests:
136 $(PYTHON) -m pytest $(PYTEST_ARGS)
137
138 # Tests with coverage report
139 check-tests-cov:
140 $(PYTHON) -m pytest $(PYTEST_ARGS) --cov=plinth \
141 --cov-report=html:./htmlcov --cov-report=term
142
143 # Code quality checking using flake8
144 check-code:
145 $(PYTHON) -m flake8 plinth container
146
147 # Static type checking using mypy
148 check-type:
149 $(PYTHON) -m mypy .
150
151 # Use doctest for check the wikiparser in doc directory
152 check-doc:
153 $(PYTHON) -m doctest doc/scripts/wikiparser.py
154
155 clean:
156 make -C doc clean
157 rm -rf Plinth.egg-info
158 find plinth/locale -name *.mo -delete
159
160 define DEVELOP_SERVICE_CONF
161 [Service]
162 Environment=FREEDOMBOX_DEVELOP=1
163 Environment=PYTHONPATH=/freedombox/
164 endef
165 export DEVELOP_SERVICE_CONF
166
167 define DEVELOP_LOGS_SCRIPT
168 #!/usr/bin/bash
169
170 set -e
171 set -x
172
173 journalctl --follow --unit=plinth.service --unit=freedombox-privileged.service
174 endef
175 export DEVELOP_LOGS_SCRIPT
176
177 # Run basic setup for a developer environment (VM or container)
178 provision-dev:
179 # Install newer build dependencies if any
180 apt-get update
181 DEBIAN_FRONTEND=noninteractive apt-get build-dep --yes .
182
183 # Install latest code over .deb
184 $(MAKE) build install
185
186 # Configure privileged and web daemon for development setup
187 mkdir -p /etc/systemd/system/freedombox-privileged.service.d/
188 echo "$$DEVELOP_SERVICE_CONF" > /etc/systemd/system/freedombox-privileged.service.d/develop.conf
189 mkdir -p /etc/systemd/system/plinth.service.d/
190 echo "$$DEVELOP_SERVICE_CONF" > /etc/systemd/system/plinth.service.d/develop.conf
191
192 # Create a command to easily watch service logs
193 echo "$$DEVELOP_LOGS_SCRIPT" > /usr/bin/freedombox-logs
194 chmod 755 /usr/bin/freedombox-logs
195
196 # Reload newer systemd units, ignore failure
197 -systemctl daemon-reload
198
199 # Enable privileged daemon
200 -systemctl stop freedombox-privileged.service
201
202 -test -d /run/systemd/system && \
203 systemctl enable --now freedombox-privileged.socket
204
205 # Enable and restart plinth service if it is running
206 -systemctl enable plinth.service
207 -systemctl restart plinth.service
208
209 # Stop any ongoing upgrade, ignore failure
210 -killall -9 unattended-upgr
211
212 # Fix any broken packages
213 dpkg --configure -a
214 apt-get -f install
215 apt-get update
216
217 # Install new packages needed by essential apps. Don't uninstall
218 # freedombox in case new dependencies conflict with old dependencies
219 apt-mark hold freedombox
220 DEBIAN_FRONTEND=noninteractive apt-get install --no-upgrade --yes \
221 $$(sudo -u plinth ./run --develop --list-dependencies)
222 apt-mark unhold freedombox
223
224 # DNS resolution may be broken by upgrade to systemd-resolved. See
225 # #1079819 and ##1032937.
226 -systemctl restart systemd-resolved
227 -nmcli general reload dns-rc
228
229 # Install additional packages
230 DEBIAN_FRONTEND=noninteractive apt-get install --yes ncurses-term \
231 sshpass bash-completion
232
233 wait-while-first-setup:
234 while [ x$$(curl -k https://localhost/freedombox/status/ 2> /dev/null | \
235 json_pp 2> /dev/null | grep 'is_first_setup_running' | \
236 tr -d '[:space:]' | cut -d':' -f2 ) != 'xfalse' ] ; do \
237 sleep 1; echo -n .; done
238
239 .PHONY: \
240 build \
241 check \
242 check-code \
243 check-doc \
244 check-type \
245 check-tests \
246 check-tests-cov \
247 clean \
248 configure \
249 install \
250 provision \
251 update-translations \
252 wait-while-first-setup