Re: [gentoo-dev] [PATCH v2 1/4] kernel-install.eclass: Install logic for dist-kernels

2020-01-06 Thread Michał Górny
On Sun, 2020-01-05 at 07:30 +, Robin H. Johnson wrote:
> On Sun, Jan 05, 2020 at 07:27:38AM +0100, Michał Górny wrote:
> > Introduce a new eclass that contains common logic needed to test
> > and install distribution kernels.  This is the eclass common both
> > to kernels built from source and installed from binary packages.
> I'm 100% in favour of the concept here, but I have some implementation
> concerns.
> 
> For the (public) record, Infra has been wrapping genkernel to build
> binary kernel + initramfs for internal usage for 5 years now.
> 
> Conceptually, can you clarify why you are depending on dracut here,
> rather than using genkernel's initramfs mode?

For a start, because dracut is not bundling all its dependencies.  It's
also tested outside Gentoo, so it has much wider testing than genkernel,
and doesn't suffer from intermediate deaths, -next forks and total
confusion over which version should be used.

> I'm not sure you're going to get correct build output in cases like
> x86_64 -> x86 cross-compiles.

Cross-compile support is untested, and provided merely where it was
clear how to do it.  I'm happy to fix it later, when someone figures it
out.

> Why not call genkernel from the ebuild instead of re-inventing the
> wheel to compile the kernel yourself.

Have you read the logic and found a way to achieve all that from
genkernel, without 1) losing advantages of my approach, 2) adding a huge
dependency to replace 5 lines of code?

-- 
Best regards,
Michał Górny



signature.asc
Description: This is a digitally signed message part


Re: [gentoo-dev] [PATCH v2 1/4] kernel-install.eclass: Install logic for dist-kernels

2020-01-06 Thread Robin H. Johnson
On Sun, Jan 05, 2020 at 07:27:38AM +0100, Michał Górny wrote:
> Introduce a new eclass that contains common logic needed to test
> and install distribution kernels.  This is the eclass common both
> to kernels built from source and installed from binary packages.
I'm 100% in favour of the concept here, but I have some implementation
concerns.

For the (public) record, Infra has been wrapping genkernel to build
binary kernel + initramfs for internal usage for 5 years now.

Conceptually, can you clarify why you are depending on dracut here,
rather than using genkernel's initramfs mode?

I'm not sure you're going to get correct build output in cases like
x86_64 -> x86 cross-compiles.

Why not call genkernel from the ebuild instead of re-inventing the
wheel to compile the kernel yourself.

-- 
Robin Hugh Johnson
Gentoo Linux: Dev, Infra Lead, Foundation Treasurer
E-Mail   : robb...@gentoo.org
GnuPG FP : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85
GnuPG FP : 7D0B3CEB E9B85B1F 825BCECF EE05E6F6 A48F6136


signature.asc
Description: PGP signature


[gentoo-dev] [PATCH v2 1/4] kernel-install.eclass: Install logic for dist-kernels

2020-01-04 Thread Michał Górny
Introduce a new eclass that contains common logic needed to test
and install distribution kernels.  This is the eclass common both
to kernels built from source and installed from binary packages.

Signed-off-by: Michał Górny 
---
 eclass/kernel-install.eclass | 309 +++
 1 file changed, 309 insertions(+)
 create mode 100644 eclass/kernel-install.eclass

diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
new file mode 100644
index ..f64e01976a7b
--- /dev/null
+++ b/eclass/kernel-install.eclass
@@ -0,0 +1,309 @@
+# Copyright 2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: kernel-install.eclass
+# @MAINTAINER:
+# Distribution Kernel Project 
+# @AUTHOR:
+# Michał Górny 
+# @SUPPORTED_EAPIS: 7
+# @BLURB: Installation mechanics for Distribution Kernels
+# @DESCRIPTION:
+# This eclass provides the logic needed to test and install different
+# kinds of Distribution Kernel packages, including both kernels built
+# from source and distributed as binaries.  The eclass relies on the
+# ebuild installing a subset of built kernel tree into
+# /usr/src/linux-${PV} containing the kernel image in its standard
+# location and System.map.
+#
+# The eclass exports src_test, pkg_postinst and pkg_postrm.
+# Additionally, the inherited mount-boot eclass exports pkg_pretend.
+# It also stubs out pkg_preinst and pkg_prerm defined by mount-boot.
+
+if [[ ! ${_KERNEL_INSTALL_ECLASS} ]]; then
+
+case "${EAPI:-0}" in
+   0|1|2|3|4|5|6)
+   die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
+   ;;
+   7)
+   ;;
+   *)
+   die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
+   ;;
+esac
+
+inherit mount-boot
+
+TCL_VER=10.1
+SRC_URI+="
+   test? (
+   amd64? (
+   
https://dev.gentoo.org/~mgorny/dist/tinycorelinux-${TCL_VER}-amd64.qcow2
+   )
+   x86? (
+   
https://dev.gentoo.org/~mgorny/dist/tinycorelinux-${TCL_VER}-x86.qcow2
+   )
+   )"
+
+SLOT="${PV}"
+IUSE="+initramfs test"
+RESTRICT+=" !test? ( test ) test? ( userpriv )"
+
+# install-DEPEND actually
+# note: we need installkernel with initramfs support!
+RDEPEND="
+   || (
+   sys-kernel/installkernel-gentoo
+   sys-kernel/installkernel-systemd-boot
+   )
+   initramfs? ( >=sys-kernel/dracut-049-r3 )"
+BDEPEND="
+   test? (
+   dev-tcltk/expect
+   sys-kernel/dracut
+   amd64? ( app-emulation/qemu[qemu_softmmu_targets_x86_64] )
+   x86? ( app-emulation/qemu[qemu_softmmu_targets_i386] )
+   )"
+
+# @FUNCTION: kernel-install_build_initramfs
+# @USAGE:  
+# @DESCRIPTION:
+# Build an initramfs for the kernel.   specifies the absolute
+# path where initramfs will be created, while  specifies
+# the kernel version, used to find modules.
+kernel-install_build_initramfs() {
+   debug-print-function ${FUNCNAME} "${@}"
+
+   [[ ${#} -eq 2 ]] || die "${FUNCNAME}: invalid arguments"
+   local output=${1}
+   local version=${2}
+
+   ebegin "Building initramfs via dracut"
+   dracut --force "${output}" "${version}"
+   eend ${?} || die "Building initramfs failed"
+}
+
+# @FUNCTION: kernel-install_get_image_path
+# @DESCRIPTION:
+# Get relative kernel image path specific to the current ${ARCH}.
+kernel-install_get_image_path() {
+   case ${ARCH} in
+   amd64|x86)
+   echo arch/x86/boot/bzImage
+   ;;
+   *)
+   die "${FUNCNAME}: unsupported ARCH=${ARCH}"
+   ;;
+   esac
+}
+
+# @FUNCTION: kernel-install_install_kernel
+# @USAGE:   
+# @DESCRIPTION:
+# Install kernel using installkernel tool.   specifies
+# the kernel version,  full path to the image, 
+# full path to System.map.
+kernel-install_install_kernel() {
+   debug-print-function ${FUNCNAME} "${@}"
+
+   [[ ${#} -eq 3 ]] || die "${FUNCNAME}: invalid arguments"
+   local version=${1}
+   local image=${2}
+   local map=${3}
+
+   ebegin "Installing the kernel via installkernel"
+   # note: .config is taken relatively to System.map;
+   # initrd relatively to bzImage
+   installkernel "${version}" "${image}" "${map}"
+   eend ${?} || die "Installing the kernel failed"
+}
+
+# @FUNCTION: kernel-install_update_symlink
+# @USAGE:  
+# @DESCRIPTION:
+# Update the kernel source symlink at  (full path) with a link
+# to - if it's either missing or pointing out to
+# an older version of this package.
+kernel-install_update_symlink() {
+   debug-print-function ${FUNCNAME} "${@}"
+
+   [[ ${#} -eq 2 ]] || die "${FUNCNAME}: invalid arguments"
+   local target=${1}
+   local version=${2}
+
+   if [[ ! -e ${target} ]]; then
+   ebegin "Creating ${targe