summaryrefslogtreecommitdiffstats
path: root/mkosi.images/base/mkosi.conf.d/10-debian-ubuntu/mkosi.build.chroot
blob: d1ec8c189426ff371de066db6fe1abe0fc08cf8b (plain)
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
#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -e

if [ ! -d "pkg/$DISTRIBUTION/debian" ]; then
    echo "deb rules not found at pkg/$DISTRIBUTION/debian, run mkosi once with -ff to make sure the rules are cloned" >&2
    exit 1
fi

# We transplant the debian/ folder from the deb package sources into the upstream sources.
mount --mkdir --bind "$SRCDIR/pkg/$DISTRIBUTION/debian" "$SRCDIR"/debian

# We hide the patches/ directory by mounting an empty directory on top so they don't get applied.
TMP=$(mktemp -d)
mount --bind "$TMP" "$SRCDIR"/debian/patches

# While the build directory can be specified through DH_OPTIONS, the default one is hardcoded everywhere so
# we have to use that. Because it is architecture dependent, we query it using dpkg-architecture first.
DEB_HOST_GNU_TYPE="$(dpkg-architecture --query DEB_HOST_GNU_TYPE)"
mount --mkdir --bind "$BUILDDIR" "$SRCDIR/obj-$DEB_HOST_GNU_TYPE"

if [ -d .git/ ] && [ -z "$(git status --porcelain)" ]; then
    TS="$(git show --no-patch --format=%ct HEAD)"
else
    TS="${SOURCE_DATE_EPOCH:-$(date +%s)}"
fi

# Add a new changelog entry to update the version. We use a fixed date since a dynamic one causes a full
# rebuild every time.
cat >debian/changelog.new <<EOF
systemd ($(cat meson.version).$(date "+%Y%m%d%H%M%S" --date "@$TS")) UNRELEASED; urgency=low

  * Automatic build from mkosi

 -- systemd test <systemd-devel@lists.freedesktop.org>  $(date --rfc-email --date "@$TS")

EOF
cat debian/changelog >>debian/changelog.new
mv debian/changelog.new debian/changelog

build() {
    DEB_BUILD_OPTIONS="$( ((WITH_TESTS)) || echo nocheck) $( ((WITH_DOCS)) || echo nodoc) nostrip terse optimize=-lto" \
    DEB_BUILD_PROFILES="$( ((WITH_TESTS)) || echo nocheck) $( ((WITH_DOCS)) || echo nodoc) pkg.systemd.upstream" \
    DEB_CFLAGS_APPEND="-Og" \
    DPKG_FORCE="unsafe-io" \
    DPKG_DEB_COMPRESSOR_TYPE="none" \
    DH_MISSING="--fail-missing" \
    CONFFLAGS_UPSTREAM="-D mode=developer -D b_sanitize=${SANITIZERS:-none}" \
    dpkg-buildpackage \
        --no-pre-clean \
        --unsigned-changes \
        --build=binary
}

if ! build; then
    # debhelper installs files for each package to debian/<package> so we figure out which files were
    # packaged by querying all the package names from debian/control and running find on each of the
    # corresponding package directory in debian/.
    grep "Package:" debian/control |
        sed "s/Package: //" |
        xargs -d '\n' -I {} sh -c "[ -d debian/{} ] && (cd debian/{} && find . ! -type d ! -path "*dh-exec*" -printf '%P\n')" |
        # Remove compression suffix from compressed manpages as the manpages in debian/tmp will be uncompressed.
        sed --regexp-extended 's/([0-9])\.gz$/\1/' |
        sort --unique >/tmp/packaged-files

    # We figure out the installed files by running find on debian/tmp/ which contains the files installed
    # by meson install.
    (cd debian/tmp/ && find . ! -type d ! -path "*dh-exec*" -printf '%P\n') >/tmp/installed-files

    if [ -f debian/not-installed ]; then
        grep --invert-match "^#" debian/not-installed >>/tmp/installed-files
    fi

    sort --unique --output /tmp/installed-files /tmp/installed-files

    # We get all the installed files that were not packaged by finding entries in the installed file that are
    # not in the packaged file.
    comm -23 /tmp/installed-files /tmp/packaged-files > /tmp/unpackaged-files
    # If there are no unpackaged files something else went wrong.
    if [ ! -s /tmp/unpackaged-files ]; then
        exit 1
    fi

    # Otherwise, we append the unpackaged files to the filelist for the systemd package and retry the build.
    cat /tmp/unpackaged-files >>debian/systemd.install
    build
fi

mv ../*.deb "$PACKAGEDIR"