From patchwork Mon Dec 19 15:56:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lev Stipakov X-Patchwork-Id: 2929 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:c95:b0:82:e4b3:40a0 with SMTP id p21csp3112540dyk; Mon, 19 Dec 2022 07:57:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf46h5RO+sQTU1Xk3HjLVtFn8/SwUa0iMytoqrsr0ljZHYmc2t9q1cbguJo657XoX1gYjE1g X-Received: by 2002:a17:902:ccc8:b0:188:640f:f41e with SMTP id z8-20020a170902ccc800b00188640ff41emr51974701ple.4.1671465455476; Mon, 19 Dec 2022 07:57:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671465455; cv=none; d=google.com; s=arc-20160816; b=gEZQYv7kv5Z3LYQAgcqXvxqlR/E7zZrUD7FTNqkZA5EFDH+6/xxlosVnTnF090QWlY Ztz3CkAs79JB918ar3yQutodG/T4bPyee0EYQIfjbLMmYCWnE096E6Dju+e02A83eQjv 5brqhQGFsHfQF5knIG7cUYU/z2/aZGzCsi7iMmfvRVMkeIByeAScsjLubnHkTFKbEclH e1+AbQCos/UsUe5Dsvtr0vHk5LE+xSfag0H4FlQXNzlmFG0fLT0bxb5+LYvarGc1EMy9 BJU0NO9S+yvSVsXERIJGTQE5PRveQVX2Rc0tlze9K3yG21NXpKknUm8//5fbz0XwMLpW OelQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:content-transfer-encoding:cc:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=rCyqFxhzTUIkOpmE5Q8FdhOTsyAcmQ0O0ewPc4vMDeA=; b=rhXHhJmZE4EKAc14rfilAbvudlkhKNnNhNalO9JxekViqoJhgqdohJzd64PN/fnOFZ RWDsocEBAJc/Kbl2ZclkAnwI/cSyuQ/tEED4Bh48n38Yv6nijICgLveoXwE48mkcoRxT dVReN2qS9jWz3DEl0Qq+AedjztVhq8dlJ9ALvTGxOn+wet03fK04K+MJto97BqEj/Dwx HxmFYp2rNXA/C9ihIK4PHSeqCkxD1FhLYLjCfobEhEUjJ4qYd9pue3nVGqkm0Fq3JBnW +gjloU88jXHh3MB7XC72DtyF09YSl+NWYc8Iz4rJuDQq/hidBQ4IFZVsMokeMIT0uuXp udew== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=ahq04O4t; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="JJIE/Y29"; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=YbpcvHWs; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id b18-20020a170902d51200b0018965226454si11636795plg.501.2022.12.19.07.57.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Dec 2022 07:57:35 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=ahq04O4t; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="JJIE/Y29"; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=YbpcvHWs; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1p7IVv-0004bK-GP; Mon, 19 Dec 2022 15:57:15 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1p7IVl-0004aq-Nt for openvpn-devel@lists.sourceforge.net; Mon, 19 Dec 2022 15:57:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=KD6VXl3wSGLFd/MG0oNUs8t3Ys2bNPYSn0XbfO6nWx0=; b=ahq04O4tg/GIHlUZ/OvjOqJ2Zi 80dL53t+peLss+alUzShCFEA4UKzH2BTxrTdgl4Gl7h+J+grM0y6mMlt9J8cQAwLKzsl/e+EyYxmU RXFsescNTGJC883Wc0FT0IqwLBPRP+my9vqGJKpF3ZtmeSn9I8m7QZNOUSfLMloODEJQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=KD6VXl3wSGLFd/MG0oNUs8t3Ys2bNPYSn0XbfO6nWx0=; b=JJIE/Y29O9aTVaBmLDBNoGnRFr JDPmA5h4SYU6VREqzZ4I9W/74s6+lDC4z0Lig9nikgUzvaaiHUmyMNSVgnToRR9w7hL6BOJQ/5xAW l9uGOvDhMO4KM944sdsDwSRV87jRDdi+F1Bt2cBcyYlT0oerqqWxz0FJWeHzWyHHQdek=; Received: from mail-lf1-f48.google.com ([209.85.167.48]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1p7IVg-004u1L-V4 for openvpn-devel@lists.sourceforge.net; Mon, 19 Dec 2022 15:57:05 +0000 Received: by mail-lf1-f48.google.com with SMTP id y25so14273299lfa.9 for ; Mon, 19 Dec 2022 07:57:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KD6VXl3wSGLFd/MG0oNUs8t3Ys2bNPYSn0XbfO6nWx0=; b=YbpcvHWsdSnuV68IIdleKNIu0GhRasC1IZ7XrykmoLBDsMdeewdTj8dl07GrtsO2On eaDVW956FuKc+jNZpQHAe323VdYOf7U6QcVW8szmhsQ2QZaDPsGHz+9qd3DrBD+ywfuZ 5otaTLZFqZiU7UgolBx8olc1C9e5woCllwkTjO50OYFVeab4KoTROQC1EDSiwbZZ6LZ+ JEFkOKoVR6R5oOcyBev1AZiLglaqEt2f1TxJQ97jcgnxCsMHsAKpk9tVCt+EYOfvN8t3 5KZqOqPspNMpdg09aXZM772845F1yOAOruh/E01KhG6235tnpqtZ5YtskpsZhuJ2j+ua fB4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KD6VXl3wSGLFd/MG0oNUs8t3Ys2bNPYSn0XbfO6nWx0=; b=jnX0dfdPvK1iFdmysus5admR9rHBsRj5zsWRl3IXP5DUWhJMgTjbDZbKMDYY2h9wK+ 4ZRapHn+liulELukML4OUr7rI8NHP+yj11rllzFiFWtyNDkX7oVh1SRxltGHv3COeTM0 S7zbnBjrUVJWKvPtFU0iyrTNTN8mZP3UjH/70TLNEqZhjPyanRYKxIRNfxFfUa+29IBK JszrHn5Lk3hq/0TDVlEf/03DFfgCMM92zxZnpJlNP271yocr8pYVmlMru7yilvTSddz7 pZMke5j/Q4UhN8pADZU4y74wSnN2NqLeSXAnq2CcU1CPi6wx3mBpYhzgPmEHoq9Q7aMA tn+w== X-Gm-Message-State: AFqh2koWWUaPzB3kozlQBRF55dxXHb78icyTDuY2buFxlGc9X+3fOxzQ CbPfE3nn7p2o/rUhM/Deo2FqP92NSe4= X-Received: by 2002:a05:6512:3b94:b0:4bc:bdf5:f161 with SMTP id g20-20020a0565123b9400b004bcbdf5f161mr6244245lfv.49.1671465413878; Mon, 19 Dec 2022 07:56:53 -0800 (PST) Received: from LAPTOP-4L3N7KFS.localdomain (85-76-85-229-nat.elisa-mobile.fi. [85.76.85.229]) by smtp.gmail.com with ESMTPSA id q1-20020ac24a61000000b004b57c5b7ec3sm1128417lfp.235.2022.12.19.07.56.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 07:56:53 -0800 (PST) From: Lev Stipakov To: openvpn-devel@lists.sourceforge.net Date: Mon, 19 Dec 2022 17:56:38 +0200 Message-Id: <20221219155638.497-1-lstipakov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-1.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Lev Stipakov Git magic to get branch name git rev-parse --symbolic-full-name HEAD Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.167.48 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [lstipakov[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.167.48 listed in wl.mailspike.net] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1p7IVg-004u1L-V4 Subject: [Openvpn-devel] [PATCH v3] git-version.py: proper support for tags X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lev Stipakov Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1752655154039026004?= X-GMAIL-MSGID: =?utf-8?q?1752658561571744792?= From: Lev Stipakov Git magic to get branch name git rev-parse --symbolic-full-name HEAD doesn't work when we're on tag, which is the case when we build releases. First, try to get tag name with git describe --exact-match and if this fails, get branch name as before. Use subprocess.Popen() to suppress stdout/stderr output. This fixes https://github.com/OpenVPN/openvpn/issues/199. Signed-off-by: Lev Stipakov Acked-By: Frank Lichtenheld --- v3: - use "none" as branch name when we're not on a branch nor tag v2: - try to get tag name before branch - use "git describe --exact-match" instead of "git describe --tags" - use subprocess.Popen() instead of os.popen() to suppress output build/msvc/msvc-generate/git-version.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/build/msvc/msvc-generate/git-version.py b/build/msvc/msvc-generate/git-version.py index 814dc86a..00458955 100644 --- a/build/msvc/msvc-generate/git-version.py +++ b/build/msvc/msvc-generate/git-version.py @@ -24,15 +24,25 @@ import os import sys +import subprocess + +def run_command(args): + sp = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) + o, _ = sp.communicate() + return o.decode("utf-8")[:-1] def get_branch_commit_id(): - commit_id = os.popen("git rev-parse --short=16 HEAD").read()[:-1] + commit_id = run_command(["git", "rev-parse", "--short=16", "HEAD"]) if not commit_id: raise - l = os.popen("git rev-parse --symbolic-full-name HEAD").read().split("/")[2:] - if not l: - l = ["none\n"] - branch = "/" .join(l)[:-1] + branch = run_command(["git", "describe", "--exact-match"]) + if not branch: + # this returns an array like ["master"] or ["release", "2.6"] + branch = run_command(["git", "rev-parse", "--symbolic-full-name", "HEAD"]).split("/")[2:] + if not branch: + branch = ["none"] + branch = "/" .join(branch) # handle cases like release/2.6 + return branch, commit_id def main():