[4/4] kernel/reproducibility: factor kernel source epoch for common use

Submitted by Bruce Ashfield on May 13, 2020, 2:24 p.m. | Patch ID: 172548

Details

Message ID d09f4c9abf8c9e0ff342c4b5d6323eb371391c63.1589378829.git.bruce.ashfield@gmail.com
State Master Next
Commit b71cc765762b03aafed7454c8ddaf5d782f3718b
Headers show

Commit Message

Bruce Ashfield May 13, 2020, 2:24 p.m.
From: Bruce Ashfield <bruce.ashfield@gmail.com>

Rather than duplicating the code to generate the kbuild environment
variable: KBUILD_BUILD_TIMESTAMP, we can factor the checks into a
python function and call it from the main image and kernel module
do_compile routines.

All paths have been checked and the timestamp is identical to the
previous shell variant.

Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
---
 meta/classes/kernel.bbclass | 43 ++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 24 deletions(-)

Patch hide | download patch | download mbox

diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass
index a3990aaf59..de63e1c0f6 100644
--- a/meta/classes/kernel.bbclass
+++ b/meta/classes/kernel.bbclass
@@ -153,6 +153,21 @@  python do_symlink_kernsrc () {
 }
 addtask symlink_kernsrc before do_configure after do_unpack
 
+def get_kernel_source_date_epoch(d):
+    import subprocess
+
+    s_d_e = d.getVar("SOURCE_DATE_EPOCH")
+    if not s_d_e:
+        s_d_e = subprocess.check_output(['git', '--git-dir=%s/.git' % d.getVar('S'), 'log', '-1', '--pretty=%ct']).decode('utf-8')
+        if not s_d_e:
+            s_d_e = d.getVar("REPRODUCIBLE_TIMESTAMP_ROOTFS")
+
+    env = os.environ.copy()
+    env['LC_ALL'] = 'C'
+    ts = subprocess.check_output(['date', '-d @%s' % s_d_e]).decode('utf-8')
+
+    return ts
+
 inherit kernel-arch deploy
 
 PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*"
