-
Notifications
You must be signed in to change notification settings - Fork 285
/
Makefile
204 lines (161 loc) · 9.4 KB
/
Makefile
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
include config.mk
XAPIDOC=_build/install/default/usr/share/xapi/doc
XAPISDK=_build/install/default/usr/share/xapi/sdk
JOBS = $(shell getconf _NPROCESSORS_ONLN)
PROFILE=release
OPTMANDIR ?= $(OPTDIR)/man/man1/
.PHONY: build clean test doc python format install uninstall coverage
# if we have XAPI_VERSION set then set it in dune-project so we use that version number instead of the one obtained from git
# this is typically used when we're not building from a git repo
build:
[ -z "${XAPI_VERSION}" ] || (sed -i '/(version.*)/d' dune-project && echo "(version ${XAPI_VERSION})" >> dune-project)
# if available use external file, otherwise use built-in, this allows building XAPI without being root
if test -f $(SHAREDIR)/sm/XE_SR_ERRORCODES.xml; then cp $(SHAREDIR)/sm/XE_SR_ERRORCODES.xml ocaml/sdk-gen/csharp/XE_SR_ERRORCODES.xml; fi
dune build @ocaml/idl/update-dm-lifecycle -j $(JOBS) --profile=$(PROFILE) --auto-promote || dune build @ocaml/idl/update-dm-lifecycle -j $(JOBS) --profile=$(PROFILE) --auto-promote
dune build -j $(JOBS) --profile=$(PROFILE) @install @ocaml/xapi-storage/python/xapi/storage/api/v5/python @ocaml/xapi-doc @ocaml/sdk-gen/sdkgen
# Quickly verify that the code compiles, without actually building it
check:
dune build @check -j $(JOBS)
coverage:
dune runtest --instrument-with bisect_ppx --force --profile=$(RELEASE) -j $(JOBS)
bisect-ppx-report html
bisect-ppx-report summary --per-file
clean:
dune clean
lint:
dune build @python
pylint --disable=line-too-long,too-few-public-methods,unused-argument,no-self-use,invalid-name,broad-except,protected-access,redefined-builtin,too-many-lines,wildcard-import,too-many-branches,too-many-arguments,unused-wildcard-import,raising-format-tuple,too-many-statements,duplicate-code _build/default/xapi-storage/python/xapi/storage/api/v5/*.py
pycodestyle --ignore=E501 _build/default/xapi-storage/python/xapi/storage/api/v5/*.py
# ulimit -S -t <N>
# Set a soft CPU time quota which will kill processes with SIGXCPU
# This will in preference kill children of dune that consume CPU time (e.g. a stuck test),
# and not dune itself (which should consume little CPU time when it just waits for subprocesses)
# However it won't kill idle processes (e.g. a test sleeping and waiting for an event that never arrives)
# sleep <N> && ps
# Prints a process tree once the timeout is reached to identify any sleeping processes that are stuck
# (if we send 'dune' a SIGINT or SIGTERM it'd kill all subprocesses but won't say which ones were running and since when!)
# -e: prints all processes
# -ww: disables line length restrictions
# -ly: prints additional columns, e.g. WCHAN which shows currently active syscall
# -F: prints process start time and CPU time, useful in identifying which test got started recently,
# and which one was running for a while
# --forest prints a process tree
# timeout --foreground <M> dune
# Sends a SIGTERM to dune after N seconds. This should print any pending buffered output, but won't tell us which processes were still running
# The timeout used here should be > timeout in ulimit && ps to allow time for subprocesses to terminate first
# ulimit -n <NFILES>
# By default the ulimit on some systems is very large (e.g. Fedora39 distrobox 1048576)
# which causes some tests to take very long to run (e.g. forkexec tests which loop through and close all fds up to limit)
TEST_TIMEOUT=600
TEST_TIMEOUT2=1200
test:
ulimit -S -t $(TEST_TIMEOUT); \
ulimit -n 2048; \
(sleep $(TEST_TIMEOUT) && ps -ewwlyF --forest)& \
PSTREE_SLEEP_PID=$$!; \
trap "kill $${PSTREE_SLEEP_PID}" INT TERM EXIT; \
timeout --foreground $(TEST_TIMEOUT2) \
dune build --profile=$(PROFILE) --error-reporting=twice -j $(JOBS) @runtest @runtest-python
stresstest:
dune build @stresstest --profile=$(PROFILE) --no-buffer -j $(JOBS)
# check that the IDL hash is current
schema:
dune runtest ocaml/idl
doc:
dune build --profile=$(PROFILE) @xapi-doc
sdk:
dune build --profile=$(PROFILE) @sdkgen xapi-sdk.install @ocaml/sdk-gen/install
.PHONY: sdk-build-c
sdk-build-c: sdk
cd _build/install/default/share/c && make clean && make -j $(JOBS)
.PHONY: sdk-build-java
sdk-build-java: sdk
cd _build/install/default/share/java && mvn -f xen-api/pom.xml -B clean package install -Drevision=0.0
python:
$(MAKE) -C python3/examples build
doc-json: doc
format:
dune build @fmt --auto-promote
.PHONY: quality-gate
quality-gate:
./quality-gate.sh
.PHONY: install-scripts install-python3 install-dune1 install-dune2 install-dune3 install-dune4 install-extra
install-scripts:
$(MAKE) -C scripts install
install-python3:
$(MAKE) -C python3 install
install-parallel: install-dune1 install-dune2 install-dune3 install-dune4 install-scripts install-python3 install-extra
install-extra:
mkdir -p $(DESTDIR)$(OPTDIR)/bin
mkdir -p $(DESTDIR)$(OPTMANDIR)
mkdir -p $(DESTDIR)$(LIBEXECDIR)
mkdir -p $(DESTDIR)$(OPTDIR)/debug
mkdir -p $(DESTDIR)/usr/bin
mkdir -p $(DESTDIR)/usr/libexec/xapi
mkdir -p $(DESTDIR)$(MANDIR)/man1
mkdir -p $(DESTDIR)/etc
mkdir -p $(DESTDIR)/etc/bash_completion.d
# ocaml/xapi
scripts/install.sh 755 ocaml/quicktest/quicktest $(DESTDIR)$(OPTDIR)/debug
# ocaml/xe-cli
ln -sf $(OPTDIR)/bin/xe $(DESTDIR)/usr/bin/xe
scripts/install.sh 755 ocaml/xe-cli/bash-completion $(DESTDIR)/etc/bash_completion.d/xe
# rrd2csv
scripts/install.sh 644 ocaml/rrd2csv/man/rrd2csv.1.man $(DESTDIR)$(OPTMANDIR)/rrd2csv.1
# rrdd-plugins
install -D -m 644 ocaml/xcp-rrdd/bugtool-plugin/rrdd-plugins.xml $(DESTDIR)$(ETCXENDIR)/bugtool/xcp-rrdd-plugins.xml
install -D -m 644 ocaml/xcp-rrdd/bugtool-plugin/rrdd-plugins/stuff.xml $(DESTDIR)$(ETCXENDIR)/bugtool/xcp-rrdd-plugins/stuff.xml
install -D -m 755 ocaml/xcp-rrdd/bin/rrdp-scripts/sysconfig-rrdd-plugins $(DESTDIR)/etc/sysconfig/xcp-rrdd-plugins
install -D -m 644 ocaml/xcp-rrdd/bin/rrdp-scripts/logrotate-rrdd-plugins $(DESTDIR)/etc/logrotate.d/xcp-rrdd-plugins
# vhd-tool
install -m 644 ocaml/vhd-tool/cli/sparse_dd.conf $(DESTDIR)/etc/sparse_dd.conf
# xenopsd
install -D ./ocaml/xenopsd/scripts/xen-backend.rules $(DESTDIR)/$(ETCDIR)/udev/rules.d/xen-backend.rules
install -D ./ocaml/xenopsd/scripts/qemu-wrapper $(DESTDIR)/$(QEMU_WRAPPER_DIR)/qemu-wrapper
install -D ./ocaml/xenopsd/scripts/swtpm-wrapper $(DESTDIR)/$(QEMU_WRAPPER_DIR)/swtpm-wrapper
install -D ./ocaml/xenopsd/scripts/pygrub-wrapper $(DESTDIR)/$(QEMU_WRAPPER_DIR)/pygrub-wrapper
DESTDIR=$(DESTDIR) SBINDIR=$(SBINDIR) QEMU_WRAPPER_DIR=$(QEMU_WRAPPER_DIR) XENOPSD_LIBEXECDIR=$(XENOPSD_LIBEXECDIR) ETCDIR=$(ETCDIR) ./ocaml/xenopsd/scripts/make-custom-xenopsd.conf
# common flags and packages for 'dune install' and 'dune uninstall'
DUNE_IU_PACKAGES1=-j $(JOBS) --destdir=$(DESTDIR) --prefix=$(PREFIX) --libdir=$(LIBDIR) --mandir=$(MANDIR)
DUNE_IU_PACKAGES1+=--libexecdir=$(XENOPSD_LIBEXECDIR) --datadir=$(SDKDIR)
DUNE_IU_PACKAGES1+=xapi-client xapi-schema xapi-consts xapi-cli-protocol xapi-datamodel xapi-types
DUNE_IU_PACKAGES1+=xen-api-client xen-api-client-lwt rrdd-plugin rrd-transport
DUNE_IU_PACKAGES1+=gzip http-lib pciutil sexpr stunnel uuid xml-light2 zstd xapi-compression safe-resources
DUNE_IU_PACKAGES1+=message-switch message-switch-cli message-switch-core message-switch-lwt
DUNE_IU_PACKAGES1+=message-switch-unix xapi-idl forkexec xapi-forkexecd xapi-storage xapi-storage-script xapi-storage-cli
DUNE_IU_PACKAGES1+=xapi-nbd varstored-guard xapi-log xapi-open-uri xapi-tracing xapi-tracing-export xapi-expiry-alerts cohttp-posix
DUNE_IU_PACKAGES1+=xapi-rrd xapi-inventory clock xapi-sdk
DUNE_IU_PACKAGES1+=xapi-stdext-date xapi-stdext-encodings xapi-stdext-pervasives xapi-stdext-std xapi-stdext-threads xapi-stdext-unix xapi-stdext-zerocheck xapi-tools
install-dune1:
# dune can install libraries and several other files into the right locations
dune install $(DUNE_IU_PACKAGES1)
DUNE_IU_PACKAGES2=-j $(JOBS) --destdir=$(DESTDIR) --prefix=$(OPTDIR) --libdir=$(LIBDIR) --mandir=$(MANDIR) --libexecdir=$(OPTDIR)/libexec --datadir=$(DOCDIR) xapi xe
install-dune2:
dune install $(DUNE_IU_PACKAGES2)
DUNE_IU_PACKAGES3=-j $(JOBS) --destdir=$(DESTDIR) --prefix=$(OPTDIR) --libdir=$(LIBDIR) --mandir=$(MANDIR) --libexecdir=$(OPTDIR)/libexec --bindir=$(OPTDIR)/debug --datadir=$(OPTDIR)/debug xapi-debug
install-dune3:
dune install $(DUNE_IU_PACKAGES3)
DUNE_IU_PACKAGES4=-j $(JOBS) --destdir=$(DESTDIR) --prefix=$(PREFIX) --libdir=$(LIBDIR) --libexecdir=/usr/libexec --mandir=$(MANDIR) vhd-tool
install-dune4:
dune install $(DUNE_IU_PACKAGES4)
install:
$(MAKE) -j $(JOBS) install-parallel
# wsproxy
mv $(DESTDIR)/usr/bin/wsproxy $(DESTDIR)$(LIBEXECDIR)/wsproxy
(cd $(DESTDIR)/$(XENOPSD_LIBEXECDIR) && ln -sf pvs-proxy-ovs-setup setup-pvs-proxy-rules)
chmod +x $(DESTDIR)$(DOCDIR)/doc-convert.sh
# backward compat with existing specfile, to be removed after it is updated
find $(DESTDIR) -name '*.cmxs' -delete
for pkg in xapi-debug xapi xe xapi-tools xapi-sdk vhd-tool; do for f in CHANGELOG LICENSE README.markdown; do rm $(DESTDIR)$(OPTDIR)/doc/$$pkg/$$f $(DESTDIR)$(PREFIX)/doc/$$pkg/$$f -f; done; for f in META dune-package opam; do rm $(DESTDIR)$(LIBDIR)/$$pkg/$$f -f; done; done;
uninstall:
# only removes what was installed with `dune install`
dune uninstall $(DUNE_IU_PACKAGES1)
dune uninstall $(DUNE_IU_PACKAGES2)
dune uninstall $(DUNE_IU_PACKAGES3)
dune uninstall $(DUNE_IU_PACKAGES4)
compile_flags.txt: Makefile
(ocamlc -config-var ocamlc_cflags;\
ocamlc -config-var ocamlc_cppflags;\
echo -I$(shell ocamlc -where);\
echo -Wall -Wextra -Wstrict-prototypes -D_FORTIFY_SOURCE=2\
) | xargs -n1 echo >$@