[OE-core] [PATCH] image_types: improve reproducibility of .cpio files.

Andre McCurdy armccurdy at gmail.com
Thu May 24 21:56:27 UTC 2018


On Thu, May 24, 2018 at 2:27 PM, Kamel Hacene <kamel.hacene at smile.fr> wrote:
> When BUILD_REPRODUCIBLE_BINARIES is set, run cpio command with the
> --reproducible flag and set the timestamp of the created /init file to
> REPRODUCIBLE_TIMESTAMP_ROOTFS in accordance with reproducible_final_image_task
> in image.bbclass.
>
> Signed-off-by: Kamel Hacene <kamel.hacene at smile.fr>
> ---
>  meta/classes/image_types.bbclass | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/meta/classes/image_types.bbclass b/meta/classes/image_types.bbclass
> index 00a00d318f..345dba5358 100644
> --- a/meta/classes/image_types.bbclass
> +++ b/meta/classes/image_types.bbclass
> @@ -127,9 +127,16 @@ IMAGE_CMD_TAR ?= "tar"
>  # ignore return code 1 "file changed as we read it" as other tasks(e.g. do_image_wic) may be hardlinking rootfs
>  IMAGE_CMD_tar = "${IMAGE_CMD_TAR} --numeric-owner -cf ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.tar -C ${IMAGE_ROOTFS} . || [ $? -eq 1 ]"
>
> +# Extra options given to the cpio command
> +CPIO_EXTRA_OPTS ?= ""
> +CPIO_EXTRA_OPTS += "${@'--reproducible' if d.getVar('BUILD_REPRODUCIBLE_BINARIES') == '1' else ''}"
>  do_image_cpio[cleandirs] += "${WORKDIR}/cpio_append"
>  IMAGE_CMD_cpio () {
> -       (cd ${IMAGE_ROOTFS} && find . | cpio -o -H newc >${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.cpio)
> +       # Ensure cpio provides --reproducible option if generating a reproducible binary
> +       if [ "$BUILD_REPRODUCIBLE_BINARIES" = "1" ] && ! cpio --help | grep -q "\-\-reproducible"; then
> +               bbfatal "cpio v2.12 or higher is required to generate a reproducible binary. Upgrade your host's cpio command or use oe's cpio recipe by adding a depend to cpio-native in your image."

If the host version of cpio can't be relied on it would be better to
make use of cpio-native.

> +       fi
> +       (cd ${IMAGE_ROOTFS} && find . | cpio ${CPIO_EXTRA_OPTS} -o -H newc >${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.cpio)
>         # We only need the /init symlink if we're building the real
>         # image. The -dbg image doesn't need it! By being clever
>         # about this we also avoid 'touch' below failing, as it
> @@ -142,7 +149,10 @@ IMAGE_CMD_cpio () {
>                         else
>                                 touch ${WORKDIR}/cpio_append/init
>                         fi
> -                       (cd  ${WORKDIR}/cpio_append && echo ./init | cpio -oA -H newc -F ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.cpio)
> +                       if [ "$BUILD_REPRODUCIBLE_BINARIES" = "1" ]; then
> +                               touch --no-dereference --date=@${REPRODUCIBLE_TIMESTAMP_ROOTFS} ${WORKDIR}/cpio_append/init
> +                       fi
> +                       (cd  ${WORKDIR}/cpio_append && echo ./init | cpio ${CPIO_EXTRA_OPTS} -oA -H newc -F ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.cpio)
>                 fi
>         fi
>  }
> --
> 2.16.2
>
> --
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core at lists.openembedded.org
> http://lists.openembedded.org/mailman/listinfo/openembedded-core



More information about the Openembedded-core mailing list