commit:     a3d49067e775c640a146514d68755dc0a4c6c613
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 15 17:59:44 2019 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Mon Jul 15 17:59:44 2019 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=a3d49067

Add "--module-rebuild" parameter

MODULEREBUILD option will be enabled by default.

When enabled and we are building a non-static kernel for the same
host (no cross-compile!), also building modules and install into
into a non-custom location, we will now call `emerge @module-rebuild`.

Closes: https://bugs.gentoo.org/453372
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 doc/genkernel.8.txt  |  6 ++++++
 gen_cmdline.sh       |  7 +++++++
 gen_compile.sh       | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 gen_determineargs.sh |  1 +
 genkernel            |  1 +
 genkernel.conf       |  6 +++++-
 6 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/doc/genkernel.8.txt b/doc/genkernel.8.txt
index 8b38279..177be51 100644
--- a/doc/genkernel.8.txt
+++ b/doc/genkernel.8.txt
@@ -170,6 +170,12 @@ KERNEL COMPILATION
 *--*[*no-*]*all-ramdisk-modules*::
     Copies or does not copy all kernel modules to the initrd.
 
+*--*[*no-*]*module-rebuild*::
+    Runs, or does not run "emerge @module-rebuild" to build out-of-tree
+    modules when possible, i.e. when non-static kernel and modules will be
+    build, installed, no custom INSTALL_MOD_PATH is set,
+    '/var/lib/module-rebuild/moduledb' exists and is not empty.
+
 *--callback*=<...>::
     Run the specified arguments in the current environment after the
     kernel and modules have been compiled.

diff --git a/gen_cmdline.sh b/gen_cmdline.sh
index 098e3d4..9f1b7cf 100755
--- a/gen_cmdline.sh
+++ b/gen_cmdline.sh
@@ -62,6 +62,9 @@ longusage() {
   echo "       --ramdisk-modules       Copy required modules to the initramfs"
   echo "       --no-ramdisk-modules    Don't copy any modules to the initramfs"
   echo "       --all-ramdisk-modules   Copy all kernel modules to the 
initramfs"
+  echo "       --module-rebuild        Automatically run 'emerge 
@module-rebuild' when"
+  echo "                               necessary (and possible)"
+  echo "       --no-module-rebuild     Don't automatically run 'emerge 
@module-rebuild'"
   echo "       --callback=<...>        Run the specified arguments after the"
   echo "                               kernel and modules have been compiled"
   echo "       --static                Build a static (monolithic kernel)"
@@ -569,6 +572,10 @@ parse_cmdline() {
                        CMD_ALLRAMDISKMODULES=$(parse_optbool "$*")
                        print_info 2 "CMD_ALLRAMDISKMODULES: 
${CMD_ALLRAMDISKMODULES}"
                        ;;
+               --module-rebuild|--no-module-rebuild)
+                       CMD_MODULEREBUILD=$(parse_optbool "$*")
+                       print_info 2 "CMD_MODULEREBUILD: ${CMD_MODULEREBUILD}"
+                       ;;
                --callback=*)
                        CMD_CALLBACK="${*#*=}"
                        print_info 2 "CMD_CALLBACK: ${CMD_CALLBACK}/$*"

diff --git a/gen_compile.sh b/gen_compile.sh
index f62d80d..cc7b1aa 100755
--- a/gen_compile.sh
+++ b/gen_compile.sh
@@ -1,6 +1,59 @@
 #!/bin/bash
 # $Id$
 
