<div dir="ltr"><div dir="ltr">Hi Kieran,</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 14 Oct 2021 at 13:16, Kieran Bingham <<a href="mailto:kieran.bingham@ideasonboard.com">kieran.bingham@ideasonboard.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Quoting Naushir Patuck (2021-10-14 11:16:35)<br>
> When distributions build and package libcamera libraries, they may not<br>
> necessarily run the build in the upstream source tree. In these cases, the git<br>
> SHA1 versioning information will be lost.<br>
> <br>
> This change addresses that problem by requiring package managers to run<br>
> 'meson dist' to create a tarball of the source files and build from there.<br>
> On runing 'meson dist', the utils/run-dist.sh script will create a<br>
> .tarball-version file in the release tarball with the version string generated<br>
> from the existing utils/gen-version.sh script.<br>
> <br>
> The utils/gen-version.sh script has been updated to check for the presence of<br>
> this .tarball-version file and read the version string from it instead of<br>
> creating one.<br>
> <br>
> Signed-off-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com" target="_blank">naush@raspberrypi.com</a>><br>
> ---<br>
>  meson.build               |  3 +++<br>
>  src/libcamera/meson.build | 11 +++++------<br>
>  utils/gen-version.sh      |  9 +++++++++<br>
>  utils/run-dist.sh         | 11 +++++++++++<br>
>  4 files changed, 28 insertions(+), 6 deletions(-)<br>
>  create mode 100644 utils/run-dist.sh<br>
> <br>
> diff --git a/meson.build b/meson.build<br>
> index a49c484fe64e..67be6762108c 100644<br>
> --- a/meson.build<br>
> +++ b/meson.build<br>
> @@ -24,6 +24,9 @@ endif<br>
>  <br>
>  libcamera_version = libcamera_git_version.split('+')[0]<br>
>  <br>
> +# This script gererates the .tarball-version file on a 'meson dist' command.<br>
> +meson.add_dist_script('utils/run-dist.sh')<br>
> +<br>
>  # Configure the build environment.<br>
>  cc = meson.get_compiler('c')<br>
>  cxx = meson.get_compiler('cpp')<br>
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build<br>
> index 243dd3c180eb..360eaf80ecf1 100644<br>
> --- a/src/libcamera/meson.build<br>
> +++ b/src/libcamera/meson.build<br>
> @@ -93,12 +93,11 @@ endforeach<br>
>  <br>
>  libcamera_sources += control_sources<br>
>  <br>
> -gen_version = meson.source_root() / 'utils' / 'gen-version.sh'<br>
> -<br>
> -version_cpp = vcs_tag(command : [gen_version, meson.build_root()],<br>
> -                      input : '<a href="http://version.cpp.in" rel="noreferrer" target="_blank">version.cpp.in</a>',<br>
> -                      output : 'version.cpp',<br>
> -                      fallback : meson.project_version())<br>
> +version_data = configuration_data()<br>
> +version_data.set('VCS_TAG', libcamera_git_version)<br>
<br>
configuration_data() is already available as config_h, so I think we can<br>
use that directly instead of version_data.<br>
<br>
> +version_cpp = configure_file(input : '<a href="http://version.cpp.in" rel="noreferrer" target="_blank">version.cpp.in</a>',<br>
> +                             output : 'version.cpp',<br>
> +                             configuration : version_data)<br>
>  <br>
>  libcamera_sources += version_cpp<br>
>  <br>
> diff --git a/utils/gen-version.sh b/utils/gen-version.sh<br>
> index b09ad495f86a..216b1ff0b33e 100755<br>
> --- a/utils/gen-version.sh<br>
> +++ b/utils/gen-version.sh<br>
> @@ -5,6 +5,15 @@<br>
>  <br>
>  build_dir="$1"<br>
>  <br>
> +# If .tarball-version exists, output the version string from the file and exit.<br>
> +# This file is auto-generated on a 'meson dist' command from the run-dist.sh<br>
> +# script.<br>
> +if [ -f "${MESON_SOURCE_ROOT}"/.tarball-version ]<br>
> +then<br>
> +       cat "${MESON_SOURCE_ROOT}"/.tarball-version<br>
> +       exit 0<br>
> +fi<br>
> +<br>
<br>
I'm not sure I'm keen on tieing this script to require MESON variables.<br>
<br>
Would this script need to read .tarball-version if called externally<br>
from meson? Perhaps not...<br>
<br>
<br>
The script already processes $1 as the build_dir as passed from meson.<br>
<br>
The sources are available under $build_dir/sources/ ... so I wonder if<br>
it's cleaner to use that somehow.<br>
<br>
But it's probably fine to use the env variables too.<br></blockquote><div><br></div><div>Oops, this change has been superseded with v4.  In that version, we do</div><div>not use the env variables anymore.  They are instead passed into the</div><div>script as cmd line arguments.</div><div><br></div><div>Regards,</div><div>Naush</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
--<br>
Kieran<br>
<br>
<br>
<br>
>  # Bail out if the directory isn't under git control<br>
>  src_dir=$(git rev-parse --git-dir 2>&1) || exit 1<br>
>  src_dir=$(readlink -f "$src_dir/..")<br>
> diff --git a/utils/run-dist.sh b/utils/run-dist.sh<br>
> new file mode 100644<br>
> index 000000000000..e89c3733b56c<br>
> --- /dev/null<br>
> +++ b/utils/run-dist.sh<br>
> @@ -0,0 +1,11 @@<br>
> +#!/bin/sh<br>
> +<br>
> +# SPDX-License-Identifier: GPL-2.0-or-later<br>
> +#<br>
> +# On a meson dist run, generate the version string and store it in a file.<br>
> +# This will later be picked up by the utils/gen-version.sh script and used<br>
> +# instead of re-generating it. This way, if we are not building in the upstream<br>
> +# git source tree, the upstream version information will be preserved.<br>
> +<br>
> +cd "$MESON_SOURCE_ROOT" || return<br>
> +./utils/gen-version.sh > "$MESON_DIST_ROOT"/.tarball-version<br>
> -- <br>
> 2.25.1<br>
><br>
</blockquote></div></div>