From patchwork Wed Mar 22 18:03:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 18442 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 92D54C0F1B for ; Wed, 22 Mar 2023 18:03:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B780C626E5; Wed, 22 Mar 2023 19:03:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1679508223; bh=UFKonO9KHnRf9rsDLgRyQkgSEGP0t9AVYawUMxa65rA=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=T5uJj1dLSwnUu0fsDxW+NY2oeJUOcw5lCPibAnUAoqPxu7JZ7mFtjMjdJfqhF22GV T0HAqUBRM/n0D877AVDWs4DJNVcVvP5IuNHqN7XZXDqCPoGmVZ7o6R6QPPEyDwb3iz qqcxqN/aulqkk2FsyJwK/RF/HHhSoYTgkyjCaSF2F4EyVmGw/U+eW8RzqLSBKqojeg mAF9bVs0gjmR3+3M/XBjqjxesKr/6psVr8ZH4RiA5yUpPNAKuSAuTCD1FioPC6PI7k 940n72mcua9Fa12gFAp6IMoIC/0biGQp7rUwK9PkZwcLS6BGk0qyBK+ZI3tQGPclHp jnHIS7CifldSA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1393461ECE for ; Wed, 22 Mar 2023 19:03:42 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="EEy+Or17"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6D477183F for ; Wed, 22 Mar 2023 19:03:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1679508221; bh=UFKonO9KHnRf9rsDLgRyQkgSEGP0t9AVYawUMxa65rA=; h=From:To:Subject:Date:From; b=EEy+Or17sdMiqkfRjf8twdx7VjrXqdWawRk8pWdvgfaJK/udeSiRvqUAWOlhzPYY2 d0Ofg6uoW8BWmVE62hJCAGLnaN7iyXZwdCeEETz7FKUhtp5r7+vJu6pLzeC/pQuPQg yf+0zEFXkwVu8sXNUI4CRmDqsRyjcfwCfKRqvKdA= To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Mar 2023 20:03:47 +0200 Message-Id: <20230322180347.1766-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The previous attempt to fix git version parsing in commit d34cefad1791 ("meson: Fix git version parsing") was too naive, and didn't take into account cases where the libcamera git version contains no or multiple '+' signs. Fixing this is more complex than a one-liner change, as meson doesn't support Python-style slicing of arrays or a length method on strings. The simplest and most versatile option is to patch the version string in the gen-version.sh script. Do so, and clarify the comments related to version handling in meson.build. Fixes: d34cefad1791 ("meson: Fix git version parsing") Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain --- meson.build | 29 ++++++++++++++++++----------- utils/gen-version.sh | 8 ++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) base-commit: e39f046f660a6d0954d81b92bd183e7ba679fa56 diff --git a/meson.build b/meson.build index 189e97736d90..8628e6acebee 100644 --- a/meson.build +++ b/meson.build @@ -11,15 +11,19 @@ project('libcamera', 'c', 'cpp', license : 'LGPL 2.1+') # Generate version information. The libcamera_git_version variable contains the -# full version with git patch count and SHA1 (e.g. 1.2.3+211-c94a24f4), while -# the libcamera_version variable contains the major.minor.patch (e.g. 1.2.3) -# only. If the source tree isn't under git control, or if it matches the last -# git version tag, the build metadata (e.g. +211-c94a24f4) is omitted from -# libcamera_git_version. +# full version with build metadata (patch count and SHA1, e.g. +# 1.2.3+211-c94a24f4), while the libcamera_version variable contains the +# major.minor.patch (e.g. 1.2.3) only. +# +# If the source tree matches the last git version tag, the build metadata +# (e.g. +211-c94a24f4) is omitted from libcamera_git_version. libcamera_git_version = run_command('utils/gen-version.sh', meson.project_build_root(), meson.project_source_root(), check: false).stdout().strip() + +# If the source tree isn't under git control, set libcamera_git_version to the +# meson project version. if libcamera_git_version == '' libcamera_git_version = meson.project_version() endif @@ -31,7 +35,7 @@ project_version = meson.project_version().split('+')[0] # meson.project_version() could leave the project in a mis-described state. # Produce a warning in this event, and fix to a best effort. if libcamera_version != project_version - warning('The sources disagree about the version: ' + warning('The sources and meson.build disagree about the version: ' + libcamera_version + ' != ' + project_version) summary({'libcamera git version' : libcamera_git_version, @@ -39,13 +43,16 @@ if libcamera_version != project_version }, bool_yn : true, section : 'Versions') - # Replace the version components reported by git with the release version, - # but keep all trailing information supplied by git. - libcamera_git_version = (project_version + '+' + - libcamera_git_version.split('+')[1]) + # Re-run gen-version.sh to replace the git version (major.minor.patch) with + # the meson project version. The build metadata provided by git are kept. + libcamera_git_version = run_command('utils/gen-version.sh', + meson.project_build_root(), + meson.project_source_root(), + project_version, + check: false).stdout().strip() libcamera_version = project_version - # Append a marker to show we have modified this version string + # Append a marker to show we have modified this version string. libcamera_git_version += '-nvm' endif diff --git a/utils/gen-version.sh b/utils/gen-version.sh index eb7c72685c54..e1f7ca7b6f01 100755 --- a/utils/gen-version.sh +++ b/utils/gen-version.sh @@ -5,6 +5,7 @@ build_dir="$1" src_dir="$2" +project_version="$3" # If .tarball-version exists, output the version string from the file and exit. # This file is auto-generated on a 'meson dist' command from the run-dist.sh @@ -43,6 +44,13 @@ then fi git diff-index --quiet HEAD || version="$version-dirty ($(date --iso-8601=seconds))" +# If a project version is provided, use it to replace the version number. +if [ -n "$project_version" ] +then + version=$(echo "$version" | sed -e 's/^[^-]*-//') + version="v$project_version-$version" +fi + # Replace first '-' with a '+' to denote build metadata, strip the 'g' in from # of the git SHA1 and remove the initial 'v'. version=$(echo "$version" | sed -e 's/-/+/' | sed -e 's/-g/-/' | cut -c 2-)