mirror of
https://github.com/dynup/kpatch
synced 2025-01-14 09:00:46 +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)"
|
||||
CACHEDIR="$HOME/.kpatch"
|
||||
TEMPDIR=
|
||||
APPLIEDPATCHFILE="applied-patch"
|
||||
APPLIEDPATCHFILE="kpatch.patch"
|
||||
DEBUG=0
|
||||
|
||||
die() {
|
||||
@ -56,11 +56,17 @@ die() {
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
[[ "$DEBUG" -eq 0 ]] && rm -rf "$TEMPDIR"
|
||||
if [[ -e "$SRCDIR/$APPLIEDPATCHFILE" ]]; then
|
||||
patch -p1 -R -d "$SRCDIR" < "$SRCDIR/$APPLIEDPATCHFILE" &> /dev/null
|
||||
rm -f "$SRCDIR/$APPLIEDPATCHFILE"
|
||||
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() {
|
||||
@ -193,6 +199,22 @@ while [[ $# -gt 0 ]]; do
|
||||
shift
|
||||
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"
|
||||
OBJDIR="$CACHEDIR/obj"
|
||||
OBJDIR2="$CACHEDIR/obj2"
|
||||
@ -208,10 +230,6 @@ fi
|
||||
# Everything else is replaced with '-'.
|
||||
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"
|
||||
|
||||
[[ -e "$SYMVERSFILE" ]] || die "can't find core module Module.symvers"
|
||||
@ -232,7 +250,8 @@ elif [[ $DISTRO = ubuntu ]]; then
|
||||
fi
|
||||
|
||||
if [[ -n "$USERSRCDIR" ]]; then
|
||||
SRCDIR="$CACHEDIR/src"
|
||||
echo "Using source directory at $USERSRCDIR"
|
||||
SRCDIR="$USERSRCDIR"
|
||||
OBJDIR="$CACHEDIR/obj"
|
||||
OBJDIR2="$CACHEDIR/obj2"
|
||||
|
||||
@ -240,14 +259,14 @@ if [[ -n "$USERSRCDIR" ]]; then
|
||||
mkdir -p "$CACHEDIR"
|
||||
mkdir -p "$OBJDIR" "$OBJDIR2"
|
||||
|
||||
if [[ -n "$CONFIGFILE" ]]; then
|
||||
cp "$CONFIGFILE" "$OBJDIR/.config" || die "config file is missing"
|
||||
else
|
||||
cp "$USERSRCDIR/.config" "$OBJDIR" || die "source dir is missing a .config file"
|
||||
fi
|
||||
cp -f "$CONFIGFILE" "$OBJDIR/.config"
|
||||
|
||||
echo "Copying source to $SRCDIR"
|
||||
cp -a "$USERSRCDIR" "$SRCDIR" || die "copy failed"
|
||||
echo "Detecting kernel version"
|
||||
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
|
||||
echo "Using cache at $SRCDIR"
|
||||
|
Loading…
Reference in New Issue
Block a user