mirror of
https://github.com/dynup/kpatch
synced 2025-04-04 23:29:23 +00:00
kpatch-build: allow list of patches on command line
It can be convenient to build a patchset into a single kpatch module, so teach kpatch-build to accept a list of .patch files on the commandline. Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
This commit is contained in:
parent
8dc25d79d1
commit
139cfb38d4
@ -45,11 +45,12 @@ RPMTOPDIR="$CACHEDIR/buildroot"
|
|||||||
VERSIONFILE="$CACHEDIR/version"
|
VERSIONFILE="$CACHEDIR/version"
|
||||||
TEMPDIR="$CACHEDIR/tmp"
|
TEMPDIR="$CACHEDIR/tmp"
|
||||||
LOGFILE="$CACHEDIR/build.log"
|
LOGFILE="$CACHEDIR/build.log"
|
||||||
APPLIEDPATCHFILE="kpatch.patch"
|
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
SKIPCLEANUP=0
|
SKIPCLEANUP=0
|
||||||
SKIPGCCCHECK=0
|
SKIPGCCCHECK=0
|
||||||
ARCH_KCFLAGS=""
|
ARCH_KCFLAGS=""
|
||||||
|
declare -a PATCH_LIST
|
||||||
|
APPLIED_PATCHES=0
|
||||||
|
|
||||||
warn() {
|
warn() {
|
||||||
echo "ERROR: $1" >&2
|
echo "ERROR: $1" >&2
|
||||||
@ -71,15 +72,34 @@ die() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply_patches() {
|
||||||
|
local patch
|
||||||
|
|
||||||
|
for patch in "${PATCH_LIST[@]}"; do
|
||||||
|
patch -N -p1 --dry-run < "$patch" >> "$LOGFILE" 2>&1 || die "$patch file failed to apply"
|
||||||
|
patch -N -p1 < "$patch" >> "$LOGFILE" 2>&1 || die "$patch file failed to apply"
|
||||||
|
(( APPLIED_PATCHES++ ))
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_patches() {
|
||||||
|
local patch
|
||||||
|
local idx
|
||||||
|
|
||||||
|
for (( ; APPLIED_PATCHES>0; APPLIED_PATCHES-- )); do
|
||||||
|
idx=$(( APPLIED_PATCHES - 1))
|
||||||
|
patch="${PATCH_LIST[$idx]}"
|
||||||
|
patch -p1 -R -d "$SRCDIR" < "$patch" &> /dev/null
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
rm -f "$SRCDIR/.scmversion"
|
rm -f "$SRCDIR/.scmversion"
|
||||||
if [[ -e "$SRCDIR/$APPLIEDPATCHFILE" ]]; then
|
|
||||||
patch -p1 -R -d "$SRCDIR" < "$SRCDIR/$APPLIEDPATCHFILE" &> /dev/null
|
remove_patches
|
||||||
rm -f "$SRCDIR/$APPLIEDPATCHFILE"
|
|
||||||
# If $SRCDIR was a git repo, make sure git actually sees that
|
# If $SRCDIR was a git repo, make sure git actually sees that
|
||||||
# we've reverted our patch above.
|
# we've reverted our patch(es).
|
||||||
[[ -d $SRCDIR/.git ]] && (cd $SRCDIR && git update-index -q --refresh)
|
[[ -d $SRCDIR/.git ]] && (cd $SRCDIR && git update-index -q --refresh)
|
||||||
fi
|
|
||||||
|
|
||||||
# restore original .config and vmlinux if they were removed with mrproper
|
# restore original .config and vmlinux if they were removed with mrproper
|
||||||
[[ -e $TEMPDIR/.config ]] && mv -f $TEMPDIR/.config $SRCDIR/
|
[[ -e $TEMPDIR/.config ]] && mv -f $TEMPDIR/.config $SRCDIR/
|
||||||
@ -327,7 +347,8 @@ module_name_string() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: $(basename $0) [options] <patch file>" >&2
|
echo "usage: $(basename $0) [options] <patch1 ... patchN>" >&2
|
||||||
|
echo " patchN Input patchfile(s)" >&2
|
||||||
echo " -h, --help Show this help message" >&2
|
echo " -h, --help Show this help message" >&2
|
||||||
echo " -r, --sourcerpm Specify kernel source RPM" >&2
|
echo " -r, --sourcerpm Specify kernel source RPM" >&2
|
||||||
echo " -s, --sourcedir Specify kernel source directory" >&2
|
echo " -s, --sourcedir Specify kernel source directory" >&2
|
||||||
@ -406,16 +427,21 @@ while [[ $# -gt 0 ]]; do
|
|||||||
echo "WARNING: Skipping gcc version matching check (not recommended)"
|
echo "WARNING: Skipping gcc version matching check (not recommended)"
|
||||||
SKIPGCCCHECK=1
|
SKIPGCCCHECK=1
|
||||||
;;
|
;;
|
||||||
--)
|
*)
|
||||||
[[ -z "$2" ]] && die "no patch file specified"
|
[[ "$1" = "--" ]] && shift && continue
|
||||||
[[ ! -f "$2" ]] && die "patch file '$2' not found"
|
[[ ! -f "$1" ]] && die "patch file '$1' not found"
|
||||||
PATCHFILE=$(readlink -f "$2")
|
PATCH_LIST+=($(readlink -f "$1"))
|
||||||
break
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [[ ${#PATCH_LIST[@]} -eq 0 ]]; then
|
||||||
|
warn "no patch file(s) specified"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# ensure cachedir and tempdir are setup properly and cleaned
|
# ensure cachedir and tempdir are setup properly and cleaned
|
||||||
mkdir -p "$TEMPDIR" || die "Couldn't create $TEMPDIR"
|
mkdir -p "$TEMPDIR" || die "Couldn't create $TEMPDIR"
|
||||||
rm -rf "$TEMPDIR"/*
|
rm -rf "$TEMPDIR"/*
|
||||||
@ -441,13 +467,18 @@ fi
|
|||||||
|
|
||||||
[[ -z $TARGETS ]] && TARGETS="vmlinux modules"
|
[[ -z $TARGETS ]] && TARGETS="vmlinux modules"
|
||||||
|
|
||||||
# If no kpatch module name was provided on the command line, derive one
|
# If no kpatch module name was provided on the command line:
|
||||||
# from the .patch filename
|
# - For single input .patch, use the patch filename
|
||||||
|
# - For multiple input .patches, use "patch"
|
||||||
if [[ -z $MODNAME ]] ; then
|
if [[ -z $MODNAME ]] ; then
|
||||||
MODNAME=$(basename "$PATCHFILE")
|
if [[ ${#PATCH_LIST[@]} -eq 1 ]]; then
|
||||||
|
MODNAME=$(basename "${PATCH_LIST[0]}")
|
||||||
if [[ "$MODNAME" =~ \.patch$ ]] || [[ "$MODNAME" =~ \.diff$ ]]; then
|
if [[ "$MODNAME" =~ \.patch$ ]] || [[ "$MODNAME" =~ \.diff$ ]]; then
|
||||||
MODNAME="${MODNAME%.*}"
|
MODNAME="${MODNAME%.*}"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
MODNAME="patch"
|
||||||
|
fi
|
||||||
|
|
||||||
MODNAME=$(module_name_string "$MODNAME")
|
MODNAME=$(module_name_string "$MODNAME")
|
||||||
fi
|
fi
|
||||||
@ -604,10 +635,11 @@ fi
|
|||||||
# unsupported kernel option checking: CONFIG_DEBUG_INFO_SPLIT
|
# unsupported kernel option checking: CONFIG_DEBUG_INFO_SPLIT
|
||||||
grep -q "CONFIG_DEBUG_INFO_SPLIT=y" "$CONFIGFILE" && die "kernel option 'CONFIG_DEBUG_INFO_SPLIT' not supported"
|
grep -q "CONFIG_DEBUG_INFO_SPLIT=y" "$CONFIGFILE" && die "kernel option 'CONFIG_DEBUG_INFO_SPLIT' not supported"
|
||||||
|
|
||||||
echo "Testing patch file"
|
echo "Testing patch file(s)"
|
||||||
cd "$SRCDIR" || die
|
cd "$SRCDIR" || die
|
||||||
patch -N -p1 --dry-run < "$PATCHFILE" || die "source patch file failed to apply"
|
apply_patches
|
||||||
cp "$PATCHFILE" "$APPLIEDPATCHFILE" || die
|
remove_patches
|
||||||
|
|
||||||
cp -LR "$DATADIR/patch" "$TEMPDIR" || die
|
cp -LR "$DATADIR/patch" "$TEMPDIR" || die
|
||||||
|
|
||||||
if [[ $ARCH = "ppc64le" ]]; then
|
if [[ $ARCH = "ppc64le" ]]; then
|
||||||
@ -627,7 +659,7 @@ unset KPATCH_GCC_TEMPDIR
|
|||||||
CROSS_COMPILE="$TOOLSDIR/kpatch-gcc " make "-j$CPUS" $TARGETS >> "$LOGFILE" 2>&1 || die
|
CROSS_COMPILE="$TOOLSDIR/kpatch-gcc " make "-j$CPUS" $TARGETS >> "$LOGFILE" 2>&1 || die
|
||||||
|
|
||||||
echo "Building patched kernel"
|
echo "Building patched kernel"
|
||||||
patch -N -p1 < "$APPLIEDPATCHFILE" >> "$LOGFILE" 2>&1 || die
|
apply_patches
|
||||||
mkdir -p "$TEMPDIR/orig" "$TEMPDIR/patched"
|
mkdir -p "$TEMPDIR/orig" "$TEMPDIR/patched"
|
||||||
KPATCH_GCC_TEMPDIR=$TEMPDIR
|
KPATCH_GCC_TEMPDIR=$TEMPDIR
|
||||||
export KPATCH_GCC_TEMPDIR
|
export KPATCH_GCC_TEMPDIR
|
||||||
|
Loading…
Reference in New Issue
Block a user