tests/docker: add python3-setuptools the docker images
[qemu.git] / tests / docker / Makefile.include
1 # Makefile for Docker tests
2
3 .PHONY: docker docker-test docker-clean docker-image docker-qemu-src
4
5 HOST_ARCH = $(if $(ARCH),$(ARCH),$(shell uname -m))
6
7 DOCKER_SUFFIX := .docker
8 DOCKER_FILES_DIR := $(SRC_PATH)/tests/docker/dockerfiles
9 # we don't run tests on intermediate images (used as base by another image)
10 DOCKER_PARTIAL_IMAGES := debian9 debian10 debian11
11 DOCKER_PARTIAL_IMAGES += debian9-mxe debian-bootstrap
12 DOCKER_IMAGES := $(sort $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker))))
13 DOCKER_TARGETS := $(patsubst %,docker-image-%,$(DOCKER_IMAGES))
14 # Use a global constant ccache directory to speed up repetitive builds
15 DOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache
16 DOCKER_REGISTRY := $(if $(REGISTRY),$(REGISTRY),registry.gitlab.com/qemu-project/qemu)
17
18 DOCKER_TESTS := $(notdir $(shell \
19         find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f))
20
21 DOCKER_TOOLS := travis
22
23 ENGINE := auto
24
25 DOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py --engine $(ENGINE)
26
27 TESTS ?= %
28 IMAGES ?= %
29
30 CUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$)
31 DOCKER_SRC_COPY := $(BUILD_DIR)/docker-src.$(CUR_TIME)
32
33 .DELETE_ON_ERROR: $(DOCKER_SRC_COPY)
34 $(DOCKER_SRC_COPY):
35         @mkdir $@
36         $(if $(SRC_ARCHIVE), \
37                 $(call quiet-command, cp "$(SRC_ARCHIVE)" $@/qemu.tar, \
38                         "CP", "$@/qemu.tar"), \
39                 $(call quiet-command, cd $(SRC_PATH) && scripts/archive-source.sh $@/qemu.tar, \
40                         "GEN", "$@/qemu.tar"))
41         $(call quiet-command, cp $(SRC_PATH)/tests/docker/run $@/run, \
42                 "COPY","RUNNER")
43
44 docker-qemu-src: $(DOCKER_SRC_COPY)
45
46 docker-image: ${DOCKER_TARGETS}
47
48 # General rule for building docker images. If we are a sub-make
49 # invoked with SKIP_DOCKER_BUILD we still check the image is up to date
50 # though
51 ifdef SKIP_DOCKER_BUILD
52 docker-image-%: $(DOCKER_FILES_DIR)/%.docker
53         $(call quiet-command, \
54                 $(DOCKER_SCRIPT) check --quiet qemu/$* $<, \
55                 "CHECK", "$*")
56 else
57 docker-image-%: $(DOCKER_FILES_DIR)/%.docker
58         $(call quiet-command,\
59                 $(DOCKER_SCRIPT) build -t qemu/$* -f $< \
60                 $(if $V,,--quiet) \
61                 $(if $(NOCACHE),--no-cache, \
62                         $(if $(DOCKER_REGISTRY),--registry $(DOCKER_REGISTRY))) \
63                 $(if $(NOUSER),,--add-current-user) \
64                 $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))\
65                 $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\
66                 "BUILD","$*")
67
68 # Special rule for debootstraped binfmt linux-user images
69 docker-binfmt-image-debian-%: $(DOCKER_FILES_DIR)/debian-bootstrap.docker
70         $(if $(EXECUTABLE),,\
71                 $(error EXECUTABLE not set, debootstrap of debian-$* would fail))
72         $(if $(DEB_ARCH),,\
73                 $(error DEB_ARCH not set, debootstrap of debian-$* would fail))
74         $(if $(DEB_TYPE),,\
75                 $(error DEB_TYPE not set, debootstrap of debian-$* would fail))
76         $(if $(wildcard $(EXECUTABLE)),                                         \
77                 $(call quiet-command,                                           \
78                         DEB_ARCH=$(DEB_ARCH)                                    \
79                         DEB_TYPE=$(DEB_TYPE)                                    \
80                         $(if $(DEB_URL),DEB_URL=$(DEB_URL),)                    \
81                         $(DOCKER_SCRIPT) build -t qemu/debian-$* -f $<          \
82                         $(if $V,,--quiet) $(if $(NOCACHE),--no-cache)           \
83                         $(if $(NOUSER),,--add-current-user)                     \
84                         $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))       \
85                         $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)), \
86                         "BUILD","binfmt debian-$* (debootstrapped)"),           \
87                 $(call quiet-command,                                           \
88                         $(DOCKER_SCRIPT) check --quiet qemu/debian-$* $< ||     \
89                         { echo "You will need to build $(EXECUTABLE)"; exit 1;},\
90                         "CHECK", "debian-$* exists"))
91
92 endif
93
94 # Enforce dependencies for composite images
95 docker-image-debian9-mxe: docker-image-debian9
96 ifeq ($(HOST_ARCH),x86_64)
97 docker-image-debian-amd64: docker-image-debian10
98 DOCKER_PARTIAL_IMAGES += debian-amd64-cross
99 else
100 docker-image-debian-amd64-cross: docker-image-debian10
101 DOCKER_PARTIAL_IMAGES += debian-amd64
102 endif
103 docker-image-debian-win32-cross: docker-image-debian9-mxe
104 docker-image-debian-win64-cross: docker-image-debian9-mxe
105
106 # For non-x86 hosts not all cross-compilers have been packaged
107 ifneq ($(HOST_ARCH),x86_64)
108 DOCKER_PARTIAL_IMAGES += debian-mips-cross debian-mipsel-cross debian-mips64el-cross
109 DOCKER_PARTIAL_IMAGES += debian-ppc64el-cross
110 DOCKER_PARTIAL_IMAGES += debian-s390x-cross
111 DOCKER_PARTIAL_IMAGES += debian-win32-cross debian-win64-cross
112 DOCKER_PARTIAL_IMAGES += fedora travis
113 endif
114
115 docker-image-debian-alpha-cross: docker-image-debian10
116 docker-image-debian-arm64-cross: docker-image-debian10
117 docker-image-debian-armel-cross: docker-image-debian10
118 docker-image-debian-armhf-cross: docker-image-debian10
119 docker-image-debian-hppa-cross: docker-image-debian10
120 docker-image-debian-m68k-cross: docker-image-debian10
121 docker-image-debian-mips-cross: docker-image-debian10
122 docker-image-debian-mips64-cross: docker-image-debian10
123 docker-image-debian-mips64el-cross: docker-image-debian10
124 docker-image-debian-mipsel-cross: docker-image-debian10
125 docker-image-debian-powerpc-cross: docker-image-debian10
126 docker-image-debian-ppc64-cross: docker-image-debian10
127 docker-image-debian-ppc64el-cross: docker-image-debian10
128 docker-image-debian-riscv64-cross: docker-image-debian10
129 docker-image-debian-s390x-cross: docker-image-debian10
130 docker-image-debian-sh4-cross: docker-image-debian10
131 docker-image-debian-sparc64-cross: docker-image-debian10
132
133 docker-image-travis: NOUSER=1
134
135 # Specialist build images, sometimes very limited tools
136 docker-image-debian-tricore-cross: docker-image-debian9
137 docker-image-debian-all-test-cross: docker-image-debian10
138 docker-image-debian-arm64-test-cross: docker-image-debian11
139
140 # These images may be good enough for building tests but not for test builds
141 DOCKER_PARTIAL_IMAGES += debian-alpha-cross
142 DOCKER_PARTIAL_IMAGES += debian-arm64-test-cross
143 DOCKER_PARTIAL_IMAGES += debian-hppa-cross
144 DOCKER_PARTIAL_IMAGES += debian-m68k-cross debian-mips64-cross
145 DOCKER_PARTIAL_IMAGES += debian-powerpc-cross debian-ppc64-cross
146 DOCKER_PARTIAL_IMAGES += debian-riscv64-cross
147 DOCKER_PARTIAL_IMAGES += debian-sh4-cross debian-sparc64-cross
148 DOCKER_PARTIAL_IMAGES += debian-tricore-cross
149 DOCKER_PARTIAL_IMAGES += debian-xtensa-cross
150 DOCKER_PARTIAL_IMAGES += fedora-i386-cross fedora-cris-cross
151
152 # Rules for building linux-user powered images
153 #
154 # These are slower than using native cross compiler setups but can
155 # work around issues with poorly working multi-arch systems and broken
156 # packages.
157
158 # Expand all the pre-requistes for each docker image and test combination
159 $(foreach i,$(filter-out $(DOCKER_PARTIAL_IMAGES),$(DOCKER_IMAGES)), \
160         $(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \
161                 $(eval .PHONY: docker-$t@$i) \
162                 $(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \
163         ) \
164         $(foreach t,$(DOCKER_TESTS), \
165                 $(eval docker-all-tests: docker-$t@$i) \
166                 $(eval docker-$t: docker-$t@$i) \
167         ) \
168 )
169
170 docker:
171         @echo 'Build QEMU and run tests inside Docker or Podman containers'
172         @echo
173         @echo 'Available targets:'
174         @echo
175         @echo '    docker:              Print this help.'
176         @echo '    docker-all-tests:    Run all image/test combinations.'
177         @echo '    docker-TEST:         Run "TEST" on all image combinations.'
178         @echo '    docker-clean:        Kill and remove residual docker testing containers.'
179         @echo '    docker-TEST@IMAGE:   Run "TEST" in container "IMAGE".'
180         @echo '                         Note: "TEST" is one of the listed test name,'
181         @echo '                         or a script name under $$QEMU_SRC/tests/docker/;'
182         @echo '                         "IMAGE" is one of the listed container name.'
183         @echo '    docker-image:        Build all images.'
184         @echo '    docker-image-IMAGE:  Build image "IMAGE".'
185         @echo '    docker-run:          For manually running a "TEST" with "IMAGE".'
186         @echo
187         @echo 'Available container images:'
188         @echo '    $(DOCKER_IMAGES)'
189 ifneq ($(DOCKER_USER_IMAGES),)
190         @echo
191         @echo 'Available linux-user images (docker-binfmt-image-debian-%):'
192         @echo '    $(DOCKER_USER_IMAGES)'
193 endif
194         @echo
195         @echo 'Available tests:'
196         @echo '    $(DOCKER_TESTS)'
197         @echo
198         @echo 'Available tools:'
199         @echo '    $(DOCKER_TOOLS)'
200         @echo
201         @echo 'Special variables:'
202         @echo '    TARGET_LIST=a,b,c    Override target list in builds.'
203         @echo '    EXTRA_CONFIGURE_OPTS="..."'
204         @echo '                         Extra configure options.'
205         @echo '    IMAGES="a b c ..":   Filters which images to build or run.'
206         @echo '    TESTS="x y z .."     Filters which tests to run (for docker-test).'
207         @echo '    J=[0..9]*            Overrides the -jN parameter for make commands'
208         @echo '                         (default is 1)'
209         @echo '    DEBUG=1              Stop and drop to shell in the created container'
210         @echo '                         before running the command.'
211         @echo '    NETWORK=1            Enable virtual network interface with default backend.'
212         @echo '    NETWORK=$$BACKEND     Enable virtual network interface with $$BACKEND.'
213         @echo '    NOUSER               Define to disable adding current user to containers passwd.'
214         @echo '    NOCACHE=1            Ignore cache when build images.'
215         @echo '    EXECUTABLE=<path>    Include executable in image.'
216         @echo '    EXTRA_FILES="<path> [... <path>]"'
217         @echo '                         Include extra files in image.'
218         @echo '    ENGINE=auto/docker/podman'
219         @echo '                         Specify which container engine to run.'
220         @echo '    REGISTRY=url         Cache builds from registry (default:$(DOCKER_REGISTRY))'
221
222 # This rule if for directly running against an arbitrary docker target.
223 # It is called by the expanded docker targets (e.g. make
224 # docker-test-foo@bar) which will do additional verification.
225 #
226 # For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64
227 #
228 docker-run: docker-qemu-src
229         @mkdir -p "$(DOCKER_CCACHE_DIR)"
230         @if test -z "$(IMAGE)" || test -z "$(TEST)"; \
231                 then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \
232         fi
233         $(if $(EXECUTABLE),                                             \
234                 $(call quiet-command,                                   \
235                         $(DOCKER_SCRIPT) update                         \
236                         $(IMAGE) $(EXECUTABLE),                         \
237                         "  COPYING $(EXECUTABLE) to $(IMAGE)"))
238         $(call quiet-command,                                           \
239                 $(DOCKER_SCRIPT) run                                    \
240                         $(if $(NOUSER),,--run-as-current-user)          \
241                         --security-opt seccomp=unconfined               \
242                         $(if $V,,--rm)                                  \
243                         $(if $(DEBUG),-ti,)                             \
244                         $(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \
245                         -e TARGET_LIST=$(subst $(SPACE),$(COMMA),$(TARGET_LIST))        \
246                         -e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \
247                         -e V=$V -e J=$J -e DEBUG=$(DEBUG)               \
248                         -e SHOW_ENV=$(SHOW_ENV)                         \
249                         $(if $(NOUSER),,                                \
250                                 -e CCACHE_DIR=/var/tmp/ccache           \
251                                 -v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \
252                         )                                               \
253                         -v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
254                         $(IMAGE)                                        \
255                         /var/tmp/qemu/run                               \
256                         $(TEST), "  RUN $(TEST) in ${IMAGE}")
257         $(call quiet-command, rm -r $(DOCKER_SRC_COPY), \
258                 "  CLEANUP $(DOCKER_SRC_COPY)")
259
260 # Run targets:
261 #
262 # Of the form docker-TEST-FOO@IMAGE-BAR which will then be expanded into a call to "make docker-run"
263 docker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/')
264 docker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/')
265 docker-run-%:
266         @$(MAKE) docker-run TEST=$(CMD) IMAGE=qemu/$(IMAGE)
267
268 docker-clean:
269         $(call quiet-command, $(DOCKER_SCRIPT) clean)