From patchwork Wed Oct 13 10:16:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14495 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9F133BDB1C for ; Tue, 9 Nov 2021 17:41:54 +0000 (UTC) Received: from pendragon.ideasonboard.com (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3C5BE501 for ; Tue, 9 Nov 2021 18:41:54 +0100 (CET) Authentication-Results: perceval.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="t0+3wBU+"; dkim-atps=neutral Delivered-To: kbingham@ideasonboard.com Received: from perceval.ideasonboard.com by perceval.ideasonboard.com with LMTP id eKqwDpyyZmH6NAAA4E0KoQ (envelope-from ) for ; Wed, 13 Oct 2021 12:19:08 +0200 Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by perceval.ideasonboard.com (Postfix) with ESMTPS id 0A44318FF; Wed, 13 Oct 2021 12:19:08 +0200 (CEST) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B836268F50; Wed, 13 Oct 2021 12:19:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="t0+3wBU+"; dkim-atps=neutral Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5357360501 for ; Wed, 13 Oct 2021 12:19:06 +0200 (CEST) Received: by mail-wr1-x42d.google.com with SMTP id e12so6583042wra.4 for ; Wed, 13 Oct 2021 03:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y7mEJ+pwpU7N62NwAYoOxAHnlZ330zf8im/kM1eJFR4=; b=t0+3wBU+kIvlxhMMFvtsW3CXTjFvdIVvldETbvStqUpGOsb7YDu4DHJIlEOdUclDvo sco4W+Fee7wivo6V48qBKH+Q9A0XMVMWI7Zq+LsVk8BBRfNrr4yIUarAIX0jhzIF9oK/ m4sA7PtM9b6Q4EhyNHz45tLjZM4c84fccMlRP77otRkHkiFWeTxVKSQzM5Nk5GSJgE27 N22Gb5kPUMLQcDctPhvcZEkFXc/IpqH8B+9/Y2ZKirL8xl3tucB9JGGu07JzLFPp2I32 BJTKUijnAzC3RSJgtHXqS0BqRQxsZNrpXfaPYFnG6kYzSkJUDLZ4q6YA9pdFoiExrKPe 4asQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y7mEJ+pwpU7N62NwAYoOxAHnlZ330zf8im/kM1eJFR4=; b=YoqOOBpGLkpKAPqG8V6e9uArqlu5vzs2oaJoy0C9NSPYXqmDzkw0HWTUbZm9PZ4WC6 U1M1etEULLlq8QoRtR0QdV8/0OWVFh9kEgi8QriEKKh57I5ExsvCP+oQY4TMNcUCSuTh MU9FJda0g4yEhoAdnAKNabCgDoulzL6AfWOB4JeyZ2p0+JyKRZpTGSoRskZTNPhCrGo6 dIzW/cdnPAsCkPa221xQYxHpElYnpW35akIRBjsqKKcpd+kxJlrQ0bhNpVJiilmCFZHD DH/Ghyq4P7zFFaGLPHDBFWIsaOTV0VG8cQ2vR0bl/cmVWto0yYVenbXZfI2xCWcNuJ6S rzMA== X-Gm-Message-State: AOAM5319dOMX9qQ1HeJT5xhQSqMlINtOKN55U6TcmE9nRPYC7Mi6G4dg AucP/GlFz2KJsgAIN1Xow43vRhmf7UQ= X-Google-Smtp-Source: =?utf-8?q?ABdhPJwwAQTp/QT0MTVOlCcRYsGsuHRR0eDaM1Haa?= =?utf-8?q?DAHEt6OBfcpKn3CJK0b5a9QWw/YAwqiAsqAJg=3D=3D?= X-Received: by 2002:adf:a45c:: with SMTP id e28mr39047440wra.347.1634120345821; Wed, 13 Oct 2021 03:19:05 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:a13d:95a9:c25e:7597]) by smtp.gmail.com with ESMTPSA id y5sm7904902wrq.85.2021.10.13.03.19.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 03:19:05 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 11:16:50 +0100 Message-Id: <20211013101650.1810576-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211013101650.1810576-1-naush@raspberrypi.com> References: <20211013101650.1810576-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 1/1] build: Preserve upstream git versioning using meson dist 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" X-TUID: pDLR32bicpsi Resent-From: Kieran Bingham Resent-To: parsemail@patchwork.libcamera.org When distributions build and package libcamera libraries, they may not necessarily run the build in the upstream source tree. In these cases, the git SHA1 versioning information will be lost. This change addresses that problem by requiring package managers to run 'meson dist' to create a tarball of the source files and build from there. On runing 'meson dist', the utils/run-dist.sh script will create a version.gen file in the release tarball with the version string generated from the existing utils/gen-version.sh script. The build system has been updated to check for the presence of this version.gen file and read the version string from it. If the file is not present, the version string is generated by running utils/gen-version.sh as it currently does. Signed-off-by: Naushir Patuck --- meson.build | 30 ++++++++++++++++++++---------- src/libcamera/meson.build | 11 +++++------ utils/run-dist.sh | 9 +++++++++ 3 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 utils/run-dist.sh diff --git a/meson.build b/meson.build index a49c484fe64e..f27bfd479a5c 100644 --- a/meson.build +++ b/meson.build @@ -10,20 +10,30 @@ 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. -libcamera_git_version = run_command('utils/gen-version.sh', - meson.build_root()).stdout().strip() -if libcamera_git_version == '' - libcamera_git_version = meson.project_version() +fs_mod = import('fs') +if not fs_mod.is_file('version.gen') + # Generate version information. The libcamera_git_version variable contains the + # 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. + libcamera_git_version = run_command('utils/gen-version.sh', + meson.build_root()).stdout().strip() + if libcamera_git_version == '' + libcamera_git_version = meson.project_version() + endif +else + # Read the version information from the file generated by the utils/run-dist.sh + # script on a 'meson dist' command. + libcamera_git_version = run_command(['cat', 'version.gen']).stdout().strip() endif libcamera_version = libcamera_git_version.split('+')[0] +# This script gererates the version.gen file on a 'meson dist' command. +meson.add_dist_script('utils/run-dist.sh') + # Configure the build environment. cc = meson.get_compiler('c') cxx = meson.get_compiler('cpp') diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 243dd3c180eb..360eaf80ecf1 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -93,12 +93,11 @@ endforeach libcamera_sources += control_sources -gen_version = meson.source_root() / 'utils' / 'gen-version.sh' - -version_cpp = vcs_tag(command : [gen_version, meson.build_root()], - input : 'version.cpp.in', - output : 'version.cpp', - fallback : meson.project_version()) +version_data = configuration_data() +version_data.set('VCS_TAG', libcamera_git_version) +version_cpp = configure_file(input : 'version.cpp.in', + output : 'version.cpp', + configuration : version_data) libcamera_sources += version_cpp diff --git a/utils/run-dist.sh b/utils/run-dist.sh new file mode 100644 index 000000000000..1b2a6348c6bc --- /dev/null +++ b/utils/run-dist.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# SPDX-License-Identifier: GPL-2.0-or-later +# +# On a meson dist run, generate the version string and store it in a file. +# This will late be picked up by the build system and used in place of running +# the utils/gen-version.sh script again since we may not be running in the +# upstream git source tree, and so version information would be lost. +"$MESON_DIST_ROOT"/utils/gen-version.sh > "$MESON_DIST_ROOT"/version.gen