| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
set -e |
| 4 |
shopt -s extglob |
| 5 |
|
| 6 |
# Set defaults from the running kernel |
| 7 |
arch="$(dpkg --print-architecture)" |
| 8 |
kernelabi="$(uname -r)" |
| 9 |
ff="${kernelabi##+([^-])-?(@(trunk|?(rc)+([0-9])|0.@(bpo|deb+([0-9])).+([0-9]))-)}" |
| 10 |
# Until we add a new featureset just unconditionally set flavour and featureset |
| 11 |
# cf. https://salsa.debian.org/kernel-team/linux/-/merge_requests/1636#note_661937 |
| 12 |
flavour="${ff}" |
| 13 |
featureset=none |
| 14 |
|
| 15 |
dbginfo= |
| 16 |
fuzz=0 |
| 17 |
jobs=$(nproc) |
| 18 |
|
| 19 |
eval "set -- $(getopt -n "$0" -o "f:gj:s:" -l "fuzz:" -- "$@")" |
| 20 |
while true; do |
| 21 |
case "$1" in |
| 22 |
-f) flavour="$2"; shift 2 ;; |
| 23 |
-g) dbginfo=y; shift 1 ;; |
| 24 |
-j) jobs="$2"; shift 2 ;; |
| 25 |
-s) featureset="$2"; shift 2 ;; |
| 26 |
--fuzz) fuzz="$2"; shift 2;; |
| 27 |
--) shift 1; break ;; |
| 28 |
esac |
| 29 |
done |
| 30 |
|
| 31 |
if [ $# -lt 1 ]; then |
| 32 |
echo >&2 "Usage: $0 [<options>] <patch>..." |
| 33 |
cat >&2 <<EOF |
| 34 |
Options: |
| 35 |
-f <flavour> specify the 'flavour' of kernel to build, e.g. 686-pae |
| 36 |
-g enable debug info |
| 37 |
-j <jobs> specify number of compiler jobs to run in parallel |
| 38 |
(default: number of available processors) |
| 39 |
-s <featureset> specify an optional featureset to apply, e.g. rt |
| 40 |
--fuzz <num> set the maximum patch fuzz factor (default: 0) |
| 41 |
EOF |
| 42 |
exit 2 |
| 43 |
fi |
| 44 |
|
| 45 |
if [ -z "$flavour" ]; then |
| 46 |
echo >&2 "You must specify a flavour to build with the -f option" |
| 47 |
exit 2 |
| 48 |
fi |
| 49 |
|
| 50 |
profiles=nodoc,noudeb,pkg.linux.nosource,pkg.linux.mintools |
| 51 |
if [ -z "$dbginfo" ]; then |
| 52 |
profiles="$profiles,pkg.linux.nokerneldbg,pkg.linux.nokerneldbginfo" |
| 53 |
fi |
| 54 |
|
| 55 |
# Check build-dependencies early if possible |
| 56 |
if [ -f debian/control ]; then |
| 57 |
dpkg-checkbuilddeps -P"$profiles" |
| 58 |
fi |
| 59 |
|
| 60 |
# Provide defaults for DEBEMAIL and DEBFULLNAME |
| 61 |
if [[ -z "${DEBEMAIL}" && -z "${EMAIL}" ]]; then |
| 62 |
export [email protected] |
| 63 |
fi |
| 64 |
if [[ -z "${DEBFULLNAME}" && -z "${NAME}" ]]; then |
| 65 |
export DEBFULLNAME=test-patches |
| 66 |
fi |
| 67 |
|
| 68 |
# Append 'a~test' to Debian version; this should be less than any official |
| 69 |
# successor and easily recognisable |
| 70 |
version="$(dpkg-parsechangelog | sed 's/^Version: //; t; d')" |
| 71 |
if [ "${version%a~test}" = "$version" ]; then |
| 72 |
version="$version"a~test |
| 73 |
dch -v "$version" --distribution UNRELEASED "Testing patches $*" |
| 74 |
fi |
| 75 |
|
| 76 |
# Ignore user's .quiltrc |
| 77 |
alias quilt='quilt --quiltrc -' |
| 78 |
|
| 79 |
# Try to clean up any previous test patches |
| 80 |
if [ "$featureset" = none ]; then |
| 81 |
patchdir=debian/patches |
| 82 |
while patch="$(quilt top 2>/dev/null)" && \ |
| 83 |
[ "${patch#test/}" != "$patch" ]; do |
| 84 |
quilt pop -f |
| 85 |
done |
| 86 |
while patch="$(quilt next 2>/dev/null)" && \ |
| 87 |
[ "${patch#test/}" != "$patch" ]; do |
| 88 |
quilt delete -r "$patch" |
| 89 |
done |
| 90 |
else |
| 91 |
patchdir=debian/patches-${featureset} |
| 92 |
sed -i '/^test\//d' $patchdir/series |
| 93 |
fi |
| 94 |
|
| 95 |
# Prepare a new directory for the patches |
| 96 |
rm -rf $patchdir/test/ |
| 97 |
mkdir $patchdir/test |
| 98 |
|
| 99 |
# Prepare a new directory for the config; override ABI name, featuresets, flavours |
| 100 |
rm -rf debian/config.local |
| 101 |
mkdir debian/config.local debian/config.local/"$arch" |
| 102 |
for other_fs in none; do |
| 103 |
if [ "$other_fs" != "$featureset" ]; then |
| 104 |
cat >debian/config.local/defines.toml <<EOF |
| 105 |
[[featureset]] |
| 106 |
name = '$other_fs' |
| 107 |
enable = false |
| 108 |
EOF |
| 109 |
fi |
| 110 |
done |
| 111 |
cat >debian/config.local/"$arch"/defines.toml <<EOF |
| 112 |
[[featureset]] |
| 113 |
name = '$featureset' |
| 114 |
|
| 115 |
[[featureset.flavour]] |
| 116 |
name = '$flavour' |
| 117 |
|
| 118 |
[build] |
| 119 |
enable_signed = false |
| 120 |
EOF |
| 121 |
|
| 122 |
# Regenerate control and included rules |
| 123 |
rm -f debian/control debian/rules.gen |
| 124 |
debian/rules debian/control-real |
| 125 |
test -f debian/control |
| 126 |
test -f debian/rules.gen |
| 127 |
|
| 128 |
# Check build-dependencies now that we know debian/control exists |
| 129 |
dpkg-checkbuilddeps -P"$profiles" |
| 130 |
|
| 131 |
# Clean up old build; apply existing patches for featureset |
| 132 |
debian/rules clean |
| 133 |
debian/rules source |
| 134 |
|
| 135 |
# Apply the additional patches |
| 136 |
for patch in "$@"; do |
| 137 |
patch_abs="$(readlink -f "$patch")" |
| 138 |
(cd "debian/build/source_${featureset}" && \ |
| 139 |
quilt import -P "test/$(basename "$patch")" "$patch_abs" && \ |
| 140 |
quilt push --fuzz="$fuzz") |
| 141 |
done |
| 142 |
|
| 143 |
# Build selected binaries |
| 144 |
dpkg-buildpackage -b -P"$profiles" -j"$jobs" -nc -uc |