From 5c73c936e84b0eeb9f595b39488deceb5cb509ab Mon Sep 17 00:00:00 2001
From: Daniel Santos <daniel.santos@pobox.com>
Date: Tue, 30 Oct 2018 20:54:00 -0500
Subject: [PATCH] Add option to build external kernel tree (experimental)
This patch modifies quilt and adds the root .config options that can be
configured to cause the OpenWRT / quilt build to re-construct a real git
tree using a base git reference and then applying the kernel patches
using git am or git apply.
You only need to enable this and run the build one time, after which you
should generally disable the option and configure OpenWRT to *use* the
external kernel directory, which inhibits OpenWRT from reconstructing
(extracting and patching) your kernel tree.
This patch still needs cleanup (removal of commented out code, etc.)
land probably also refinement. Also, it is not perfect at
reconstructing the logical patch history due to the "files" directories
that must be applied as a set of mega-patches (one for generic and one
for the arch files), but it's step in the right direction.
Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
---
config/Config-devel.in | 28 +++++++++++++++++++++++++
include/quilt.mk | 6 ++++++
scripts/patch-kernel.sh | 45 ++++++++++++++++++++++++++++++++++++-----
3 files changed, 74 insertions(+), 5 deletions(-)
@@ -73,6 +73,34 @@ menuconfig DEVEL
string "Use external kernel tree" if DEVEL
default ""
+ config EXTERNAL_KERNEL_TREE_BUILD_GIT
+ bool "Build git tree from OpenWRT patches." if DEVEL
+ depends on !KERNEL_GIT_CLONE_URI
+ default n
+ help
+ Uses git to clone the upstream kernel and then apply OpenWRT
+ patches with git-am or git-apply to create a proper Linux
+ kernel git tree.
+
+ TODO: needs more explanation.
+
+ config EXTERNAL_KERNEL_TREE_BUILD_GIT_URI
+ bool "Upstream git URI" if DEVEL
+ depends on EXTERNAL_KERNEL_TREE_BUILD_GIT
+ default "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
+ help
+ Where to clone the Linux tree from. You probably want the
+ default unless you already have a local copy you want to
+ clone.
+
+ config EXTERNAL_KERNEL_TREE_BUILD_GIT_REF
+ bool "Local referenceBuild git tree from OpenWRT patches." if DEVEL
+ depends on EXTERNAL_KERNEL_TREE_BUILD_GIT
+ default ""
+ help
+ Use git clone --dissociate --reference-if-able <local_dir>
+ when cloning to reduce network traffic.
+
config KERNEL_GIT_CLONE_URI
string "Enter git repository to clone" if DEVEL
default ""
@@ -95,7 +95,13 @@ endef
kernel_files=$(foreach fdir,$(GENERIC_FILES_DIR) $(FILES_DIR),$(fdir)/.)
define Kernel/Patch/Default
$(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
+
+ #echo "copy files is next"
+ #read
$(if $(kernel_files),$(CP) $(kernel_files) $(LINUX_DIR)/)
+
+ #echo "remove (old?) rejects and patch..."
+ #read
find $(LINUX_DIR)/ -name \*.rej -or -name \*.orig | $(XARGS) rm -f
if [ -d $(GENERIC_PLATFORM_DIR)/patches$(if $(wildcard $(GENERIC_PLATFORM_DIR)/patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER)) ]; then \
echo "generic patches directory is present. please move your patches to the pending directory" ; \
@@ -18,7 +18,20 @@ if [ ! -d "${patchdir}" ] ; then
echo "Aborting. '${patchdir}' is not a directory."
exit 1
fi
-
+
+fixit() {
+ op="$1"
+ file="$2"
+ patch="$3"
+ shift 3
+ echo "$op failed on $file ($patch). $@"
+ /bin/bash
+ while [ -n "`git status --porcelain`" ]; do
+ echo "git repo not clean, please try again"
+ /bin/bash
+ done
+}
+
for i in ${patchdir}/${patchpattern} ; do
case "$i" in
*.gz)
@@ -37,12 +50,34 @@ for i in ${patchdir}/${patchpattern} ; do
[ -d "${i}" ] && echo "Ignoring subdirectory ${i}" && continue
echo ""
echo "Applying ${i} using ${type}: "
- ${uncomp} ${i} | ${PATCH:-patch} -f -p1 -d ${targetdir}
- if [ $? != 0 ] ; then
- echo "Patch failed! Please fix $i!"
- exit 1
+ if true; then
+ if ! ${uncomp} ${i} | ${PATCH:-patch} -f -p1 -d ${targetdir}; then
+ echo "Patch failed! Please fix $i!"
+ exit 1
+ fi
+ else
+ pushd "${targetdir}"
+ p=/tmp/patch.$$
+ ${uncomp} ${i} > ${p}
+ if ! git am < ${p}; then
+ git am --abort || fixit "git am --abort" $i $p
+ [ -z "`git status --porcelain`" ] || fixit "git status" $i $p "tree not clean"
+ git apply < $p || fixit "git apply" $i $p
+ git add -A && git commit -am "`basename $i`" || fixit "git add and commit" $i $p
+# if [ -n "`git status --porcelain`" ]; then
+# echo "files left over, please fix (maybe git add -A and git commit --amend)"
+# /bin/bash
+# fi
+
+# echo "maybe git am -3i < $p"
+# echo "maybe git apply < $p && git commit -am '`basename $i`'"
+# fixit "git am" $i $p
+ fi
+ rm $p
+ popd
fi
done
+popd
# Check for rejects...
if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
--
2.19.2