diff mbox series

rootfs-postcommands: Make /etc/timestamp consistent with image

Message ID 20220829235935.670738-1-wak@google.com
State New
Headers show
Series rootfs-postcommands: Make /etc/timestamp consistent with image | expand

Commit Message

William Kennington Aug. 29, 2022, 11:59 p.m. UTC
This makes the determination of the timestamp for the /etc/timestamp
file consistent with mtimes in the generated image. This is desirable to
make the built image reproducible with the git commit date instead of
the current date.

Change-Id: I7d9fe32906aa93baf53948aa40b7a98fb05dd384
Signed-off-by: William A. Kennington III <wak@google.com>
---
 meta/classes-recipe/rootfs-postcommands.bbclass | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Mark Hatle Aug. 30, 2022, 12:15 a.m. UTC | #1
On 8/29/22 6:59 PM, William A. Kennington III via lists.openembedded.org wrote:
> This makes the determination of the timestamp for the /etc/timestamp
> file consistent with mtimes in the generated image. This is desirable to
> make the built image reproducible with the git commit date instead of
> the current date.

This is only going to pay attention to poky, or oe-core...  the rootfs will vary 
with a change to ANY layer in the system.

If you really want to be consistent you would need to iterate over all of the 
layers and look at every file in the system for the timestamp (or if they're git 
repositories last commit in each layer..)

All of this doesn't seem like it really makes sense to me which is why a static 
timestamp was defined previously.

(with the previous change to the time stamps, I've had more then one user get 
concerned they were 'using old software' when they just built something from 
scratch -- this will get even more confusing if it's only based on the 
oe-core/poky repository.)

--Mark

