[{"id":20177,"web_url":"https://patchwork.libcamera.org/comment/20177/","msgid":"<CAEmqJPozBmDgpjSEGuGt=L3aJ3L_qAE=Hu6SCaD_ZNcmGfxn4w@mail.gmail.com>","date":"2021-10-13T10:20:53","subject":"Re: [libcamera-devel] [RFC 1/1] build: Preserve upstream git\n\tversioning using meson dist","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"On Wed, 13 Oct 2021 at 11:19, Naushir Patuck <naush@raspberrypi.com> wrote:\n\n> When distributions build and package libcamera libraries, they may not\n> necessarily run the build in the upstream source tree. In these cases, the\n> git\n> SHA1 versioning information will be lost.\n>\n> This change addresses that problem by requiring package managers to run\n> 'meson dist' to create a tarball of the source files and build from there.\n> On runing 'meson dist', the utils/run-dist.sh script will create a\n> version.gen\n> file in the release tarball with the version string generated from the\n> existing\n> utils/gen-version.sh script.\n>\n> The build system has been updated to check for the presence of this\n> version.gen\n> file and read the version string from it. If the file is not present, the\n> version string is generated by running utils/gen-version.sh as it currently\n> does.\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  meson.build               | 30 ++++++++++++++++++++----------\n>  src/libcamera/meson.build | 11 +++++------\n>  utils/run-dist.sh         |  9 +++++++++\n>  3 files changed, 34 insertions(+), 16 deletions(-)\n>  create mode 100644 utils/run-dist.sh\n>\n> diff --git a/meson.build b/meson.build\n> index a49c484fe64e..f27bfd479a5c 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -10,20 +10,30 @@ project('libcamera', 'c', 'cpp',\n>      ],\n>      license : 'LGPL 2.1+')\n>\n> -# Generate version information. The libcamera_git_version variable\n> contains the\n> -# full version with git patch count and SHA1 (e.g. 1.2.3+211-c94a24f4),\n> while\n> -# the libcamera_version variable contains the major.minor.patch (e.g.\n> 1.2.3)\n> -# only. If the source tree isn't under git control, or if it matches the\n> last\n> -# git version tag, the build metadata (e.g. +211-c94a24f4) is omitted from\n> -# libcamera_git_version.\n> -libcamera_git_version = run_command('utils/gen-version.sh',\n> -                                    meson.build_root()).stdout().strip()\n> -if libcamera_git_version == ''\n> -    libcamera_git_version = meson.project_version()\n> +fs_mod = import('fs')\n> +if not fs_mod.is_file('version.gen')\n> +    # Generate version information. The libcamera_git_version variable\n> contains the\n> +    # the full version with git patch count and SHA1 (e.g.\n> 1.2.3+211-c94a24f4), while\n> +    # the libcamera_version variable contains the major.minor.patch (e.g.\n> 1.2.3)\n> +    # only. If the source tree isn't under git control, or if it matches\n> the last\n> +    # git version tag, the build metadata (e.g. +211-c94a24f4) is omitted\n> from\n> +    # libcamera_git_version.\n> +    libcamera_git_version = run_command('utils/gen-version.sh',\n> +\n> meson.build_root()).stdout().strip()\n> +    if libcamera_git_version == ''\n> +        libcamera_git_version = meson.project_version()\n> +    endif\n> +else\n> +    # Read the version information from the file generated by the\n> utils/run-dist.sh\n> +    # script on a 'meson dist' command.\n> +    libcamera_git_version = run_command(['cat',\n> 'version.gen']).stdout().strip()\n>  endif\n>\n\nI've added an if clause here to check for the presence of the version file,\nbut I\ncould equally leave this as-is and check for the file in gen-version.sh.  I\ndon't have\na strong preference either way.\n\nNaush\n\n\n>\n>  libcamera_version = libcamera_git_version.split('+')[0]\n>\n> +# This script gererates the version.gen file on a 'meson dist' command.\n> +meson.add_dist_script('utils/run-dist.sh')\n> +\n>  # Configure the build environment.\n>  cc = meson.get_compiler('c')\n>  cxx = meson.get_compiler('cpp')\n> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> index 243dd3c180eb..360eaf80ecf1 100644\n> --- a/src/libcamera/meson.build\n> +++ b/src/libcamera/meson.build\n> @@ -93,12 +93,11 @@ endforeach\n>\n>  libcamera_sources += control_sources\n>\n> -gen_version = meson.source_root() / 'utils' / 'gen-version.sh'\n> -\n> -version_cpp = vcs_tag(command : [gen_version, meson.build_root()],\n> -                      input : 'version.cpp.in',\n> -                      output : 'version.cpp',\n> -                      fallback : meson.project_version())\n> +version_data = configuration_data()\n> +version_data.set('VCS_TAG', libcamera_git_version)\n> +version_cpp = configure_file(input : 'version.cpp.in',\n> +                             output : 'version.cpp',\n> +                             configuration : version_data)\n>\n>  libcamera_sources += version_cpp\n>\n> diff --git a/utils/run-dist.sh b/utils/run-dist.sh\n> new file mode 100644\n> index 000000000000..1b2a6348c6bc\n> --- /dev/null\n> +++ b/utils/run-dist.sh\n> @@ -0,0 +1,9 @@\n> +#!/bin/sh\n> +\n> +# SPDX-License-Identifier: GPL-2.0-or-later\n> +#\n> +# On a meson dist run, generate the version string and store it in a file.\n> +# This will late be picked up by the build system and used in place of\n> running\n> +# the utils/gen-version.sh script again since we may not be running in the\n> +# upstream git source tree, and so version information would be lost.\n> +\"$MESON_DIST_ROOT\"/utils/gen-version.sh > \"$MESON_DIST_ROOT\"/version.gen\n> --\n> 2.25.1\n>\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B5F9DC323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 13 Oct 2021 10:21:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3FA1068F4B;\n\tWed, 13 Oct 2021 12:21:11 +0200 (CEST)","from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com\n\t[IPv6:2a00:1450:4864:20::12b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0144D60501\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Oct 2021 12:21:09 +0200 (CEST)","by mail-lf1-x12b.google.com with SMTP id p16so9705844lfa.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Oct 2021 03:21:09 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"BlqYzrqZ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to;\n\tbh=QQko1wtGga2euzoSbMjND4eWC6dc0N81HLncJC4bT9w=;\n\tb=BlqYzrqZ2oB/18rzVn5w2Q/hLV6uQpflTyHLbNyCwL42QoicmurRrGaL/6XaqGjlGT\n\twvzjLGqqkYX6I8F+/8HqbdwnEZfvQ0B1wCWE+mJzP4UPxSfCnBUN6ZbpyWknjxst8i2P\n\tna54yK6iIWDg0E9PiVjGoQMzaMXOel9lj0AeNxkxiYBol1aixtbUQoUKbao0/5O2Gsor\n\tcobnjRTRjY3KRJmvR42nh4qMDxfnBgzhMyXb2o87s+92VdjgiaTSw0g0NqLs8PoRKkxi\n\tKmrvAQFGwGANqsJVObDGk/5eYC1VhQAEOxFDxODnbD/tEvqgtKbW9e0n/fIjJr3eFLAV\n\tlwHA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to;\n\tbh=QQko1wtGga2euzoSbMjND4eWC6dc0N81HLncJC4bT9w=;\n\tb=kyM7uauh6aSaSL/ePzXa2X9ZdXa55vlGPEfxPF6dT1ZiTDrEaYE4utGHowOvBnugCA\n\tF0Vs6BNWnioF9p3fJi+jlcLj9c9njtMPVbKQ5tfsfQDTweI76Pu7HEAfKxXiLtCw8SRH\n\tQUcYb+Nnh6Yy8Pf6lU7aiJ8F2w9t6KS6TWbncB2Ghzfi3uXHfqOORTEfvHWvAOZ2MXn/\n\tGGUkoz6nL9m3QriYogOwa+wqreBUKxW52KCQKjibpNfJyQnTFl6+UFnREyZ1lvOwlffe\n\tqbmH9K6VNsBUYWh4GqNdTM9VP0pwaf23MgyUIe1rReJHeD2XtSQkLr5SyuLw0l/Hse0j\n\tuWjA==","X-Gm-Message-State":"AOAM530C/AvAchFlF/dnw7o3sA0a0j5g+I/mgKIWvibEGihiTGEv1xFf\n\tcBxI1xu12xxOy61B4V4J3lxIdS2ACNT0H2SJItoErUd7+Q3i2g==","X-Google-Smtp-Source":"ABdhPJxPT6lrnKmR/Dwcjsu03IBrcSmnSZ1dzkABd9HmDk1MOU+yloUya52m7B3/5/q5x5mox80qGCA/A+EGWNxUyj0=","X-Received":"by 2002:a2e:530b:: with SMTP id\n\th11mr35871487ljb.372.1634120469157; \n\tWed, 13 Oct 2021 03:21:09 -0700 (PDT)","MIME-Version":"1.0","References":"<20211013101650.1810576-1-naush@raspberrypi.com>\n\t<20211013101650.1810576-2-naush@raspberrypi.com>","In-Reply-To":"<20211013101650.1810576-2-naush@raspberrypi.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Wed, 13 Oct 2021 11:20:53 +0100","Message-ID":"<CAEmqJPozBmDgpjSEGuGt=L3aJ3L_qAE=Hu6SCaD_ZNcmGfxn4w@mail.gmail.com>","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"multipart/alternative; boundary=\"00000000000015b1c805ce3952b4\"","Subject":"Re: [libcamera-devel] [RFC 1/1] build: Preserve upstream git\n\tversioning using meson dist","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":20179,"web_url":"https://patchwork.libcamera.org/comment/20179/","msgid":"<YWa3MtdGJ9h2s06r@pendragon.ideasonboard.com>","date":"2021-10-13T10:38:42","subject":"Re: [libcamera-devel] [RFC 1/1] build: Preserve upstream git\n\tversioning using meson dist","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Naush,\n\nThank you for the patch.\n\nOn Wed, Oct 13, 2021 at 11:20:53AM +0100, Naushir Patuck wrote:\n> On Wed, 13 Oct 2021 at 11:19, Naushir Patuck wrote:\n> > When distributions build and package libcamera libraries, they may not\n> > necessarily run the build in the upstream source tree. In these cases, the git\n> > SHA1 versioning information will be lost.\n> >\n> > This change addresses that problem by requiring package managers to run\n> > 'meson dist' to create a tarball of the source files and build from there.\n> > On runing 'meson dist', the utils/run-dist.sh script will create a version.gen\n> > file in the release tarball with the version string generated from the existing\n> > utils/gen-version.sh script.\n> >\n> > The build system has been updated to check for the presence of this version.gen\n> > file and read the version string from it. If the file is not present, the\n> > version string is generated by running utils/gen-version.sh as it currently\n> > does.\n> >\n> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> > ---\n> >  meson.build               | 30 ++++++++++++++++++++----------\n> >  src/libcamera/meson.build | 11 +++++------\n> >  utils/run-dist.sh         |  9 +++++++++\n> >  3 files changed, 34 insertions(+), 16 deletions(-)\n> >  create mode 100644 utils/run-dist.sh\n> >\n> > diff --git a/meson.build b/meson.build\n> > index a49c484fe64e..f27bfd479a5c 100644\n> > --- a/meson.build\n> > +++ b/meson.build\n> > @@ -10,20 +10,30 @@ project('libcamera', 'c', 'cpp',\n> >      ],\n> >      license : 'LGPL 2.1+')\n> >\n> > -# Generate version information. The libcamera_git_version variable contains the\n> > -# full version with git patch count and SHA1 (e.g. 1.2.3+211-c94a24f4), while\n> > -# the libcamera_version variable contains the major.minor.patch (e.g. 1.2.3)\n> > -# only. If the source tree isn't under git control, or if it matches the last\n> > -# git version tag, the build metadata (e.g. +211-c94a24f4) is omitted from\n> > -# libcamera_git_version.\n> > -libcamera_git_version = run_command('utils/gen-version.sh',\n> > -                                    meson.build_root()).stdout().strip()\n> > -if libcamera_git_version == ''\n> > -    libcamera_git_version = meson.project_version()\n> > +fs_mod = import('fs')\n> > +if not fs_mod.is_file('version.gen')\n> > +    # Generate version information. The libcamera_git_version variable contains the\n> > +    # the full version with git patch count and SHA1 (e.g. 1.2.3+211-c94a24f4), while\n> > +    # the libcamera_version variable contains the major.minor.patch (e.g. 1.2.3)\n> > +    # only. If the source tree isn't under git control, or if it matches the last\n> > +    # git version tag, the build metadata (e.g. +211-c94a24f4) is omitted from\n> > +    # libcamera_git_version.\n> > +    libcamera_git_version = run_command('utils/gen-version.sh',\n> > +                                        meson.build_root()).stdout().strip()\n> > +    if libcamera_git_version == ''\n> > +        libcamera_git_version = meson.project_version()\n> > +    endif\n> > +else\n> > +    # Read the version information from the file generated by the utils/run-dist.sh\n> > +    # script on a 'meson dist' command.\n> > +    libcamera_git_version = run_command(['cat', 'version.gen']).stdout().strip()\n> >  endif\n> \n> I've added an if clause here to check for the presence of the version file, but I\n> could equally leave this as-is and check for the file in gen-version.sh. I don't have\n> a strong preference either way.\n\nI think I'd prefer handling this in gen-version.sh, as it will\ncentralize all the version handling code in a single place.\n\n> >  libcamera_version = libcamera_git_version.split('+')[0]\n> >\n> > +# This script gererates the version.gen file on a 'meson dist' command.\n> > +meson.add_dist_script('utils/run-dist.sh')\n> > +\n> >  # Configure the build environment.\n> >  cc = meson.get_compiler('c')\n> >  cxx = meson.get_compiler('cpp')\n> > diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> > index 243dd3c180eb..360eaf80ecf1 100644\n> > --- a/src/libcamera/meson.build\n> > +++ b/src/libcamera/meson.build\n> > @@ -93,12 +93,11 @@ endforeach\n> >\n> >  libcamera_sources += control_sources\n> >\n> > -gen_version = meson.source_root() / 'utils' / 'gen-version.sh'\n> > -\n> > -version_cpp = vcs_tag(command : [gen_version, meson.build_root()],\n> > -                      input : 'version.cpp.in',\n> > -                      output : 'version.cpp',\n> > -                      fallback : meson.project_version())\n> > +version_data = configuration_data()\n> > +version_data.set('VCS_TAG', libcamera_git_version)\n> > +version_cpp = configure_file(input : 'version.cpp.in',\n> > +                             output : 'version.cpp',\n> > +                             configuration : version_data)\n> >\n> >  libcamera_sources += version_cpp\n> >\n> > diff --git a/utils/run-dist.sh b/utils/run-dist.sh\n> > new file mode 100644\n> > index 000000000000..1b2a6348c6bc\n> > --- /dev/null\n> > +++ b/utils/run-dist.sh\n> > @@ -0,0 +1,9 @@\n> > +#!/bin/sh\n> > +\n> > +# SPDX-License-Identifier: GPL-2.0-or-later\n> > +#\n> > +# On a meson dist run, generate the version string and store it in a file.\n> > +# This will late be picked up by the build system and used in place of running\n\ns/late/later/\n\n> > +# the utils/gen-version.sh script again since we may not be running in the\n> > +# upstream git source tree, and so version information would be lost.\n\nA blank line here would be nice.\n\n> > +\"$MESON_DIST_ROOT\"/utils/gen-version.sh > \"$MESON_DIST_ROOT\"/version.gen\n\nDo we need to cd to MESON_SOURCE_ROOT first (or set GIT_DIR), or is\nthere a guarantee that this script will always run from a subdirectory\nof MESON_SOURCE_ROOT ?\n\nTo end with some nitpicking, I wonder if there's a standard name for\nfiles containing a version number (I initially thought about .version\nbut have no evidence that it would be better than version.gen).","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 1E611BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 13 Oct 2021 10:38:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8495568F4F;\n\tWed, 13 Oct 2021 12:38:58 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D5F760501\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Oct 2021 12:38:57 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 98CE018FF;\n\tWed, 13 Oct 2021 12:38:56 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"wpAquRtK\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1634121536;\n\tbh=c5I82qd+mdMISvRN3IwcMltrsBoEytnnE2QmN/6nKNs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=wpAquRtK2AFXedOP7ItV+r7AJTuKkDZnkLTwC6qlv6d7w4SbdVKLi2ruuHwbr5Q94\n\tpavPN5if5vJGd0rolrr/XuBCq4PET3IUNyuLY/WqOG6EaSi8mrBBy45OUjcM3IbvTz\n\tpijWBiQYVqxKsl0TNsD+YAhcuVo1mxGRxxe+mnlw=","Date":"Wed, 13 Oct 2021 13:38:42 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<YWa3MtdGJ9h2s06r@pendragon.ideasonboard.com>","References":"<20211013101650.1810576-1-naush@raspberrypi.com>\n\t<20211013101650.1810576-2-naush@raspberrypi.com>\n\t<CAEmqJPozBmDgpjSEGuGt=L3aJ3L_qAE=Hu6SCaD_ZNcmGfxn4w@mail.gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<CAEmqJPozBmDgpjSEGuGt=L3aJ3L_qAE=Hu6SCaD_ZNcmGfxn4w@mail.gmail.com>","Subject":"Re: [libcamera-devel] [RFC 1/1] build: Preserve upstream git\n\tversioning using meson dist","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":20180,"web_url":"https://patchwork.libcamera.org/comment/20180/","msgid":"<CAEmqJPrFZ1VrGzdtqYoBo-TD0tWMU7KzEsO-VcLBqQAGp_nHNQ@mail.gmail.com>","date":"2021-10-13T10:52:05","subject":"Re: [libcamera-devel] [RFC 1/1] build: Preserve upstream git\n\tversioning using meson dist","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Laurent,\n\nThank you for your feedback.\n\nOn Wed, 13 Oct 2021 at 11:38, Laurent Pinchart <\nlaurent.pinchart@ideasonboard.com> wrote:\n\n> Hi Naush,\n>\n> Thank you for the patch.\n>\n> On Wed, Oct 13, 2021 at 11:20:53AM +0100, Naushir Patuck wrote:\n> > On Wed, 13 Oct 2021 at 11:19, Naushir Patuck wrote:\n> > > When distributions build and package libcamera libraries, they may not\n> > > necessarily run the build in the upstream source tree. In these cases,\n> the git\n> > > SHA1 versioning information will be lost.\n> > >\n> > > This change addresses that problem by requiring package managers to run\n> > > 'meson dist' to create a tarball of the source files and build from\n> there.\n> > > On runing 'meson dist', the utils/run-dist.sh script will create a\n> version.gen\n> > > file in the release tarball with the version string generated from the\n> existing\n> > > utils/gen-version.sh script.\n> > >\n> > > The build system has been updated to check for the presence of this\n> version.gen\n> > > file and read the version string from it. If the file is not present,\n> the\n> > > version string is generated by running utils/gen-version.sh as it\n> currently\n> > > does.\n> > >\n> > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> > > ---\n> > >  meson.build               | 30 ++++++++++++++++++++----------\n> > >  src/libcamera/meson.build | 11 +++++------\n> > >  utils/run-dist.sh         |  9 +++++++++\n> > >  3 files changed, 34 insertions(+), 16 deletions(-)\n> > >  create mode 100644 utils/run-dist.sh\n> > >\n> > > diff --git a/meson.build b/meson.build\n> > > index a49c484fe64e..f27bfd479a5c 100644\n> > > --- a/meson.build\n> > > +++ b/meson.build\n> > > @@ -10,20 +10,30 @@ project('libcamera', 'c', 'cpp',\n> > >      ],\n> > >      license : 'LGPL 2.1+')\n> > >\n> > > -# Generate version information. The libcamera_git_version variable\n> contains the\n> > > -# full version with git patch count and SHA1 (e.g.\n> 1.2.3+211-c94a24f4), while\n> > > -# the libcamera_version variable contains the major.minor.patch (e.g.\n> 1.2.3)\n> > > -# only. If the source tree isn't under git control, or if it matches\n> the last\n> > > -# git version tag, the build metadata (e.g. +211-c94a24f4) is omitted\n> from\n> > > -# libcamera_git_version.\n> > > -libcamera_git_version = run_command('utils/gen-version.sh',\n> > > -\n> meson.build_root()).stdout().strip()\n> > > -if libcamera_git_version == ''\n> > > -    libcamera_git_version = meson.project_version()\n> > > +fs_mod = import('fs')\n> > > +if not fs_mod.is_file('version.gen')\n> > > +    # Generate version information. The libcamera_git_version\n> variable contains the\n> > > +    # the full version with git patch count and SHA1 (e.g.\n> 1.2.3+211-c94a24f4), while\n> > > +    # the libcamera_version variable contains the major.minor.patch\n> (e.g. 1.2.3)\n> > > +    # only. If the source tree isn't under git control, or if it\n> matches the last\n> > > +    # git version tag, the build metadata (e.g. +211-c94a24f4) is\n> omitted from\n> > > +    # libcamera_git_version.\n> > > +    libcamera_git_version = run_command('utils/gen-version.sh',\n> > > +\n> meson.build_root()).stdout().strip()\n> > > +    if libcamera_git_version == ''\n> > > +        libcamera_git_version = meson.project_version()\n> > > +    endif\n> > > +else\n> > > +    # Read the version information from the file generated by the\n> utils/run-dist.sh\n> > > +    # script on a 'meson dist' command.\n> > > +    libcamera_git_version = run_command(['cat',\n> 'version.gen']).stdout().strip()\n> > >  endif\n> >\n> > I've added an if clause here to check for the presence of the version\n> file, but I\n> > could equally leave this as-is and check for the file in gen-version.sh.\n> I don't have\n> > a strong preference either way.\n>\n> I think I'd prefer handling this in gen-version.sh, as it will\n> centralize all the version handling code in a single place.\n>\n\nOk, will do.\n\n\n>\n> > >  libcamera_version = libcamera_git_version.split('+')[0]\n> > >\n> > > +# This script gererates the version.gen file on a 'meson dist'\n> command.\n> > > +meson.add_dist_script('utils/run-dist.sh')\n> > > +\n> > >  # Configure the build environment.\n> > >  cc = meson.get_compiler('c')\n> > >  cxx = meson.get_compiler('cpp')\n> > > diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> > > index 243dd3c180eb..360eaf80ecf1 100644\n> > > --- a/src/libcamera/meson.build\n> > > +++ b/src/libcamera/meson.build\n> > > @@ -93,12 +93,11 @@ endforeach\n> > >\n> > >  libcamera_sources += control_sources\n> > >\n> > > -gen_version = meson.source_root() / 'utils' / 'gen-version.sh'\n> > > -\n> > > -version_cpp = vcs_tag(command : [gen_version, meson.build_root()],\n> > > -                      input : 'version.cpp.in',\n> > > -                      output : 'version.cpp',\n> > > -                      fallback : meson.project_version())\n> > > +version_data = configuration_data()\n> > > +version_data.set('VCS_TAG', libcamera_git_version)\n> > > +version_cpp = configure_file(input : 'version.cpp.in',\n> > > +                             output : 'version.cpp',\n> > > +                             configuration : version_data)\n> > >\n> > >  libcamera_sources += version_cpp\n> > >\n> > > diff --git a/utils/run-dist.sh b/utils/run-dist.sh\n> > > new file mode 100644\n> > > index 000000000000..1b2a6348c6bc\n> > > --- /dev/null\n> > > +++ b/utils/run-dist.sh\n> > > @@ -0,0 +1,9 @@\n> > > +#!/bin/sh\n> > > +\n> > > +# SPDX-License-Identifier: GPL-2.0-or-later\n> > > +#\n> > > +# On a meson dist run, generate the version string and store it in a\n> file.\n> > > +# This will late be picked up by the build system and used in place\n> of running\n>\n> s/late/later/\n>\n> > > +# the utils/gen-version.sh script again since we may not be running\n> in the\n> > > +# upstream git source tree, and so version information would be lost.\n>\n> A blank line here would be nice.\n>\n> > > +\"$MESON_DIST_ROOT\"/utils/gen-version.sh >\n> \"$MESON_DIST_ROOT\"/version.gen\n>\n> Do we need to cd to MESON_SOURCE_ROOT first (or set GIT_DIR), or is\n> there a guarantee that this script will always run from a subdirectory\n> of MESON_SOURCE_ROOT ?\n>\n\nFrom what I can tell, meson dist does not seem to allow the user to specify\nthe dist output directory,\nit creates a 'meson-dist' direcotry under MESON_BUILD_ROOT. I had assumed\nthe latter will\nwill always be a subdirectly of MESON_SOURCE_ROOT, but perhaps that will\nnot always be the\ncase, so I could cd MESON_SOURCE_ROOT to be sure!\n\n\n>\n> To end with some nitpicking, I wonder if there's a standard name for\n> files containing a version number (I initially thought about .version\n> but have no evidence that it would be better than version.gen).\n>\n\nI don't know of any specific standard filename for this.  I chose the .gen\nextension to loosely signify\nthat this was an auto generated file.  I can change to .version if you\nprefer?\n\nRegards,\nNaush\n\n\n>\n> --\n> Regards,\n>\n> Laurent Pinchart\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 72218C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 13 Oct 2021 10:52:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E096668F4B;\n\tWed, 13 Oct 2021 12:52:24 +0200 (CEST)","from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com\n\t[IPv6:2a00:1450:4864:20::12f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CE47E60501\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Oct 2021 12:52:22 +0200 (CEST)","by mail-lf1-x12f.google.com with SMTP id r19so9845299lfe.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Oct 2021 03:52:22 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"tt5mg0cL\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=bFj+FIf1CiiaTOtZOCWg/jU0ez+M05AVid4lCFd9Oxg=;\n\tb=tt5mg0cL4GXcsaptyuw5Nph7jI8Itg7ORYx5PnMLXgROTjcXLdTrHErVlUr5zdMgcy\n\tY+zNxua2+bvNKJJzIf4JCs98sOAyV0bXq3ccOpOfxU/6/u92uF/HTdFdDAT5SIORkIPm\n\tImIfGzhuGozG1e4M8bXex5jlEmyAbA7EdRWM8m+3RjBYdr3KtGftxvvW05Bz767RAVIO\n\tXsRMU4+H7aDrkFXZPInWRJ0LarJWBg0uEVPl/9AiCsCOQA8D3yVVGr37oehmWi1+W/an\n\t6oqXkDyp/eMCBgO0609fB0SGuzWgcUZSfrsytNBewyZ6BpcVC18PrUMc+JijJpKViWi/\n\tLZNQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=bFj+FIf1CiiaTOtZOCWg/jU0ez+M05AVid4lCFd9Oxg=;\n\tb=PTCiHUwGZBuo6l0Gbwx+DmoXK0PwIZ2m5gaPH6xuKDdFzKwVlaTifhQe+yO+Ophe1N\n\tnqiYaUWZkBCWiNE7wE5j/fSiHEBRPwSksUmx9LcPynkKDNZhEAttOUPvJ8g0WIglipU0\n\tgvkoYXnRXSuSkzDawI3vCxBS/yioKAlbq5b+jdaHFoq4nWUEVXdTnmy9H1+FCa2cRs4c\n\tNDtLJZ9is9ZGMvHo/tGAofQu8E8gO3O5aESz9n1DCRbiTDfu0Q5euykZbBjqruWmlOm4\n\tCdp8kFyoGV97+ceHGc39tAg+MZdDrtggg8FX41+pcG2DdR5S7HfcBVfFUwS1vhZShGgd\n\tBgZQ==","X-Gm-Message-State":"AOAM531OYWDGrl4bc35IYQ8D82sBbdba24au5pcwZxeM/UN3lGzqmfFF\n\tS4R/4xaVfAd1cnNyVVwTSS8zzJByZF7v28j/XNb/PBvvJ7J6TA==","X-Google-Smtp-Source":"ABdhPJw1GI6A5bJIwjVeK3i8CwJx5o52o4GZ6C6j+l5EaJJWnP/SeogbZalrZWbsOKpSy+2VES2v43va4j336UZyxKg=","X-Received":"by 2002:a05:6512:2241:: with SMTP id\n\ti1mr37766113lfu.611.1634122341464; \n\tWed, 13 Oct 2021 03:52:21 -0700 (PDT)","MIME-Version":"1.0","References":"<20211013101650.1810576-1-naush@raspberrypi.com>\n\t<20211013101650.1810576-2-naush@raspberrypi.com>\n\t<CAEmqJPozBmDgpjSEGuGt=L3aJ3L_qAE=Hu6SCaD_ZNcmGfxn4w@mail.gmail.com>\n\t<YWa3MtdGJ9h2s06r@pendragon.ideasonboard.com>","In-Reply-To":"<YWa3MtdGJ9h2s06r@pendragon.ideasonboard.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Wed, 13 Oct 2021 11:52:05 +0100","Message-ID":"<CAEmqJPrFZ1VrGzdtqYoBo-TD0tWMU7KzEsO-VcLBqQAGp_nHNQ@mail.gmail.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Content-Type":"multipart/alternative; boundary=\"000000000000aed3d405ce39c1b2\"","Subject":"Re: [libcamera-devel] [RFC 1/1] build: Preserve upstream git\n\tversioning using meson dist","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]