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