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