Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolai Stange <nstange@suse.de>2017-06-07 12:05:41 +0200
committerMiroslav Benes <mbenes@suse.cz>2017-06-08 13:49:50 +0200
commit4e8dc885be228e6db8f3988101e63cdc466b0f1b (patch)
tree2cf07f5cd7b7f38309d10780c21f2e14d2a1538e
parent03bf1d56387d8f7614ed34bd1ddb2d81de422d53 (diff)
scripts: create kgr_patch_main.c dynamically
The kgraft-patches repository has got many branches, each corresponding to a supported codestream. Each of those carries a potentially different set of live (sub)patches which are controlled through the entry points in kgr_patch_main.c. According to Miroslav, merging of a new (sub)patch based on the pristine master is a pita due to conflicts. Since all (sub)patches stick to certain conventions already, the required modifications of the merging-hotspot kgr_patch_main.c are quite mechanic. Let a script do the work. Namely, - insert some special @@-embraced placeholders at the few places depending on the actual set of (sub)patches, - let register-patches.sh discover the available (sub)patches by searching for directories - and let register-patches.sh replace those placeholders in kgr_patch_main.c Finally, add a register-patches.sh invocation to tar-up.sh. This procedure requires that a SUBPATCH located in directory SUBPATCH/ adheres to the following conventions: - It must provide a provide a SUBPATCH/kgr_patch_SUBPATCH.h header. - This header must provide declarations for kgr_patch_SUBPATCH_init() and kgr_patch_SUBPATCH_cleanup(). - This header must also #define a KGR_PATCH_SUBPATCH_FUNCS macro. It should expand to a comma separated list of KGR_PATCH*() entries, each corresponding to a function the subpatch wants to replace. Signed-off-by: Nicolai Stange <nstange@suse.de> [mbenes: fixed typos, empty line removed] Signed-off-by: Miroslav Benes <mbenes@suse.cz>
-rw-r--r--kgr_patch_main.c13
-rwxr-xr-xscripts/register-patches.sh122
-rwxr-xr-xscripts/tar-up.sh1
3 files changed, 135 insertions, 1 deletions
diff --git a/kgr_patch_main.c b/kgr_patch_main.c
index 699aa6c..4505834 100644
--- a/kgr_patch_main.c
+++ b/kgr_patch_main.c
@@ -26,12 +26,15 @@
#include "uname_patch/kgr_patch_uname.h"
+@@KGR_PATCHES_INCLUDES@@
+
static struct kgr_patch patch = {
.name = "kgraft-patch-@@RPMRELEASE@@",
.owner = THIS_MODULE,
.replace_all = true,
.patches = {
KGR_PATCH(SyS_newuname, kgr_sys_newuname),
+ @@KGR_PATCHES_FUNCS@@,
KGR_PATCH_END
}
};
@@ -46,13 +49,21 @@ static int __init kgr_patch_init(void)
if (retval)
return retval;
- return kgr_patch_kernel(&patch);
+ @@KGR_PATCHES_INIT_CALLS@@;
+
+ retval = kgr_patch_kernel(&patch);
+ if (!retval)
+ return retval;
+
+ /* jumped to from expanded KGR_PATCHES_INIT_CALLS on failure */
+@@KGR_PATCHES_INIT_ERR_HANDLERS@@:
}
static void __exit kgr_patch_cleanup(void)
{
pr_info("kgraft-patch: removed\n");
+ @@KGR_PATCHES_CLEANUP_CALLS@@;
kgr_patch_remove(&patch);
}
diff --git a/scripts/register-patches.sh b/scripts/register-patches.sh
new file mode 100755
index 0000000..89cec61
--- /dev/null
+++ b/scripts/register-patches.sh
@@ -0,0 +1,122 @@
+#!/bin/bash
+
+#
+# register-patches.sh -- add subpatches to KGraft patch
+#
+# Copyright (c) 2017 SUSE
+# Author: Nicolai Stange <nstange@suse.de>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
+#
+
+# This script expects a kGraft subpatch to live in a subdirectory
+# SUBPATCH and to provide a SUBPATCH/kgr_patch_SUBPATCH.h
+# header.
+#
+# This header must provide declarations for
+# - kgr_patch_SUBPATCH_init()
+# - kgr_patch_SUBPATCH_cleanup()
+# and an (all uppercase) KGR_PATCH_SUBPATCH_FUNCS macro.
+# The latter should be a comma separated list of KGR_PATCH*() entries,
+# each corresponding to a function the subpatch wants to replace.
+#
+# Usage:
+# register-patches.sh kgr_patch_main.c
+#
+# This will properly substitute a number of placeholders in-place.
+#
+
+kgr_patch_main_file="$1"
+
+
+# Generate list of patches
+declare -a kgr_patches
+for d in *; do
+ [ -d "$d" ] || continue
+ [ x"$d" = xrpm -o x"$d" = xscripts -o x"$d" = xuname_patch ] && continue
+ [ -e "$d/kgr_patch_main.c" ] && continue # this is some builddir
+
+ if [ ! -f "$d/kgr_patch_${d}.h" ]; then
+ echo "error: $d/ doesn't have a $d/kgr_patch_${d}.h" 1>&2
+ exit 1
+ fi
+
+ kgr_patches[${#kgr_patches[@]}]=$(basename $d)
+done
+
+# Sort it
+kgr_patches=($(
+ for p in "${kgr_patches[@]}"; do
+ echo $p
+ done | sort))
+
+
+# Finish kgr_patch_main.c:
+## Add includes of per-patch headers.
+KGR_PATCHES_INCLUDES=$(
+ echo -n "/* Auto expanded KGR_PATCHES_INCLUDES: */\n"
+ for p in "${kgr_patches[@]}"; do
+ echo -n "#include \"${p}/kgr_patch_${p}.h\"\n"
+ done)
+
+## Add the individual patches' replacement entries to struct kgr_patch.
+KGR_PATCHES_FUNCS=$(
+ echo -n "\t\t/* Auto expanded KGR_PATCHES_FUNCS: */\n"
+ for p in "${kgr_patches[@]}"; do
+ p="KGR_PATCH_$(echo $p | tr '[:lower:]' '[:upper:]')_FUNCS"
+ echo -n "\t\t${p},\n"
+ done | sed 's/\\n$//' # rm trailing extra newlines
+)
+
+## Initialize the individual patches in kgr_patch_init().
+KGR_PATCHES_INIT_CALLS=$(
+ echo -n "\t/* Auto expanded KGR_PATCHES_INIT_CALLS: */\n"
+ for p in "${kgr_patches[@]}"; do
+ cat <<EOF
+ retval = kgr_patch_${p}_init();
+ if (retval)
+ goto err_${p};
+
+EOF
+ done | sed 's%\t%\\t%g' | sed 's%$%\\n%g' | tr -d '\n' \
+ | sed 's/\(\\n\)\?\\n$//' # rm trailing extra newlines
+)
+
+## Setup the rollback error handlers in kgr_patch_init().
+KGR_PATCHES_INIT_ERR_HANDLERS=$(
+ echo -n "\t/* Auto expanded KGR_PATCHES_INIT_ERR_HANDLERS: */\n"
+ for i in $(seq $((${#kgr_patches[@]} - 1)) -1 0); do
+ cat <<EOF
+ kgr_patch_${kgr_patches[$i]}_cleanup();
+err_${kgr_patches[$i]}:
+EOF
+ done | sed 's%\t%\\t%g' | sed 's%$%\\n%g' | tr -d '\n';
+ echo "\treturn retval;"
+)
+
+## Cleanup the individual patches in kgr_patch_cleanup().
+KGR_PATCHES_CLEANUP_CALLS=$(
+ echo -n "\t/* Auto expanded KGR_PATCHES_CLEANUP_CALLS: */\n"
+ for p in "${kgr_patches[@]}"; do
+ echo -n "\tkgr_patch_${p}_cleanup();\n"
+ done)
+
+sed -i -f - "$kgr_patch_main_file" <<EOF
+s%@@KGR_PATCHES_INCLUDES@@%$KGR_PATCHES_INCLUDES%;
+s%\s*@@KGR_PATCHES_FUNCS@@,\?%$KGR_PATCHES_FUNCS%;
+s%\s*@@KGR_PATCHES_INIT_CALLS@@;\?%$KGR_PATCHES_INIT_CALLS%;
+s%\s*@@KGR_PATCHES_INIT_ERR_HANDLERS@@:\?%$KGR_PATCHES_INIT_ERR_HANDLERS%;
+s%\s*@@KGR_PATCHES_CLEANUP_CALLS@@;\?%$KGR_PATCHES_CLEANUP_CALLS%;
+s%\s*@@KGR_PATCHES_CLEANUP_CALLS@@;\?%$KGR_PATCHES_CLEANUP_CALLS%;
+EOF
diff --git a/scripts/tar-up.sh b/scripts/tar-up.sh
index 9bdbd45..5622787 100755
--- a/scripts/tar-up.sh
+++ b/scripts/tar-up.sh
@@ -73,6 +73,7 @@ done
source $(dirname $0)/release-version.sh
install -m 644 kgr_patch_main.c $build_dir
+scripts/register-patches.sh $build_dir/kgr_patch_main.c
install -m 644 rpm/kgraft-patch.spec $build_dir/kgraft-patch-"$RELEASE".spec
install -m 644 rpm/config.sh $build_dir/config.sh
install -m 644 compat.h $build_dir