> Change-Id: I7d9fe32906aa93baf53948aa40b7a98fb05dd384
> Signed-off-by: William A. Kennington III <wak@google.com>
> ---
>   meta/classes-recipe/rootfs-postcommands.bbclass | 12 +++++++-----
>   1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/meta/classes-recipe/rootfs-postcommands.bbclass b/meta/classes-recipe/rootfs-postcommands.bbclass
> index 215e38e33d..8d710186d7 100644
> --- a/meta/classes-recipe/rootfs-postcommands.bbclass
> +++ b/meta/classes-recipe/rootfs-postcommands.bbclass
> @@ -312,12 +312,14 @@ python write_image_manifest () {
>   # Can be used to create /etc/timestamp during image construction to give a reasonably
>   # sane default time setting
>   rootfs_update_timestamp () {
> -	if [ "${REPRODUCIBLE_TIMESTAMP_ROOTFS}" != "" ]; then
> -		# Convert UTC into %4Y%2m%2d%2H%2M%2S
> -		sformatted=`date -u -d @${REPRODUCIBLE_TIMESTAMP_ROOTFS} +%4Y%2m%2d%2H%2M%2S`
> -	else
> -		sformatted=`date -u +%4Y%2m%2d%2H%2M%2S`
> +	if [ "$REPRODUCIBLE_TIMESTAMP_ROOTFS" = "" ]; then
> +		REPRODUCIBLE_TIMESTAMP_ROOTFS=`git -C "${COREBASE}" log -1 --pretty=%ct 2>/dev/null` || true
> +		if [ "$REPRODUCIBLE_TIMESTAMP_ROOTFS" = "" ]; then
> +			REPRODUCIBLE_TIMESTAMP_ROOTFS=`stat -c%Y ${@bb.utils.which(d.getVar("BBPATH"), "conf/bitbake.conf")}`
> +		fi
>   	fi
> +	# Convert UTC into %4Y%2m%2d%2H%2M%2S
> +	sformatted=`date -u -d @${REPRODUCIBLE_TIMESTAMP_ROOTFS} +%4Y%2m%2d%2H%2M%2S`
>   	echo $sformatted > ${IMAGE_ROOTFS}/etc/timestamp
>   	bbnote "rootfs_update_timestamp: set /etc/timestamp to $sformatted"
>   }
> 
> 
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#170041): https://lists.openembedded.org/g/openembedded-core/message/170041
> Mute This Topic: https://lists.openembedded.org/mt/93339153/3616948
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [mark.hatle@kernel.crashing.org]
> -=-=-=-=-=-=-=-=-=-=-=-
>
William Kennington Aug. 30, 2022, 12:39 a.m. UTC | #2
On Mon, Aug 29, 2022 at 5:19 PM Mark Hatle <mark.hatle@kernel.crashing.org>
wrote:

>
>
> On 8/29/22 6:59 PM, William A. Kennington III via lists.openembedded.org
> wrote:
> > This makes the determination of the timestamp for the /etc/timestamp
> > file consistent with mtimes in the generated image. This is desirable to
> > make the built image reproducible with the git commit date instead of
> > the current date.
>
> This is only going to pay attention to poky, or oe-core...  the rootfs
> will vary
> with a change to ANY layer in the system.


Yes, this is what I expect. It is following the same behavior as
image.bbclass.


> If you really want to be consistent you would need to iterate over all of
> the
> layers and look at every file in the system for the timestamp (or if
> they're git
> repositories last commit in each layer..)
>
>
I'm just looking for consistency with the image generation side of things
that set the timestamp based on the same logic flow. It's weird that they
used different logic for setting timestamps in the output image. Sure we
could improve the most recent timestamp by looking at all the git repos of
all the meta layers, but that's not the point of this change.


> All of this doesn't seem like it really makes sense to me which is why a
> static
> timestamp was defined previously.
>

That's fine too, we just want our builds to have reasonably recent
timestamps that are deterministic when REPRODUCIBLE_TIMESTAMP_ROOTFS is
unset.


>
> (with the previous change to the time stamps, I've had more then one user
> get
> concerned they were 'using old software' when they just built something
> from
> scratch -- this will get even more confusing if it's only based on the
> oe-core/poky repository.)
>
> --Mark
>
> > Change-Id: I7d9fe32906aa93baf53948aa40b7a98fb05dd384
> > Signed-off-by: William A. Kennington III <wak@google.com>
> > ---
> >   meta/classes-recipe/rootfs-postcommands.bbclass | 12 +++++++-----
> >   1 file changed, 7 insertions(+), 5 deletions(-)
> >
> > diff --git a/meta/classes-recipe/rootfs-postcommands.bbclass
> b/meta/classes-recipe/rootfs-postcommands.bbclass
> > index 215e38e33d..8d710186d7 100644
> > --- a/meta/classes-recipe/rootfs-postcommands.bbclass
> > +++ b/meta/classes-recipe/rootfs-postcommands.bbclass
> > @@ -312,12 +312,14 @@ python write_image_manifest () {
> >   # Can be used to create /etc/timestamp during image construction to
> give a reasonably
> >   # sane default time setting
> >   rootfs_update_timestamp () {
> > -     if [ "${REPRODUCIBLE_TIMESTAMP_ROOTFS}" != "" ]; then
> > -             # Convert UTC into %4Y%2m%2d%2H%2M%2S
> > -             sformatted=`date -u -d @${REPRODUCIBLE_TIMESTAMP_ROOTFS}
> +%4Y%2m%2d%2H%2M%2S`
> > -     else
> > -             sformatted=`date -u +%4Y%2m%2d%2H%2M%2S`
> > +     if [ "$REPRODUCIBLE_TIMESTAMP_ROOTFS" = "" ]; then
> > +             REPRODUCIBLE_TIMESTAMP_ROOTFS=`git -C "${COREBASE}" log -1
> --pretty=%ct 2>/dev/null` || true
> > +             if [ "$REPRODUCIBLE_TIMESTAMP_ROOTFS" = "" ]; then
> > +                     REPRODUCIBLE_TIMESTAMP_ROOTFS=`stat -c%Y
> ${@bb.utils.which(d.getVar("BBPATH"), "conf/bitbake.conf")}`
> > +             fi
> >       fi
> > +     # Convert UTC into %4Y%2m%2d%2H%2M%2S
> > +     sformatted=`date -u -d @${REPRODUCIBLE_TIMESTAMP_ROOTFS}
> +%4Y%2m%2d%2H%2M%2S`
> >       echo $sformatted > ${IMAGE_ROOTFS}/etc/timestamp
> >       bbnote "rootfs_update_timestamp: set /etc/timestamp to $sformatted"
> >   }
> >
> >
> >
> > -=-=-=-=-=-=-=-=-=-=-=-
> > Links: You receive all messages sent to this group.
> > View/Reply Online (#170041):
> https://lists.openembedded.org/g/openembedded-core/message/170041
> > Mute This Topic: https://lists.openembedded.org/mt/93339153/3616948
> > Group Owner: openembedded-core+owner@lists.openembedded.org
> > Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [
> mark.hatle@kernel.crashing.org]
> > -=-=-=-=-=-=-=-=-=-=-=-
> >
>
diff mbox series

Patch

diff --git a/meta/classes-recipe/rootfs-postcommands.bbclass b/meta/classes-recipe/rootfs-postcommands.bbclass
index 215e38e33d..8d710186d7 100644
--- a/meta/classes-recipe/rootfs-postcommands.bbclass
+++ b/meta/classes-recipe/rootfs-postcommands.bbclass
@@ -312,12 +312,14 @@  python write_image_manifest () {
 # Can be used to create /etc/timestamp during image construction to give a reasonably
 # sane default time setting
 rootfs_update_timestamp () {
-	if [ "${REPRODUCIBLE_TIMESTAMP_ROOTFS}" != "" ]; then
-		# Convert UTC into %4Y%2m%2d%2H%2M%2S
-		sformatted=`date -u -d @${REPRODUCIBLE_TIMESTAMP_ROOTFS} +%4Y%2m%2d%2H%2M%2S`
-	else
-		sformatted=`date -u +%4Y%2m%2d%2H%2M%2S`
+	if [ "$REPRODUCIBLE_TIMESTAMP_ROOTFS" = "" ]; then
+		REPRODUCIBLE_TIMESTAMP_ROOTFS=`git -C "${COREBASE}" log -1 --pretty=%ct 2>/dev/null` || true
+		if [ "$REPRODUCIBLE_TIMESTAMP_ROOTFS" = "" ]; then
+			REPRODUCIBLE_TIMESTAMP_ROOTFS=`stat -c%Y ${@bb.utils.which(d.getVar("BBPATH"), "conf/bitbake.conf")}`
+		fi
 	fi
+	# Convert UTC into %4Y%2m%2d%2H%2M%2S
+	sformatted=`date -u -d @${REPRODUCIBLE_TIMESTAMP_ROOTFS} +%4Y%2m%2d%2H%2M%2S`
 	echo $sformatted > ${IMAGE_ROOTFS}/etc/timestamp
 	bbnote "rootfs_update_timestamp: set /etc/timestamp to $sformatted"
 }