Debian Codegraph @

mkosi/mkosi.images/build/mkosi.conf.d/debian-ubuntu/mkosi.build.chroot

raw
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -e
4
5 if [[ "$1" == "clangd" ]]; then
6 exit 0
7 fi
8
9 if [[ ! -d "pkg/$PKG_SUBDIR/debian" ]]; then
10 echo "deb rules not found at pkg/$PKG_SUBDIR/debian, run mkosi once with -ff to make sure the rules are cloned" >&2
11 exit 1
12 fi
13
14 . mkosi/mkosi.functions
15
16 # We transplant the debian/ folder from the deb package sources into the upstream sources.
17 mount --mkdir --bind "$SRCDIR/pkg/$PKG_SUBDIR/debian" "$SRCDIR"/debian
18
19 # We hide the patches so they don't get applied.
20 if [[ -d "$SRCDIR/debian/patches" ]]; then
21 mkdir /tmp/patches
22 mount --bind /tmp/patches "$SRCDIR/debian/patches"
23 fi
24
25 # While the build directory can be specified through DH_OPTIONS, the default one is hardcoded everywhere so
26 # we have to use that. Because it is architecture dependent, we query it using dpkg-architecture first.
27 DEB_HOST_GNU_TYPE="$(dpkg-architecture --query DEB_HOST_GNU_TYPE)"
28 mount --mkdir --bind "$BUILDDIR" "$SRCDIR/obj-$DEB_HOST_GNU_TYPE"
29
30 TS="${SOURCE_DATE_EPOCH:-$(date +%s)}"
31
32 # Add a new changelog entry to update the version. We use a fixed date since a dynamic one causes a full
33 # rebuild every time.
34 cat >/tmp/changelog <<EOF
35 systemd ($(cat meson.version)-$(date "+%Y%m%d%H%M%S" --date "@$TS")) UNRELEASED; urgency=low
36
37 * Automatic build from mkosi
38
39 -- systemd test <[email protected]> $(date --rfc-email --date "@$TS")
40
41 EOF
42 cat debian/changelog >>/tmp/changelog
43 mount --bind /tmp/changelog "$PWD/debian/changelog"
44
45 DEB_BUILD_PROFILES="$(awk '$1=$1' <<<"\
46 $( ((WITH_TESTS)) || echo nocheck) \
47 $( ((WITH_DOCS)) || echo nodoc) \
48 pkg.systemd.upstream \
49 ")"
50
51 # TODO: Drop GENSYMBOLS_LEVEL once https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=986746 is fixed.
52 # Note that CXXFLAGS is for the C++ compiler, and CPPFLAGS is for the C/C++ preprocessor, they are not the same:
53 # https://en.wikipedia.org/wiki/CFLAGS
54 build() {
55 env \
56 CC="$( ((CC)) && echo "$CC" || ((LLVM)) && echo clang || echo gcc)" \
57 CXX="$( ((CXX)) && echo "$CXX" || ((LLVM)) && echo clang++ || echo g++)" \
58 CC_LD="$( ((LD)) && echo "$LD" || ((LLVM)) && echo lld)" \
59 CXX_LD="$( ((LD)) && echo "$LD" || ((LLVM)) && echo lld)" \
60 DEB_BUILD_OPTIONS="$(awk '$1=$1' <<<"\
61 $( ((WITH_TESTS)) || echo nocheck) \
62 $( ((WITH_DOCS)) || echo nodoc) \
63 $( ((WITH_DEBUG)) && echo debug || echo nostrip) \
64 $( ! ((MESON_VERBOSE)) && echo terse) \
65 optimize=-lto \
66 hardening=-fortify \
67 ")" \
68 DEB_BUILD_PROFILES="$DEB_BUILD_PROFILES" \
69 DEB_CFLAGS_APPEND="$MKOSI_CFLAGS $CFLAGS" \
70 DEB_CXXFLAGS_APPEND="$MKOSI_CFLAGS $CFLAGS" \
71 DEB_CPPFLAGS_APPEND="$CPPFLAGS" \
72 DEB_LDFLAGS_APPEND="$MKOSI_LDFLAGS $LDFLAGS" \
73 DPKG_FORCE="unsafe-io" \
74 DPKG_DEB_COMPRESSOR_TYPE="none" \
75 DH_MISSING="--fail-missing" \
76 CONFFLAGS_UPSTREAM="$MKOSI_MESON_OPTIONS $MESON_OPTIONS" \
77 GENSYMBOLS_LEVEL="$( ((LLVM)) && echo 0 || echo 1)" \
78 dpkg-buildpackage \
79 --no-pre-clean \
80 --unsigned-changes \
81 --build=binary
82
83 EXIT_STATUS=$?
84
85 # Make sure we don't reconfigure twice.
86 MKOSI_MESON_OPTIONS="${MKOSI_MESON_OPTIONS//"--wipe"/}"
87
88 return $EXIT_STATUS
89 }
90
91 trap 'umount "$SRCDIR/obj-$DEB_HOST_GNU_TYPE" && DEB_BUILD_PROFILES="$DEB_BUILD_PROFILES" dpkg-buildpackage -T clean' EXIT
92
93 if ! build; then
94 # debhelper installs files for each package to debian/<package> so we figure out which files were
95 # packaged by querying all the package names from debian/control and running find on each of the
96 # corresponding package directory in debian/.
97 grep "Package:" debian/control |
98 sed "s/Package: //" |
99 xargs -d '\n' -I {} sh -c "[ -d debian/{} ] && (cd debian/{} && find . ! -type d ! -path "*dh-exec*" -printf '%P\n')" |
100 # Remove compression suffix from compressed manpages as the manpages in debian/tmp will be uncompressed.
101 sed --regexp-extended 's/([0-9])\.gz$/\1/' >/tmp/packaged-files
102
103 # We figure out the installed files by running find on debian/tmp/ which contains the files installed
104 # by meson install.
105 (cd debian/tmp/ && find . ! -type d ! -path "*dh-exec*" -printf '%P\n' | sort --unique) >/tmp/installed-files
106
107 if [[ -f debian/not-installed ]]; then
108 pushd debian/tmp
109 grep --invert-match "^#" ../not-installed |
110 xargs -I {} sh -c "test -d '{}' && echo '{}/**/*' || echo '{}'" |
111 xargs -I {} bash -O nullglob -O globstar -c "printf '%s\n' {}" |
112 sed --expression "/^$/d" --expression "s#//*#/#g" |
113 xargs -I {} sh -c "test -f '{}' && echo '{}' || true" >>/tmp/packaged-files
114 popd
115 fi
116
117 sort --unique --output /tmp/packaged-files /tmp/packaged-files
118
119 # We get all the installed files that were not packaged by finding entries in the installed file that are
120 # not in the packaged file.
121 comm -23 /tmp/installed-files /tmp/packaged-files > /tmp/unpackaged-files
122 # If there are no unpackaged files something else went wrong.
123 if [[ ! -s /tmp/unpackaged-files ]]; then
124 exit 1
125 fi
126
127 echo -e "::warning title=UNPACKAGED-FILES::The following files were not picked up by the package, please update the packaging recipe to include: $(tr '\n' ' ' </tmp/unpackaged-files)"
128
129 # Otherwise, we append the unpackaged files to the filelist for the systemd package and retry the build.
130 cp debian/systemd.install /tmp/systemd.install
131 cat /tmp/unpackaged-files >>/tmp/systemd.install
132 mount --bind /tmp/systemd.install "$PWD/debian/systemd.install"
133 build
134 fi
135
136 (
137 shopt -s nullglob
138 rm -f "$BUILDDIR"/*.deb "$BUILDDIR"/*.ddeb
139
140 cp ../*.deb ../*.ddeb "$PACKAGEDIR"
141 cp ../*.deb ../*.ddeb "$BUILDDIR"
142
143 # These conflict with the packages that we actually want to install, so remove them
144 rm -f "$BUILDDIR"/systemd-standalone-*.deb "$BUILDDIR"/systemd-standalone-*.ddeb
145 )