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 if [[ "$1" == "clangd" ]]; then
6 exit 0
7 fi
8
9 if [[ ! -f "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec" ]]; then
10 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
11 exit 1
12 fi
13
14 . mkosi/mkosi.functions
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="$MKOSI_CFLAGS -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
47 MKOSI_LDFLAGS="$(rpm --eval "%{?build_ldflags}") $MKOSI_LDFLAGS"
48
49 # A macro can't have an empty body and currently opensuse does not specify any of its own linker flags so
50 # set LDFLAGS to %{nil} if there are no linker flags.
51 if [[ -z "${MKOSI_LDFLAGS// }" ]]; then
52 MKOSI_LDFLAGS="%{nil}"
53 fi
54
55 # The opensuse spec tars up stuff in test/ and unpacks it in test/integration-tests, which we now use for our
56 # own purposes, so let's get rid of that specific bit of logic in the opensuse spec until they've had a chance
57 # to adapt.
58 #
59 # TODO: remove manual default-hierarchy patch when the upstream spec is updated
60 sed "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec" -e '/integration-tests\/README/d' -e '/default-hierarchy/ d' >/tmp/systemd.spec
61 mount --bind /tmp/systemd.spec "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec"
62
63 build() {
64 IFS=
65 # shellcheck disable=SC2046
66 env \
67 --unset CFLAGS \
68 --unset CXXFLAGS \
69 --unset LDFLAGS \
70 CC="$( ((CC)) && echo "$CC" || ((LLVM)) && echo clang || echo gcc)" \
71 CXX="$( ((CXX)) && echo "$CXX" || ((LLVM)) && echo clang++ || echo g++)" \
72 CC_LD="$( ((LD)) && echo "$LD" || ((LLVM)) && echo lld)" \
73 CXX_LD="$( ((LD)) && echo "$LD" || ((LLVM)) && echo lld)" \
74 rpmbuild \
75 -bb \
76 --noprep \
77 --build-in-place \
78 --with upstream \
79 --without sysvcompat \
80 $( ((WITH_TESTS)) || echo "--nocheck") \
81 --define "_topdir /var/tmp" \
82 --define "_sourcedir $PWD/pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}" \
83 --define "_rpmdir $BUILDDIR" \
84 ${BUILDDIR:+"--define=_vpath_builddir $BUILDDIR"} \
85 --define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
86 --define "_binary_payload w.ufdio" \
87 $( ((WITH_DEBUG)) || echo "--define=debug_package %{nil}") \
88 --define "vendor openSUSE" \
89 --define "version_override $VERSION" \
90 --define "release_override $RELEASE" \
91 --define "__check_files sh -c '$(rpm --define "_topdir /var/tmp" --eval %__check_files) | tee /tmp/unpackaged-files'" \
92 --define "build_cflags $(rpm --eval "%{?build_cflags}") $MKOSI_CFLAGS $CFLAGS" \
93 --define "build_cxxflags $(rpm --eval "%{?build_cxxflags}") $MKOSI_CFLAGS $CFLAGS" \
94 --define "build_ldflags $MKOSI_LDFLAGS $LDFLAGS" \
95 $( ((MESON_VERBOSE)) || echo "--undefine=__meson_verbose") \
96 --define "meson_extra_configure_options $MKOSI_MESON_OPTIONS $MESON_OPTIONS" \
97 --define "__os_install_post /usr/lib/rpm/brp-suse %{nil}" \
98 --define "__elf_exclude_path ^/usr/lib/systemd/tests/unit-tests/.*$" \
99 --define "__script_requires %{nil}" \
100 --define "_find_debuginfo_dwz_opts %{nil}" \
101 --define "_find_debuginfo_opts --unique-debug-src-base \"%{name}\"" \
102 "$@" \
103 "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec"
104
105 EXIT_STATUS=$?
106
107 # Make sure we don't reconfigure twice.
108 MKOSI_MESON_OPTIONS="${MKOSI_MESON_OPTIONS//"--wipe"/}"
109
110 return $EXIT_STATUS
111 }
112
113 (
114 shopt -s nullglob
115 rm -f "$BUILDDIR"/*.rpm
116 )
117
118 if ! build; then
119 if [[ ! -s /tmp/unpackaged-files ]]; then
120 exit 1
121 fi
122
123 grep -v "\.debug" /tmp/unpackaged-files >>"pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/files.systemd"
124 build --noprep --nocheck
125 fi
126
127 cp "$BUILDDIR"/*.rpm "$PACKAGEDIR"
128
129 make_sysext_unsigned /var/tmp/BUILD/*/BUILDROOT