@@ -291,19 +306,9 @@  get_cc_option () {
 kernel_do_compile() {
 	unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
 	if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
-		# kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
-		# be set....
-		if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
-			# The source directory is not necessarily a git repository, so we
-			# specify the git-dir to ensure that git does not query a
-			# repository in any parent directory.
-			SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
-		fi
-
-		ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
-		export KBUILD_BUILD_TIMESTAMP="$ts"
+		export KBUILD_BUILD_TIMESTAMP="${@ get_kernel_source_date_epoch(d)}"
 		export KCONFIG_NOTIMESTAMP=1
-		bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
+		bbnote "KBUILD_BUILD_TIMESTAMP: $KBUILD_BUILD_TIMESTAMP"
 	fi
 	# The $use_alternate_initrd is only set from
 	# do_bundle_initramfs() This variable is specifically for the
@@ -332,19 +337,9 @@  kernel_do_compile() {
 do_compile_kernelmodules() {
 	unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
 	if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
-		# kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
-		# be set....
-		if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
-			# The source directory is not necessarily a git repository, so we
-			# specify the git-dir to ensure that git does not query a
-			# repository in any parent directory.
-			SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
-		fi
-
-		ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
-		export KBUILD_BUILD_TIMESTAMP="$ts"
+		export KBUILD_BUILD_TIMESTAMP="${@ get_kernel_source_date_epoch(d)}"
 		export KCONFIG_NOTIMESTAMP=1
-		bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
+		bbnote "KBUILD_BUILD_TIMESTAMP: $KBUILD_BUILD_TIMESTAMP"
 	fi
 	if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
 		cc_extra=$(get_cc_option)

Comments

Bruce Ashfield May 13, 2020, 2:26 p.m.
On Wed, May 13, 2020 at 10:24 AM <bruce.ashfield@gmail.com> wrote:
>
> From: Bruce Ashfield <bruce.ashfield@gmail.com>
>
> Rather than duplicating the code to generate the kbuild environment
> variable: KBUILD_BUILD_TIMESTAMP, we can factor the checks into a
> python function and call it from the main image and kernel module
> do_compile routines.
>
> All paths have been checked and the timestamp is identical to the
> previous shell variant.
>
> Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
> ---
>  meta/classes/kernel.bbclass | 43 ++++++++++++++++---------------------
>  1 file changed, 19 insertions(+), 24 deletions(-)
>
> diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass
> index a3990aaf59..de63e1c0f6 100644
> --- a/meta/classes/kernel.bbclass
> +++ b/meta/classes/kernel.bbclass
> @@ -153,6 +153,21 @@ python do_symlink_kernsrc () {
>  }
>  addtask symlink_kernsrc before do_configure after do_unpack
>
> +def get_kernel_source_date_epoch(d):
> +    import subprocess
> +
> +    s_d_e = d.getVar("SOURCE_DATE_EPOCH")
> +    if not s_d_e:
> +        s_d_e = subprocess.check_output(['git', '--git-dir=%s/.git' % d.getVar('S'), 'log', '-1', '--pretty=%ct']).decode('utf-8')
> +        if not s_d_e:
> +            s_d_e = d.getVar("REPRODUCIBLE_TIMESTAMP_ROOTFS")
> +
> +    env = os.environ.copy()
> +    env['LC_ALL'] = 'C'

Hah.

Of course after my send, I see that I'm not actually *using* the env.
I'll do an incremental patch to use env while this sits on the list.

Bruce

> +    ts = subprocess.check_output(['date', '-d @%s' % s_d_e]).decode('utf-8')
> +
> +    return ts
> +
>  inherit kernel-arch deploy
>
>  PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*"
> @@ -291,19 +306,9 @@ get_cc_option () {
>  kernel_do_compile() {
>         unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
>         if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
> -               # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
> -               # be set....
> -               if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
> -                       # The source directory is not necessarily a git repository, so we
> -                       # specify the git-dir to ensure that git does not query a
> -                       # repository in any parent directory.
> -                       SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
> -               fi
> -
> -               ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
> -               export KBUILD_BUILD_TIMESTAMP="$ts"
> +               export KBUILD_BUILD_TIMESTAMP="${@ get_kernel_source_date_epoch(d)}"
>                 export KCONFIG_NOTIMESTAMP=1
> -               bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
> +               bbnote "KBUILD_BUILD_TIMESTAMP: $KBUILD_BUILD_TIMESTAMP"
>         fi
>         # The $use_alternate_initrd is only set from
>         # do_bundle_initramfs() This variable is specifically for the
> @@ -332,19 +337,9 @@ kernel_do_compile() {
>  do_compile_kernelmodules() {
>         unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
>         if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
> -               # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
> -               # be set....
> -               if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
> -                       # The source directory is not necessarily a git repository, so we
> -                       # specify the git-dir to ensure that git does not query a
> -                       # repository in any parent directory.
> -                       SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
> -               fi
> -
> -               ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
> -               export KBUILD_BUILD_TIMESTAMP="$ts"
> +               export KBUILD_BUILD_TIMESTAMP="${@ get_kernel_source_date_epoch(d)}"
>                 export KCONFIG_NOTIMESTAMP=1
> -               bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
> +               bbnote "KBUILD_BUILD_TIMESTAMP: $KBUILD_BUILD_TIMESTAMP"
>         fi
>         if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
>                 cc_extra=$(get_cc_option)
> --
> 2.19.1
>
Joshua Watt May 14, 2020, 5:11 p.m.
On 5/13/20 9:24 AM, Bruce Ashfield wrote:
> From: Bruce Ashfield <bruce.ashfield@gmail.com>
>
> Rather than duplicating the code to generate the kbuild environment
> variable: KBUILD_BUILD_TIMESTAMP, we can factor the checks into a
> python function and call it from the main image and kernel module
> do_compile routines.
>
> All paths have been checked and the timestamp is identical to the
> previous shell variant.
>
> Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
> ---
>   meta/classes/kernel.bbclass | 43 ++++++++++++++++---------------------
>   1 file changed, 19 insertions(+), 24 deletions(-)
>
> diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass
> index a3990aaf59..de63e1c0f6 100644
> --- a/meta/classes/kernel.bbclass
> +++ b/meta/classes/kernel.bbclass
> @@ -153,6 +153,21 @@ python do_symlink_kernsrc () {
>   }
>   addtask symlink_kernsrc before do_configure after do_unpack
>   
> +def get_kernel_source_date_epoch(d):
> +    import subprocess
> +
> +    s_d_e = d.getVar("SOURCE_DATE_EPOCH")
> +    if not s_d_e:
> +        s_d_e = subprocess.check_output(['git', '--git-dir=%s/.git' % d.getVar('S'), 'log', '-1', '--pretty=%ct']).decode('utf-8')
> +        if not s_d_e:
> +            s_d_e = d.getVar("REPRODUCIBLE_TIMESTAMP_ROOTFS")
> +
> +    env = os.environ.copy()
> +    env['LC_ALL'] = 'C'
> +    ts = subprocess.check_output(['date', '-d @%s' % s_d_e]).decode('utf-8')
> +
> +    return ts
> +

Is there something special about the kernel that it can't use the 
SOURCE_DATE_EPOCH guessing code from classes/reproducible_build.bbclass? 
If so, is it possible there is some minor change we could make to the 
code to make it work? It seems a little unfortunate to replicate the 
logic to calculate the SDE when that class does it already.


>   inherit kernel-arch deploy
>   
>   PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*"
> @@ -291,19 +306,9 @@ get_cc_option () {
>   kernel_do_compile() {
>   	unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
>   	if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
> -		# kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
> -		# be set....
> -		if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
> -			# The source directory is not necessarily a git repository, so we
> -			# specify the git-dir to ensure that git does not query a
> -			# repository in any parent directory.
> -			SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
> -		fi
> -
> -		ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
> -		export KBUILD_BUILD_TIMESTAMP="$ts"
> +		export KBUILD_BUILD_TIMESTAMP="${@ get_kernel_source_date_epoch(d)}"
>   		export KCONFIG_NOTIMESTAMP=1
> -		bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
> +		bbnote "KBUILD_BUILD_TIMESTAMP: $KBUILD_BUILD_TIMESTAMP"
>   	fi
>   	# The $use_alternate_initrd is only set from
>   	# do_bundle_initramfs() This variable is specifically for the
> @@ -332,19 +337,9 @@ kernel_do_compile() {
>   do_compile_kernelmodules() {
>   	unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
>   	if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
> -		# kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
> -		# be set....
> -		if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
> -			# The source directory is not necessarily a git repository, so we
> -			# specify the git-dir to ensure that git does not query a
> -			# repository in any parent directory.
> -			SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
> -		fi
> -
> -		ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
> -		export KBUILD_BUILD_TIMESTAMP="$ts"
> +		export KBUILD_BUILD_TIMESTAMP="${@ get_kernel_source_date_epoch(d)}"
>   		export KCONFIG_NOTIMESTAMP=1
> -		bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
> +		bbnote "KBUILD_BUILD_TIMESTAMP: $KBUILD_BUILD_TIMESTAMP"
>   	fi
>   	if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
>   		cc_extra=$(get_cc_option)
>
>
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#138277): https://lists.openembedded.org/g/openembedded-core/message/138277
Mute This Topic: https://lists.openembedded.org/mt/74182751/3617530
Group Owner: openembedded-core+owner@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub  [oe-patchwork@oe-patch.openembedded.org]
-=-=-=-=-=-=-=-=-=-=-=-
Bruce Ashfield May 14, 2020, 7:25 p.m.
On Thu, May 14, 2020 at 1:11 PM Joshua Watt <jpewhacker@gmail.com> wrote:
>
>
> On 5/13/20 9:24 AM, Bruce Ashfield wrote:
>
> From: Bruce Ashfield <bruce.ashfield@gmail.com>
>
> Rather than duplicating the code to generate the kbuild environment
> variable: KBUILD_BUILD_TIMESTAMP, we can factor the checks into a
> python function and call it from the main image and kernel module
> do_compile routines.
>
> All paths have been checked and the timestamp is identical to the
> previous shell variant.
>
> Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
> ---
>  meta/classes/kernel.bbclass | 43 ++++++++++++++++---------------------
>  1 file changed, 19 insertions(+), 24 deletions(-)
>
> diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass
> index a3990aaf59..de63e1c0f6 100644
> --- a/meta/classes/kernel.bbclass
> +++ b/meta/classes/kernel.bbclass
> @@ -153,6 +153,21 @@ python do_symlink_kernsrc () {
>  }
>  addtask symlink_kernsrc before do_configure after do_unpack
>
> +def get_kernel_source_date_epoch(d):
> +    import subprocess
> +
> +    s_d_e = d.getVar("SOURCE_DATE_EPOCH")
> +    if not s_d_e:
> +        s_d_e = subprocess.check_output(['git', '--git-dir=%s/.git' % d.getVar('S'), 'log', '-1', '--pretty=%ct']).decode('utf-8')
> +        if not s_d_e:
> +            s_d_e = d.getVar("REPRODUCIBLE_TIMESTAMP_ROOTFS")
> +
> +    env = os.environ.copy()
> +    env['LC_ALL'] = 'C'
> +    ts = subprocess.check_output(['date', '-d @%s' % s_d_e]).decode('utf-8')
> +
> +    return ts
> +
>
> Is there something special about the kernel that it can't use the SOURCE_DATE_EPOCH guessing code from classes/reproducible_build.bbclass? If so, is it possible there is some minor change we could make to the code to make it work? It seems a little unfortunate to replicate the logic to calculate the SDE when that class does it already.
>

That's where it is getting the SOURCE_DATE_EPOCH from in the first
line. Only if it isn't set is it falling back and querying the top git
commit and finally the timestamp.

Or at least that's what I understood it to be doing :D

Bruce

>
>  inherit kernel-arch deploy
>
>  PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*"
> @@ -291,19 +306,9 @@ get_cc_option () {
>  kernel_do_compile() {
>   unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
>   if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
> - # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
> - # be set....
> - if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
> - # The source directory is not necessarily a git repository, so we
> - # specify the git-dir to ensure that git does not query a
> - # repository in any parent directory.
> - SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
> - fi
> -
> - ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
> - export KBUILD_BUILD_TIMESTAMP="$ts"
> + export KBUILD_BUILD_TIMESTAMP="${@ get_kernel_source_date_epoch(d)}"
>   export KCONFIG_NOTIMESTAMP=1
> - bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
> + bbnote "KBUILD_BUILD_TIMESTAMP: $KBUILD_BUILD_TIMESTAMP"
>   fi
>   # The $use_alternate_initrd is only set from
>   # do_bundle_initramfs() This variable is specifically for the
> @@ -332,19 +337,9 @@ kernel_do_compile() {
>  do_compile_kernelmodules() {
>   unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
>   if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
> - # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
> - # be set....
> - if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
> - # The source directory is not necessarily a git repository, so we
> - # specify the git-dir to ensure that git does not query a
> - # repository in any parent directory.
> - SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
> - fi
> -
> - ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
> - export KBUILD_BUILD_TIMESTAMP="$ts"
> + export KBUILD_BUILD_TIMESTAMP="${@ get_kernel_source_date_epoch(d)}"
>   export KCONFIG_NOTIMESTAMP=1
> - bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
> + bbnote "KBUILD_BUILD_TIMESTAMP: $KBUILD_BUILD_TIMESTAMP"
>   fi
>   if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
>   cc_extra=$(get_cc_option)
>
>
>
Bruce Ashfield May 14, 2020, 7:32 p.m.
On Thu, May 14, 2020 at 3:25 PM Bruce Ashfield <bruce.ashfield@gmail.com> wrote:
>
> On Thu, May 14, 2020 at 1:11 PM Joshua Watt <jpewhacker@gmail.com> wrote:
> >
> >
> > On 5/13/20 9:24 AM, Bruce Ashfield wrote:
> >
> > From: Bruce Ashfield <bruce.ashfield@gmail.com>
> >
> > Rather than duplicating the code to generate the kbuild environment
> > variable: KBUILD_BUILD_TIMESTAMP, we can factor the checks into a
> > python function and call it from the main image and kernel module
> > do_compile routines.
> >
> > All paths have been checked and the timestamp is identical to the
> > previous shell variant.
> >
> > Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
> > ---
> >  meta/classes/kernel.bbclass | 43 ++++++++++++++++---------------------
> >  1 file changed, 19 insertions(+), 24 deletions(-)
> >
> > diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass
> > index a3990aaf59..de63e1c0f6 100644
> > --- a/meta/classes/kernel.bbclass
> > +++ b/meta/classes/kernel.bbclass
> > @@ -153,6 +153,21 @@ python do_symlink_kernsrc () {
> >  }
> >  addtask symlink_kernsrc before do_configure after do_unpack
> >
> > +def get_kernel_source_date_epoch(d):
> > +    import subprocess
> > +
> > +    s_d_e = d.getVar("SOURCE_DATE_EPOCH")
> > +    if not s_d_e:
> > +        s_d_e = subprocess.check_output(['git', '--git-dir=%s/.git' % d.getVar('S'), 'log', '-1', '--pretty=%ct']).decode('utf-8')
> > +        if not s_d_e:
> > +            s_d_e = d.getVar("REPRODUCIBLE_TIMESTAMP_ROOTFS")
> > +
> > +    env = os.environ.copy()
> > +    env['LC_ALL'] = 'C'
> > +    ts = subprocess.check_output(['date', '-d @%s' % s_d_e]).decode('utf-8')
> > +
> > +    return ts
> > +
> >
> > Is there something special about the kernel that it can't use the SOURCE_DATE_EPOCH guessing code from classes/reproducible_build.bbclass? If so, is it possible there is some minor change we could make to the code to make it work? It seems a little unfortunate to replicate the logic to calculate the SDE when that class does it already.
> >
>
> That's where it is getting the SOURCE_DATE_EPOCH from in the first
> line. Only if it isn't set is it falling back and querying the top git
> commit and finally the timestamp.
>
> Or at least that's what I understood it to be doing :D

.. or maybe that isn't what you are asking ? That python code is just
a direct replacement of the existing logic that is currently in the
kernel.bbclass that follows the kernel's guidelines for reproducible
builds. I wasn't looking to change the logic, or move it to another
class, just to avoid cutting and pasting the block of code into the
kernel module build phase (which is what I did in the first patch).

Cheers,

Bruce

>
> Bruce
>
> >
> >  inherit kernel-arch deploy
> >
> >  PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*"
> > @@ -291,19 +306,9 @@ get_cc_option () {
> >  kernel_do_compile() {
> >   unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
> >   if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
> > - # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
> > - # be set....
> > - if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
> > - # The source directory is not necessarily a git repository, so we
> > - # specify the git-dir to ensure that git does not query a
> > - # repository in any parent directory.
> > - SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
> > - fi
> > -
> > - ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
> > - export KBUILD_BUILD_TIMESTAMP="$ts"
> > + export KBUILD_BUILD_TIMESTAMP="${@ get_kernel_source_date_epoch(d)}"
> >   export KCONFIG_NOTIMESTAMP=1
> > - bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
> > + bbnote "KBUILD_BUILD_TIMESTAMP: $KBUILD_BUILD_TIMESTAMP"
> >   fi
> >   # The $use_alternate_initrd is only set from
> >   # do_bundle_initramfs() This variable is specifically for the
> > @@ -332,19 +337,9 @@ kernel_do_compile() {
> >  do_compile_kernelmodules() {
> >   unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
> >   if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
> > - # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
> > - # be set....
> > - if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
> > - # The source directory is not necessarily a git repository, so we
> > - # specify the git-dir to ensure that git does not query a
> > - # repository in any parent directory.
> > - SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
> > - fi
> > -
> > - ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
> > - export KBUILD_BUILD_TIMESTAMP="$ts"
> > + export KBUILD_BUILD_TIMESTAMP="${@ get_kernel_source_date_epoch(d)}"
> >   export KCONFIG_NOTIMESTAMP=1
> > - bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
> > + bbnote "KBUILD_BUILD_TIMESTAMP: $KBUILD_BUILD_TIMESTAMP"
> >   fi
> >   if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
> >   cc_extra=$(get_cc_option)
> >
> >
> > 
>
>
>
> --
> - Thou shalt not follow the NULL pointer, for chaos and madness await
> thee at its end
> - "Use the force Harry" - Gandalf, Star Trek II