[{"id":26801,"web_url":"https://patchwork.libcamera.org/comment/26801/","msgid":"<6311594d-0c2d-c69d-ce67-de434c0b16b0@ideasonboard.com>","date":"2023-03-31T05:07:12","subject":"Re: [libcamera-devel] [PATCH] meson: Really fix git version parsing","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Laurent,\n\nThank you for the patch\n\nOn 3/22/23 11:33 PM, Laurent Pinchart via libcamera-devel wrote:\n> The previous attempt to fix git version parsing in commit d34cefad1791\n> (\"meson: Fix git version parsing\") was too naive, and didn't take into\n> account cases where the libcamera git version contains no or multiple\n> '+' signs.\n>\n> Fixing this is more complex than a one-liner change, as meson doesn't\n> support Python-style slicing of arrays or a length method on strings.\n> The simplest and most versatile option is to patch the version string in\n> the gen-version.sh script. Do so, and clarify the comments related to\n> version handling in meson.build.\n>\n> Fixes: d34cefad1791 (\"meson: Fix git version parsing\")\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nLooks good to me.\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\n> ---\n>   meson.build          | 29 ++++++++++++++++++-----------\n>   utils/gen-version.sh |  8 ++++++++\n>   2 files changed, 26 insertions(+), 11 deletions(-)\n>\n> diff --git a/meson.build b/meson.build\n> index 189e97736d90..8628e6acebee 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -11,15 +11,19 @@ project('libcamera', 'c', 'cpp',\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> +# full version with build metadata (patch count and SHA1, e.g.\n> +# 1.2.3+211-c94a24f4), while the libcamera_version variable contains the\n> +# major.minor.patch (e.g. 1.2.3) only.\n> +#\n> +# If the source tree matches the last git version tag, the build metadata\n> +# (e.g. +211-c94a24f4) is omitted from libcamera_git_version.\n>   libcamera_git_version = run_command('utils/gen-version.sh',\n>                                       meson.project_build_root(),\n>                                       meson.project_source_root(),\n>                                       check: false).stdout().strip()\n> +\n> +# If the source tree isn't under git control, set libcamera_git_version to the\n> +# meson project version.\n>   if libcamera_git_version == ''\n>       libcamera_git_version = meson.project_version()\n>   endif\n> @@ -31,7 +35,7 @@ project_version = meson.project_version().split('+')[0]\n>   # meson.project_version() could leave the project in a mis-described state.\n>   # Produce a warning in this event, and fix to a best effort.\n>   if libcamera_version != project_version\n> -    warning('The sources disagree about the version: '\n> +    warning('The sources and meson.build disagree about the version: '\n>               + libcamera_version + ' != ' + project_version)\n>   \n>       summary({'libcamera git version' : libcamera_git_version,\n> @@ -39,13 +43,16 @@ if libcamera_version != project_version\n>               },\n>               bool_yn : true, section : 'Versions')\n>   \n> -    # Replace the version components reported by git with the release version,\n> -    # but keep all trailing information supplied by git.\n> -    libcamera_git_version = (project_version + '+' +\n> -                             libcamera_git_version.split('+')[1])\n> +    # Re-run gen-version.sh to replace the git version (major.minor.patch) with\n> +    # the meson project version. The build metadata provided by git are kept.\n> +    libcamera_git_version = run_command('utils/gen-version.sh',\n> +                                        meson.project_build_root(),\n> +                                        meson.project_source_root(),\n> +                                        project_version,\n> +                                        check: false).stdout().strip()\n>       libcamera_version = project_version\n>   \n> -    # Append a marker to show we have modified this version string\n> +    # Append a marker to show we have modified this version string.\n>       libcamera_git_version += '-nvm'\n>   endif\n>   \n> diff --git a/utils/gen-version.sh b/utils/gen-version.sh\n> index eb7c72685c54..e1f7ca7b6f01 100755\n> --- a/utils/gen-version.sh\n> +++ b/utils/gen-version.sh\n> @@ -5,6 +5,7 @@\n>   \n>   build_dir=\"$1\"\n>   src_dir=\"$2\"\n> +project_version=\"$3\"\n>   \n>   # If .tarball-version exists, output the version string from the file and exit.\n>   # This file is auto-generated on a 'meson dist' command from the run-dist.sh\n> @@ -43,6 +44,13 @@ then\n>   fi\n>   git diff-index --quiet HEAD || version=\"$version-dirty ($(date --iso-8601=seconds))\"\n>   \n> +# If a project version is provided, use it to replace the version number.\n> +if [ -n \"$project_version\" ]\n> +then\n> +\tversion=$(echo \"$version\" | sed -e 's/^[^-]*-//')\n> +\tversion=\"v$project_version-$version\"\n> +fi\n> +\n>   # Replace first '-' with a '+' to denote build metadata, strip the 'g' in from\n>   # of the git SHA1 and remove the initial 'v'.\n>   version=$(echo \"$version\" | sed -e 's/-/+/' | sed -e 's/-g/-/' | cut -c 2-)\n>\n> base-commit: e39f046f660a6d0954d81b92bd183e7ba679fa56","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 09288C0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 31 Mar 2023 05:07:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4C64D626E2;\n\tFri, 31 Mar 2023 07:07:19 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D2ABF61EC5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 31 Mar 2023 07:07:17 +0200 (CEST)","from [IPV6:2401:4900:1c80:b056:9d4b:adae:fbbd:6f63] (unknown\n\t[IPv6:2401:4900:1c80:b056:9d4b:adae:fbbd:6f63])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E7B0FA39;\n\tFri, 31 Mar 2023 07:07:16 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1680239239;\n\tbh=czFWNu8G/bcRV/L3vFai7IYBC/35VvYYPxbIH7A6iKA=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=FXCZlMpCIrNX6TtRfh/Hio1kizqEHB7r+5L9IwPsW215fUhwQXJrp4JXHE16p/aXG\n\t7c90HaS5JjLc5DwUYJW8IBPJKlEOXZnMTrU7HNJyLSgcIfhNl5yXBmBDWyQ9c4xJGf\n\tICvAPLjXPmS+P2+5nfGpt0fogoYChMnMckVj9IWs5GTK/LBsuDKUlDBh6c+n9CT+1H\n\tRIAzJv6QX/1CQyLs8CJBJdAaARl1MwYqxmOGBFh09yZf/0aihRUilATNoyKyHBA/5f\n\ttIFFhpp51iPXCyDCykZgvLYw7rwK8Usymtul8fis/z1Vf17RXpaigXLhKQB4aNTYvX\n\tHoVFtz6bXSb7Q==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1680239237;\n\tbh=czFWNu8G/bcRV/L3vFai7IYBC/35VvYYPxbIH7A6iKA=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=fvsS98cgioJLjnnNkwLo2gRliAEHIc9WPy7AqKLEpTtsRBE1bNf2SxK+iodGxtzix\n\tfZ8w9CGZq/UngfnH6gsI0W9ypAiL+xH/KQXylYCdVvtN3zQcrtdyuTc/9mwLG1eXWB\n\t6nQQA8dM/CNwyhsNAEFtMviqjDU0TdqZsue83qag="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"fvsS98cg\"; dkim-atps=neutral","Message-ID":"<6311594d-0c2d-c69d-ce67-de434c0b16b0@ideasonboard.com>","Date":"Fri, 31 Mar 2023 10:37:12 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101\n\tThunderbird/102.7.1","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20230322180347.1766-1-laurent.pinchart@ideasonboard.com>","Content-Language":"en-US","In-Reply-To":"<20230322180347.1766-1-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH] meson: Really fix git version parsing","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>","From":"Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Umang Jain <umang.jain@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]