Debian Codegraph @

mkosi/mkosi.images/build/mkosi.conf.d/opensuse/mkosi.build.chroot

raw
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -e
4
5 . mkosi/mkosi.functions
6
7 if [[ "$1" == "clangd" ]]; then
8 exit 0
9 fi
10
11 if [[ ! -f "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec" ]]; then
12 echo "spec not found at pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec, run mkosi once with -ff to make sure the spec is cloned" >&2
13 exit 1
14 fi
15
16 TS="${SOURCE_DATE_EPOCH:-$(date +%s)}"
17
18 # The openSUSE filelists hardcode the manpage compression extension. This causes rpmbuild errors since we
19 # disable manpage compression as the files cannot be found. Fix the issue by removing the compression
20 # extension.
21 # TODO: remove autovt@ removal when the upstream spec is updated
22 while read -r filelist; do
23 sed -E \
24 -e '/autovt@/d' \
25 -e 's/\.gz$//' \
26 "$filelist" >"/tmp/$(basename "$filelist")"
27 mount --bind "/tmp/$(basename "$filelist")" "$filelist"
28 done < <(find "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}" -name "files.*")
29
30 if [[ "$(rpm --eval "%{lua:print(rpm.vercmp('$(rpm --version | cut -d ' ' -f3)', '4.20'))}")" == "-1" ]]; then
31 # Fix the %install override so debuginfo packages are generated.
32 tee --append /usr/lib/rpm/suse/macros <<'EOF'
33 %install %{debug_package}\
34 %%install\
35 %{nil}
36 EOF
37 fi
38
39 VERSION="$(cat meson.version)"
40 RELEASE="$(date "+%Y%m%d%H%M%S" --date "@$TS")"
41
42 MKOSI_CFLAGS="-O0 -g -Wp,-U_FORTIFY_SOURCE"
43 if ((WITH_DEBUG)); then
44 MKOSI_CFLAGS="$MKOSI_CFLAGS -fdebug-prefix-map=../src=/usr/src/debug/systemd"
45 fi
46 if ((LLVM)); then
47 # TODO: Remove -fno-sanitize-function when https://github.com/systemd/systemd/issues/29972 is fixed.
48 MKOSI_CFLAGS="$MKOSI_CFLAGS -shared-libasan -fno-sanitize=function"
49 fi
50
51 MKOSI_LDFLAGS="$(rpm --eval "%{?build_ldflags}")"
52 if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
53 MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(realpath "$(clang --print-runtime-dir)")"
54 fi
55
56 # A macro can't have an empty body and currently opensuse does not specify any of its own linker flags so
57 # set LDFLAGS to %{nil} if there are no linker flags.
58 if [[ -z "${MKOSI_LDFLAGS// }" ]]; then
59 MKOSI_LDFLAGS="%{nil}"
60 fi
61
62 MKOSI_MESON_OPTIONS="-D mode=developer -D vcs-tag=${VCS_TAG:-true} -D b_sanitize=${SANITIZERS:-none} -Dtime-epoch=1744207869"
63 if ((WIPE)) && [[ -d "$BUILDDIR/meson-private" ]]; then
64 MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS --wipe"
65 fi
66 if ((COVERAGE)); then
67 MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS -D b_coverage=true"
68 MKOSI_CFLAGS="$MKOSI_CFLAGS -fprofile-dir=/coverage"
69 fi
70
71 # The opensuse spec tars up stuff in test/ and unpacks it in test/integration-tests, which we now use for our
72 # own purposes, so let's get rid of that specific bit of logic in the opensuse spec until they've had a chance
73 # to adapt.
74 #
75 # TODO: remove manual default-hierarchy patch when the upstream spec is updated
76 sed "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec" -e '/integration-tests\/README/d' -e '/default-hierarchy/ d' >/tmp/systemd.spec
77 mount --bind /tmp/systemd.spec "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec"
78
79 build() {
80 IFS=
81 # shellcheck disable=SC2046
82 env \
83 --unset CFLAGS \
84 --unset CXXFLAGS \
85 --unset LDFLAGS \
86 CC="$( ((CC)) && echo "$CC" || ((LLVM)) && echo clang || echo gcc)" \
87 CXX="$( ((CXX)) && echo "$CXX" || ((LLVM)) && echo clang++ || echo g++)" \
88 CC_LD="$( ((LD)) && echo "$LD" || ((LLVM)) && echo lld)" \
89 CXX_LD="$( ((LD)) && echo "$LD" || ((LLVM)) && echo lld)" \
90 rpmbuild \
91 -bb \
92 --noprep \
93 --build-in-place \
94 --with upstream \
95 --without sysvcompat \
96 $( ((WITH_TESTS)) || echo "--nocheck") \
97 --define "_topdir /var/tmp" \
98 --define "_sourcedir $PWD/pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}" \
99 --define "_rpmdir $BUILDDIR" \
100 ${BUILDDIR:+"--define=_vpath_builddir $BUILDDIR"} \
101 --define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
102 --define "_binary_payload w.ufdio" \
103 $( ((WITH_DEBUG)) || echo "--define=debug_package %{nil}") \
104 --define "vendor openSUSE" \
105 --define "version_override $VERSION" \
106 --define "release_override $RELEASE" \
107 --define "__check_files sh -c '$(rpm --define "_topdir /var/tmp" --eval %__check_files) | tee /tmp/unpackaged-files'" \
108 --define "build_cflags $(rpm --eval "%{?build_cflags}") $MKOSI_CFLAGS $CFLAGS" \
109 --define "build_cxxflags $(rpm --eval "%{?build_cxxflags}") $MKOSI_CFLAGS $CFLAGS" \
110 --define "build_ldflags $MKOSI_LDFLAGS $LDFLAGS" \
111 $( ((MESON_VERBOSE)) || echo "--undefine=__meson_verbose") \
112 --define "meson_extra_configure_options $MKOSI_MESON_OPTIONS $MESON_OPTIONS" \
113 --define "__os_install_post /usr/lib/rpm/brp-suse %{nil}" \
114 --define "__elf_exclude_path ^/usr/lib/systemd/tests/unit-tests/.*$" \
115 --define "__script_requires %{nil}" \
116 --define "_find_debuginfo_dwz_opts %{nil}" \
117 --define "_find_debuginfo_opts --unique-debug-src-base \"%{name}\"" \
118 "$@" \
119 "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec"
120
121 EXIT_STATUS=$?
122
123 # Make sure we don't reconfigure twice.
124 MKOSI_MESON_OPTIONS="${MKOSI_MESON_OPTIONS//"--wipe"/}"
125
126 return $EXIT_STATUS
127 }
128
129 (
130 shopt -s nullglob
131 rm -f "$BUILDDIR"/*.rpm
132 )
133
134 if ! build; then
135 if [[ ! -s /tmp/unpackaged-files ]]; then
136 exit 1
137 fi
138
139 grep -v ".debug" /tmp/unpackaged-files >>"pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/files.systemd"
140 build --noprep --nocheck
141 fi
142
143 cp "$BUILDDIR"/*.rpm "$PACKAGEDIR"
144
145 make_sysext_unsigned /var/tmp/BUILD/*/BUILDROOT