forked from canonical/craft-parts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
347 lines (325 loc) · 11 KB
/
Makefile
File metadata and controls
347 lines (325 loc) · 11 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
PROJECT=craft_parts
# Define when more than the main package tree requires coverage
# like is the case for snapcraft (snapcraft and snapcraft_legacy):
# COVERAGE_SOURCE="starcraft"
UV_TEST_GROUPS := "--group=dev"
UV_DOCS_GROUPS := "--group=docs"
UV_LINT_GROUPS := "--group=lint" "--group=types"
UV_TICS_GROUPS := "--group=tics"
# If you have dev dependencies that depend on your distro version, uncomment these:
ifneq ($(wildcard /etc/os-release),)
include /etc/os-release
endif
ifdef VERSION_CODENAME
UV_TEST_GROUPS += "--group=dev-$(VERSION_CODENAME)"
UV_DOCS_GROUPS += "--group=dev-$(VERSION_CODENAME)"
UV_LINT_GROUPS += "--group=dev-$(VERSION_CODENAME)"
UV_TICS_GROUPS += "--group=dev-$(VERSION_CODENAME)"
endif
include common.mk
.PHONY: format
format: format-ruff format-codespell format-prettier format-pre-commit ## Run all automatic formatters
.PHONY: lint
lint: lint-ruff lint-codespell lint-mypy lint-prettier lint-pyright lint-shellcheck lint-docs lint-twine lint-uv-lockfile ## Run all linters
.PHONY: pack
pack: pack-pip ## Build all packages
.PHONY: pack-snap
pack-snap: snap/snapcraft.yaml ##- Build snap package
ifeq ($(shell which snapcraft),)
sudo snap install --classic snapcraft
endif
snapcraft pack
# Find dependencies that need installing
APT_PACKAGES :=
ifeq ($(wildcard /usr/include/libxml2/libxml/xpath.h),)
APT_PACKAGES += libxml2-dev
endif
ifeq ($(wildcard /usr/include/libxslt/xslt.h),)
APT_PACKAGES += libxslt1-dev
endif
ifeq ($(wildcard /usr/share/doc/intltool/copyright),)
APT_PACKAGES += intltool
endif
ifeq ($(wildcard /usr/share/doc/fuse-overlayfs/copyright),)
APT_PACKAGES += fuse-overlayfs
endif
ifeq ($(wildcard /usr/share/doc/socat/copyright),)
APT_PACKAGES += socat
endif
ifeq ($(wildcard /usr/share/doc/findutils/copyright),)
APT_PACKAGES += findutils
endif
ifeq ($(wildcard /usr/share/doc/python3-venv/copyright),)
APT_PACKAGES += python3-venv
endif
ifeq ($(wildcard /usr/share/doc/mmdebstrap/copyright),)
APT_PACKAGES += mmdebstrap
endif
# Dependencies for sources
ifeq ($(wildcard /usr/share/doc/p7zip-full/copyright),)
APT_PACKAGES += p7zip-full
endif
ifeq ($(wildcard /usr/share/doc/curl/copyright),)
APT_PACKAGES += curl
endif
ifeq ($(wildcard /usr/share/doc/git/copyright),)
APT_PACKAGES += git
endif
ifeq ($(wildcard /usr/share/doc/rpm/copyright),)
APT_PACKAGES += rpm
endif
# Java tools - Used for Java plugin integration tests.
# We need *a* jdk for our unit tests to succeed. Use 17 because a unit test looks for
# it specifically.
ifeq ($(wildcard /usr/share/doc/openjdk-17-jdk/copyright),)
APT_PACKAGES += openjdk-17-jdk
endif
ifneq ($(NO_JAVA),1) # Allow setting NO_JAVA=1 to avoid installing java deps
ifeq ($(wildcard /usr/share/doc/default-jdk/copyright),)
APT_PACKAGES += default-jdk
endif
ifeq ($(wildcard /usr/share/doc/openjdk-8-jdk-headless/copyright),)
APT_PACKAGES += openjdk-8-jdk-headless
endif
ifeq ($(wildcard /usr/share/doc/openjdk-11-jdk/copyright),)
APT_PACKAGES += openjdk-11-jdk
endif
ifeq ($(wildcard /usr/share/doc/openjdk-21-jdk/copyright),)
APT_PACKAGES += openjdk-21-jdk
endif
ifeq ($(wildcard /usr/share/doc/tinyproxy/copyright),)
APT_PACKAGES += tinyproxy
endif
# Maven
ifeq ($(wildcard /usr/share/doc/maven/copyright),)
APT_PACKAGES += maven
endif
ifeq ($(wildcard /usr/share/doc/libmaven-resources-plugin-java/copyright),)
APT_PACKAGES += libmaven-resources-plugin-java
endif
ifeq ($(wildcard /usr/share/doc/libmaven-compiler-plugin-java/copyright),)
APT_PACKAGES += libmaven-compiler-plugin-java
endif
ifeq ($(wildcard /usr/share/doc/libmaven-jar-plugin-java/copyright),)
APT_PACKAGES += libmaven-jar-plugin-java
endif
ifeq ($(wildcard /usr/share/doc/libmaven-install-plugin-java/copyright),)
APT_PACKAGES += libmaven-install-plugin-java
endif
ifeq ($(wildcard /usr/share/doc/libmaven-deploy-plugin-java/copyright),)
APT_PACKAGES += libmaven-deploy-plugin-java
endif
ifeq ($(wildcard /usr/share/doc/libmaven-shade-plugin-java/copyright),)
APT_PACKAGES += libmaven-shade-plugin-java
endif
ifeq ($(wildcard /usr/share/doc/libsurefire-java/copyright),)
APT_PACKAGES += libsurefire-java
endif
endif
# Python tools - used for python plugin integration tests.
ifneq ($(NO_PYTHON),1)
ifeq ($(wildcard /usr/share/doc/python3-poetry/copyright),)
APT_PACKAGES += python3-poetry
endif
ifeq ($(wildcard /usr/share/doc/python3-dev/copyright),)
APT_PACKAGES += python3-dev
endif
# Poetry 2+ removes the export subcommand and requires you to get a plugin for it
# However, jammy uses an older poetry version that still has that subcommand
ifneq ($(VERSION_CODENAME),jammy)
ifeq ($(wildcard /usr/share/doc/python3-poetry-plugin-export/copyright),)
APT_PACKAGES += python3-poetry-plugin-export
endif
# On Jammy, we can use pip to install meson. Everywhere else we install it through apt.
ifeq ($(wildcard /usr/share/doc/meson/copyright),)
APT_PACKAGES += meson
endif
endif
endif
# Colcon is not available in apt on jammy or focal.
ifeq ($(filter $(VERSION_CODENAME),jammy focal),)
ifeq ($(wildcard /usr/share/doc/colcon/copyright),)
APT_PACKAGES += colcon
endif
ifeq ($(wildcard /usr/share/doc/python3-colcon-core/),)
APT_PACKAGES += python3-colcon-core
endif
ifeq ($(wildcard /usr/share/doc/python3-colcon-cmake/),)
APT_PACKAGES += python3-colcon-cmake
endif
ifeq ($(wildcard /usr/share/doc/python3-colcon-package-selection/),)
APT_PACKAGES += python3-colcon-package-selection
endif
ifeq ($(wildcard /usr/share/doc/python3-colcon-python-setup-py/),)
APT_PACKAGES += python3-colcon-python-setup-py
endif
ifeq ($(wildcard /usr/share/doc/python3-colcon-parallel-executor/),)
APT_PACKAGES += python3-colcon-parallel-executor
endif
endif
# Tools needed for plugin integration tests that aren't java or python
ifneq ($(NO_PLUGIN),1)
ifeq ($(wildcard /usr/share/doc/automake/copyright),)
APT_PACKAGES += automake
endif
ifeq ($(wildcard /usr/share/doc/autopoint/copyright),)
APT_PACKAGES += autopoint
endif
ifeq ($(wildcard /usr/share/doc/cargo/copyright),)
# Cargo may be installed by other means, like the rustup snap.
ifeq ($(shell which cargo),)
# Particularly for CI, the apt version is preferred since it's the disto's "native" version.
APT_PACKAGES += cargo
endif
endif
ifeq ($(wildcard /usr/share/doc/cmake/copyright),)
APT_PACKAGES += cmake
endif
# bazel-bootstrap is not available in apt on focal.
ifeq ($(filter $(VERSION_CODENAME),focal),)
ifeq ($(wildcard /usr/share/doc/bazel-bootstrap/copyright),)
APT_PACKAGES += bazel-bootstrap
endif
endif
# Ruby
ifeq ($(wildcard /usr/share/doc/ruby/copyright),)
APT_PACKAGES += ruby
endif
ifeq ($(wildcard /usr/share/doc/ruby-bundler/copyright),)
APT_PACKAGES += ruby-bundler
endif
# all the packages ruby-install wants to use to build mruby
# https://github.com/postmodern/ruby-install/blob/master/share/ruby-install/mruby/dependencies.sh
ifeq ($(wildcard /usr/share/doc/build-essential/copyright),)
APT_PACKAGES += build-essential
endif
ifeq ($(wildcard /usr/share/doc/bison/copyright),)
APT_PACKAGES += bison
endif
# We'll check for any dotnet SDK, but install dotnet 8 since that version is common to
# 22.04 -> 25.10 (and possibly 26.04).
# On focal, we'll get the snap instead.
ifeq ($(wildcard /usr/share/doc/dotnet-sdk-*/copyright),)
ifneq ($(UBUNTU_CODENAME),focal)
APT_PACKAGES += dotnet-sdk-8.0
endif
endif
ifeq ($(wildcard /usr/share/doc/gcc/copyright),)
APT_PACKAGES += gcc
endif
ifeq ($(wildcard /usr/share/doc/meson/copyright),)
APT_PACKAGES += meson
endif
ifeq ($(wildcard /usr/share/doc/pkg-config/copyright),)
APT_PACKAGES += pkg-config
endif
ifeq ($(wildcard /usr/share/doc/ninja-build/copyright),)
APT_PACKAGES += ninja-build
endif
ifeq ($(wildcard /usr/share/doc/scons/copyright),)
APT_PACKAGES += scons
endif
# Specifically used by the autotools plugin tests.
ifeq ($(wildcard /usr/share/doc/gperf/copyright),)
APT_PACKAGES += gperf
endif
ifeq ($(wildcard /usr/share/doc/help2man/copyright),)
APT_PACKAGES += help2man
endif
ifeq ($(wildcard /usr/share/doc/texinfo/copyright),)
APT_PACKAGES += texinfo
endif
# Used by the autotools plugin itself.
ifeq ($(wildcard /usr/share/doc/libtool/copyright),)
APT_PACKAGES += libtool
endif
ifeq ($(wildcard /usr/share/doc/socat/copyright),)
APT_PACKAGES += socat
endif
endif
.PHONY: install-chisel
install-chisel:
ifneq ($(shell which chisel),)
else ifeq ($(shell which snap),)
$(warning Cannot install chisel without snap. Please install it yourself.)
else
sudo snap install chisel --channel latest/candidate
endif
.PHONY: install-go
install-go:
ifneq ($(shell which go),)
else ifeq ($(shell which snap),)
$(warning Cannot install go without snap. Please install it yourself.)
else
sudo snap install go --classic
endif
.PHONY: install-core20
install-core20:
ifneq ($(wildcard /snap/core20/),)
else ifeq ($(shell which snap),)
$(warning Cannot install core20 without snap. Please install it yourself.)
else
sudo snap install core20
endif
.PHONY: install-gradle
install-gradle:
ifneq ($(NO_JAVA),1)
ifneq ($(wildcard /snap/gradle/),)
else ifeq ($(shell which snap),)
$(warning Cannot install gradle without snap. Please install it yourself.)
else
sudo snap install gradle --classic
endif
endif
.PHONY: install-build-snaps
install-build-snaps: install-chisel install-go install-core20 install-dotnet install-rustup install-gradle
# Used for installing build dependencies in CI.
.PHONY: install-build-deps
install-build-deps: _gh-runner-clean install-lint-build-deps install-build-snaps
ifeq ($(APT_PACKAGES),)
else ifeq ($(shell which apt-get),)
$(warning Cannot install build dependencies without apt.)
$(warning Please ensure the equivalents to these packages are installed: $(APT_PACKAGES))
else
sudo $(APT) install $(APT_PACKAGES)
endif
# If additional build dependencies need installing in order to build the linting env.
.PHONY: install-lint-build-deps
install-lint-build-deps:
.PHONY: install-rustup
install-rustup:
ifneq ($(shell which rustup),)
else ifeq ($(shell which snap),)
$(warning Cannot install rustup without snap. Install it yourself.)
else
sudo snap install rustup --classic
endif
.PHONY: install-dotnet
install-dotnet:
ifeq ($(UBUNTU_CODENAME),focal)
ifeq ($(wildcard /snap/dotnet),) # Skip if we already have dotnet
ifeq ($(shell which snap),)
$(warning Cannot install dotnet without snap.)
else
sudo snap install dotnet --classic
endif
endif
endif
.PHONY: _gh-runner-clean
_gh-runner-clean:
# Prepare and fix issues on Github-hosted runners.
ifeq ($(CI)_$(RUNNER_ENVIRONMENT),true_github-hosted)
# Delete the (huge) Android SDK in the background.
nohup sudo rm -rf /usr/local/lib/android/ > /dev/null &
# Remove the github-installed cmake 4 because it breaks the cmake tests.
# See: https://github.com/actions/runner-images/issues/13023
nohup sudo rm -rf /usr/local/bin/cmake /usr/local/bin/cmake-gui /usr/local/bin/ccmake /usr/local/bin/ctest /usr/local/bin/cpack > /dev/null &
nohup sudo rm -rf /usr/local/share/cmake-4* > /dev/null &
# Remove Github-installed JDK 25 that's not in the repos.
# https://github.com/actions/runner-images/issues/13138
sudo $(APT) purge temurin-*-jdk || true
echo "JAVA_HOME=" >> "${GITHUB_ENV}"
# Delete the adoptium repository:
# https://github.com/actions/runner-images/blob/6fd5896f04e572647774996a7b292b854e6e8bc0/images/ubuntu/scripts/build/install-java-tools.sh#L67
sudo rm -f /etc/apt/sources.list.d/adoptium.list
endif