mirror of
https://github.com/dynup/kpatch
synced 2025-01-28 07:42:42 +00:00
kpatch-build: --sourcedir 2.0
In my experience this is a much more useful implementation of the "--sourcedir" option: - use the source tree in-place rather than first copying it to ~/.kpatch/src. In my case this avoids a 5GB copy, including the entire .git subdirectory, and allows ccache to be reused. - find the vmlinux and .config files in the sourcedir - autodetect the ARCHVERSION
This commit is contained in:
parent
92fb49e6f2
commit
89ce1c5d79
@ -43,7 +43,7 @@ ARCHVERSION="$(uname -r)"
|
|||||||
CPUS="$(grep -c ^processor /proc/cpuinfo)"
|
CPUS="$(grep -c ^processor /proc/cpuinfo)"
|
||||||
CACHEDIR="$HOME/.kpatch"
|
CACHEDIR="$HOME/.kpatch"
|
||||||
TEMPDIR=
|
TEMPDIR=
|
||||||
APPLIEDPATCHFILE="applied-patch"
|
APPLIEDPATCHFILE="kpatch.patch"
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
@ -56,11 +56,17 @@ die() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
[[ "$DEBUG" -eq 0 ]] && rm -rf "$TEMPDIR"
|
|
||||||
if [[ -e "$SRCDIR/$APPLIEDPATCHFILE" ]]; then
|
if [[ -e "$SRCDIR/$APPLIEDPATCHFILE" ]]; then
|
||||||
patch -p1 -R -d "$SRCDIR" < "$SRCDIR/$APPLIEDPATCHFILE" &> /dev/null
|
patch -p1 -R -d "$SRCDIR" < "$SRCDIR/$APPLIEDPATCHFILE" &> /dev/null
|
||||||
rm -f "$SRCDIR/$APPLIEDPATCHFILE"
|
rm -f "$SRCDIR/$APPLIEDPATCHFILE"
|
||||||
fi
|
fi
|
||||||
|
if [[ -n $USERSRCDIR ]]; then
|
||||||
|
# restore original .config and vmlinux since they were removed
|
||||||
|
# with mrproper
|
||||||
|
[[ -e $TEMPDIR/vmlinux ]] && cp -f $TEMPDIR/vmlinux $USERSRCDIR
|
||||||
|
[[ -e $TEMPDIR/.config ]] && cp -f $TEMPDIR/.config $USERSRCDIR
|
||||||
|
fi
|
||||||
|
[[ "$DEBUG" -eq 0 ]] && rm -rf "$TEMPDIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
find_dirs() {
|
find_dirs() {
|
||||||
@ -193,6 +199,22 @@ while [[ $# -gt 0 ]]; do
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
TEMPDIR="$(mktemp -d /tmp/kpatch-build-XXXXXX)" || die "mktemp failed"
|
||||||
|
trap cleanup EXIT INT TERM
|
||||||
|
|
||||||
|
if [[ -n $USERSRCDIR ]]; then
|
||||||
|
# save .config and vmlinux since they'll get removed with mrproper so
|
||||||
|
# we can restore them later and be able to run kpatch-build multiple
|
||||||
|
# times on the same sourcedir
|
||||||
|
[[ -z $CONFIGFILE ]] && CONFIGFILE="$USERSRCDIR"/.config
|
||||||
|
[[ ! -e "$CONFIGFILE" ]] && die "can't find config file"
|
||||||
|
[[ "$CONFIGFILE" = "$USERSRCDIR"/.config ]] && cp -f "$CONFIGFILE" $TEMPDIR
|
||||||
|
|
||||||
|
[[ -z $VMLINUX ]] && VMLINUX="$USERSRCDIR"/vmlinux
|
||||||
|
[[ ! -e "$VMLINUX" ]] && die "can't find vmlinux"
|
||||||
|
[[ "$VMLINUX" = "$USERSRCDIR"/vmlinux ]] && cp -f "$VMLINUX" $TEMPDIR/vmlinux && VMLINUX=$TEMPDIR/vmlinux
|
||||||
|
fi
|
||||||
|
|
||||||
SRCDIR="$CACHEDIR/src"
|
SRCDIR="$CACHEDIR/src"
|
||||||
OBJDIR="$CACHEDIR/obj"
|
OBJDIR="$CACHEDIR/obj"
|
||||||
OBJDIR2="$CACHEDIR/obj2"
|
OBJDIR2="$CACHEDIR/obj2"
|
||||||
@ -208,10 +230,6 @@ fi
|
|||||||
# Everything else is replaced with '-'.
|
# Everything else is replaced with '-'.
|
||||||
PATCHNAME=${PATCHNAME//[^a-zA-Z0-9_-]/-}
|
PATCHNAME=${PATCHNAME//[^a-zA-Z0-9_-]/-}
|
||||||
|
|
||||||
TEMPDIR="$(mktemp -d /tmp/kpatch-build-XXXXXX)" || die "mktemp failed"
|
|
||||||
|
|
||||||
trap cleanup EXIT INT TERM
|
|
||||||
|
|
||||||
find_dirs || die "can't find supporting tools"
|
find_dirs || die "can't find supporting tools"
|
||||||
|
|
||||||
[[ -e "$SYMVERSFILE" ]] || die "can't find core module Module.symvers"
|
[[ -e "$SYMVERSFILE" ]] || die "can't find core module Module.symvers"
|
||||||
@ -232,7 +250,8 @@ elif [[ $DISTRO = ubuntu ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$USERSRCDIR" ]]; then
|
if [[ -n "$USERSRCDIR" ]]; then
|
||||||
SRCDIR="$CACHEDIR/src"
|
echo "Using source directory at $USERSRCDIR"
|
||||||
|
SRCDIR="$USERSRCDIR"
|
||||||
OBJDIR="$CACHEDIR/obj"
|
OBJDIR="$CACHEDIR/obj"
|
||||||
OBJDIR2="$CACHEDIR/obj2"
|
OBJDIR2="$CACHEDIR/obj2"
|
||||||
|
|
||||||
@ -240,14 +259,14 @@ if [[ -n "$USERSRCDIR" ]]; then
|
|||||||
mkdir -p "$CACHEDIR"
|
mkdir -p "$CACHEDIR"
|
||||||
mkdir -p "$OBJDIR" "$OBJDIR2"
|
mkdir -p "$OBJDIR" "$OBJDIR2"
|
||||||
|
|
||||||
if [[ -n "$CONFIGFILE" ]]; then
|
cp -f "$CONFIGFILE" "$OBJDIR/.config"
|
||||||
cp "$CONFIGFILE" "$OBJDIR/.config" || die "config file is missing"
|
|
||||||
else
|
|
||||||
cp "$USERSRCDIR/.config" "$OBJDIR" || die "source dir is missing a .config file"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Copying source to $SRCDIR"
|
echo "Detecting kernel version"
|
||||||
cp -a "$USERSRCDIR" "$SRCDIR" || die "copy failed"
|
cd "$SRCDIR"
|
||||||
|
make mrproper >> "$LOGFILE" 2>&1 || die
|
||||||
|
make "O=$OBJDIR" include/generated/utsrelease.h >> "$LOGFILE" 2>&1 || die
|
||||||
|
ARCHVERSION=$(awk '{print $3}' "$OBJDIR"/include/generated/utsrelease.h) || die "can't find version in utsrelease.h"
|
||||||
|
ARCHVERSION=${ARCHVERSION//\"/}
|
||||||
|
|
||||||
elif [[ -e "$SRCDIR" ]] && [[ -e "$CACHEDIR"/version ]] && [[ $(cat "$CACHEDIR"/version) = $ARCHVERSION ]]; then
|
elif [[ -e "$SRCDIR" ]] && [[ -e "$CACHEDIR"/version ]] && [[ $(cat "$CACHEDIR"/version) = $ARCHVERSION ]]; then
|
||||||
echo "Using cache at $SRCDIR"
|
echo "Using cache at $SRCDIR"
|
||||||
|
Loading…
Reference in New Issue
Block a user