+compile_external_modules() {
+       local command="emerge --quiet @module-rebuild 2>&1"
+
+       if ! isTrue "${CMD_MODULEREBUILD}"
+       then
+               print_info 3 "$(get_indent 1)>> --no-module-rebuild set; 
Skipping 'emerge @module-rebuild' ..."
+               return
+       fi
+
+       if isTrue "$(tc-is-cross-compiler)"
+       then
+               print_info 3 "$(get_indent 1)>> Cross-compilation detected; 
Skipping 'emerge @module-rebuild' ..."
+               return
+       fi
+
+       if ! isTrue "${CMD_INSTALL}"
+       then
+               print_info 3 "$(get_indent 1)>> --no-install set; Skipping 
'emerge @module-rebuild' ..."
+               return
+       fi
+
+       if [ -n "${INSTALL_MOD_PATH}" ]
+       then
+               # emerge would install to a different location
+               print_warning 1 "$(get_indent 1)>> INSTALL_MOD_PATH set; 
Skipping 'emerge @module-rebuild' ..."
+               return
+       fi
+
+       local modulesdb_file="/var/lib/module-rebuild/moduledb"
+       if [ ! -s "${modulesdb_file}" ]
+       then
+               print_info 2 "$(get_indent 1)>> '${modulesdb_file}' does not 
exist or is empty; Skipping 'emerge @module-rebuild' ..."
+               return
+       fi
+
+       print_info 1 "$(get_indent 1)>> Compiling out-of-tree module(s) ..."
+       print_info 2 "COMMAND: ${command}" 1 0 1
+
+       if [ "${LOGLEVEL}" -gt 3 ]
+       then
+               # Output to stdout and logfile
+               eval ${command} | tee -a "${LOGFILE}"
+               RET=${PIPESTATUS[0]}
+       else
+               # Output to logfile only
+               eval ${command} >> "${LOGFILE}"
+               RET=$?
+       fi
+
+       [ ${RET} -ne 0 ] \
+               && gen_die "$(get_useful_function_stack 
"${FUNCNAME}")${FUNCNAME}() failed to compile out-of-tree-modules!"
+}
+
 compile_gen_init_cpio() {
        local gen_init_cpio_SRC="${KERNEL_DIR}/usr/gen_init_cpio.c"
        local gen_init_cpio_DIR="${KERNEL_OUTPUTDIR}/usr"

diff --git a/gen_determineargs.sh b/gen_determineargs.sh
index 1b3abf8..9fa8357 100755
--- a/gen_determineargs.sh
+++ b/gen_determineargs.sh
@@ -133,6 +133,7 @@ determine_real_args() {
 
        set_config_with_override STRING MINKERNPACKAGE           
CMD_MINKERNPACKAGE
        set_config_with_override STRING MODULESPACKAGE           
CMD_MODULESPACKAGE
+       set_config_with_override BOOL   MODULEREBUILD            
CMD_MODULEREBUILD            "yes"
        set_config_with_override STRING KERNCACHE                CMD_KERNCACHE
        set_config_with_override BOOL   RAMDISKMODULES           
CMD_RAMDISKMODULES           "yes"
        set_config_with_override BOOL   ALLRAMDISKMODULES        
CMD_ALLRAMDISKMODULES        "no"

diff --git a/genkernel b/genkernel
index 15f7fbc..391879e 100755
--- a/genkernel
+++ b/genkernel
@@ -238,6 +238,7 @@ then
        if isTrue "${BUILD_MODULES}" && ! isTrue "${BUILD_STATIC}"
        then
                compile_modules
+               compile_external_modules
        fi
 
        if isTrue "${SAVE_CONFIG}"

diff --git a/genkernel.conf b/genkernel.conf
index 9d809f5..cad0297 100644
--- a/genkernel.conf
+++ b/genkernel.conf
@@ -156,9 +156,13 @@ NOCOLOR="false"
 # This supersedes the "SPLASH_THEME" option in '/etc/conf.d/splash'.
 #SPLASH_THEME="gentoo"
 
+# Run "emerge @module-rebuild" automatically when possible and necessary
+# after kernel and modules have been compiled
+#MODULEREBUILD="yes"
+
 # Run the specified command in the current environment after the kernel and
 # modules have been compiled, useful to rebuild external kernel module
-# (use "emerge --quiet @module-rebuild" for >=portage-2.2) or installing 
additional
+# (see MODULEREBUILD above) or installing additional
 # files (use 'copy_image_with_preserve dtb path/to/dtb dtb 
${KNAME}-${ARCH}-${KV}')
 #CMD_CALLBACK=""
 

Reply via email to