]> git.ipfire.org Git - thirdparty/systemd.git/blob - mkosi.images/system/mkosi.conf.d/10-debian-ubuntu/mkosi.build.chroot
mkosi: Skip build if NO_BUILD is set
[thirdparty/systemd.git] / mkosi.images / system / mkosi.conf.d / 10-debian-ubuntu / mkosi.build.chroot
1 #!/bin/bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -e
4
5 if ((NO_BUILD)); then
6 exit 0
7 fi
8
9 # shellcheck source=/dev/null
10 . /usr/lib/os-release
11
12 if [ ! -d "pkg/$ID/debian" ]; then
13 echo "deb rules not found at pkg/$ID/debian, run mkosi once with -ff to make sure the rules are cloned" >&2
14 exit 1
15 fi
16
17 # We transplant the debian/ folder from the deb package sources into the upstream sources.
18 mount --mkdir --bind "$SRCDIR/pkg/$ID/debian" "$SRCDIR"/debian
19
20 # We remove the patches so they don't get applied.
21 rm -rf "$SRCDIR"/debian/patches/*
22
23 # While the build directory can be specified through DH_OPTIONS, the default one is hardcoded everywhere so
24 # we have to use that. Because it is architecture dependent, we query it using dpkg-architecture first.
25 DEB_HOST_GNU_TYPE="$(dpkg-architecture --query DEB_HOST_GNU_TYPE)"
26 mount --mkdir --bind "$BUILDDIR" "$SRCDIR/obj-$DEB_HOST_GNU_TYPE"
27
28 if [ -d .git/ ] && [ -z "$(git status --porcelain)" ]; then
29 TS="$(git show --no-patch --format=%ct HEAD)"
30 else
31 TS="${SOURCE_DATE_EPOCH:-$(date +%s)}"
32 fi
33
34 # Add a new changelog entry to update the version. We use a fixed date since a dynamic one causes a full
35 # rebuild every time.
36 cat >debian/changelog.new <<EOF
37 systemd ($(cat meson.version)-$(date "+%Y%m%d%H%M%S" --date "@$TS")) UNRELEASED; urgency=low
38
39 * Automatic build from mkosi
40
41 -- systemd test <systemd-devel@lists.freedesktop.org> $(date --rfc-email --date "@$TS")
42
43 EOF
44 cat debian/changelog >>debian/changelog.new
45 mv debian/changelog.new debian/changelog
46
47 # FIXME: Remove after tmp.mount is kept intact in the debian packaging for UPSTREAM=1 builds.
48 sed --in-place '/tmp.mount/d' debian/rules
49 sed --in-place '/tmp.mount/d' debian/not-installed
50
51 build() {
52 DEB_BUILD_OPTIONS=$(awk '$1=$1' <<<"\
53 $( ((WITH_TESTS)) || echo nocheck) \
54 $( ((WITH_DOCS)) || echo nodoc) \
55 $( ((WITH_DEBUG)) && echo debug || echo nostrip) \
56 terse \
57 optimize=-lto \
58 hardening=-fortify \
59 ") \
60 DEB_BUILD_PROFILES=$(awk '$1=$1' <<<"\
61 $( ((WITH_TESTS)) || echo nocheck) \
62 $( ((WITH_DOCS)) || echo nodoc) \
63 pkg.systemd.upstream \
64 ") \
65 DEB_CFLAGS_APPEND="-O${OPTIMIZATION:-0}" \
66 DPKG_FORCE="unsafe-io" \
67 DPKG_DEB_COMPRESSOR_TYPE="none" \
68 DH_MISSING="--fail-missing" \
69 CONFFLAGS_UPSTREAM="-D mode=developer -D b_sanitize=${SANITIZERS:-none}" \
70 dpkg-buildpackage \
71 --no-pre-clean \
72 --unsigned-changes \
73 --build=binary
74 }
75
76 if ! build; then
77 # debhelper installs files for each package to debian/<package> so we figure out which files were
78 # packaged by querying all the package names from debian/control and running find on each of the
79 # corresponding package directory in debian/.
80 grep "Package:" debian/control |
81 sed "s/Package: //" |
82 xargs -d '\n' -I {} sh -c "[ -d debian/{} ] && (cd debian/{} && find . ! -type d ! -path "*dh-exec*" -printf '%P\n')" |
83 # Remove compression suffix from compressed manpages as the manpages in debian/tmp will be uncompressed.
84 sed --regexp-extended 's/([0-9])\.gz$/\1/' |
85 sort --unique >/tmp/packaged-files
86
87 # We figure out the installed files by running find on debian/tmp/ which contains the files installed
88 # by meson install.
89 (cd debian/tmp/ && find . ! -type d ! -path "*dh-exec*" -printf '%P\n') >/tmp/installed-files
90
91 if [ -f debian/not-installed ]; then
92 grep --invert-match "^#" debian/not-installed >>/tmp/installed-files
93 fi
94
95 sort --unique --output /tmp/installed-files /tmp/installed-files
96
97 # We get all the installed files that were not packaged by finding entries in the installed file that are
98 # not in the packaged file.
99 comm -23 /tmp/installed-files /tmp/packaged-files > /tmp/unpackaged-files
100 # If there are no unpackaged files something else went wrong.
101 if [ ! -s /tmp/unpackaged-files ]; then
102 exit 1
103 fi
104
105 # Otherwise, we append the unpackaged files to the filelist for the systemd package and retry the build.
106 cat /tmp/unpackaged-files >>debian/systemd.install
107 build
108 fi
109
110 (
111 shopt -s nullglob
112 cp ../*.deb ../*.ddeb "$PACKAGEDIR"
113 cp ../*.deb ../*.ddeb "$OUTPUTDIR"
114 )