From patchwork Wed Sep 9 23:01:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 7149711 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C35DCBEEC1 for ; Wed, 9 Sep 2015 23:07:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BA80E20863 for ; Wed, 9 Sep 2015 23:07:40 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A197C20813 for ; Wed, 9 Sep 2015 23:07:39 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 95D18182EA2; Wed, 9 Sep 2015 16:07:39 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by ml01.01.org (Postfix) with ESMTP id A6CC0182E9A for ; Wed, 9 Sep 2015 16:07:38 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP; 09 Sep 2015 16:07:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,500,1437462000"; d="scan'208";a="558635994" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.137]) by FMSMGA003.fm.intel.com with ESMTP; 09 Sep 2015 16:07:13 -0700 Subject: [PATCH v2 2/4] ndctl: version from git and annotated tags From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 09 Sep 2015 19:01:31 -0400 Message-ID: <20150909230131.4976.3541.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <20150909224404.4976.10592.stgit@dwillia2-desk3.amr.corp.intel.com> References: <20150909224404.4976.10592.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-8-g92dd MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Arrange for "VERSION" in config.h to append the HEAD git commit when the build is not being done on a released tag. This also appends ".dirty" when the build was done while local changes were pending in the tree. When a released tag is present the VERSION string collapses to just the base version number. Signed-off-by: Dan Williams --- Makefile.am | 6 ++++++ autogen.sh | 1 + configure.ac | 3 ++- contrib/genspec.c | 4 +++- contrib/ndctl.spec.in | 8 +++----- git-version-gen | 47 +++++++++++++++++++++++++++++++++++++++++++++++ ndctl.c | 4 +--- 7 files changed, 63 insertions(+), 10 deletions(-) create mode 100755 git-version-gen diff --git a/Makefile.am b/Makefile.am index d3b0c5274d94..f2ebeea58720 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,6 +23,12 @@ AM_LDFLAGS = \ -Wl,--gc-sections \ -Wl,--as-needed +BUILT_SOURCES = $(top_srcdir)/version.m4 +$(top_srcdir)/version.m4: FORCE + $(AM_V_GEN)$(top_srcdir)/git-version-gen + +FORCE: + SED_PROCESS = \ $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(SED) \ -e 's,@VERSION\@,$(VERSION),g' \ diff --git a/autogen.sh b/autogen.sh index 0d60b0a96e9a..2970a3b9bff7 100755 --- a/autogen.sh +++ b/autogen.sh @@ -6,6 +6,7 @@ if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then echo "Activated pre-commit hook." fi +$(dirname $0)/git-version-gen autoreconf --install --symlink libdir() { diff --git a/configure.ac b/configure.ac index 4b83e7444770..deaa94b0338b 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,7 @@ AC_PREREQ(2.60) +m4_include([version.m4]) AC_INIT([ndctl], - [41], + GIT_VERSION, [linux-nvdimm@lists.01.org], [ndctl], [https://github.com/pmem/ndctl]) diff --git a/contrib/genspec.c b/contrib/genspec.c index 14f27c4b2224..b3e85da3c9ff 100644 --- a/contrib/genspec.c +++ b/contrib/genspec.c @@ -34,7 +34,7 @@ int main(int argc, char **argv) while (fgets(buf, sizeof(buf), stdin)) { if (strncmp("Version:", buf, 8) == 0) - fprintf(stdout, "Version: %s\n", VERSION); + fprintf(stdout, "Version: %s\n", &VERSION[1]); else if (strncmp("%global gitcommit", buf, 17) == 0) fprintf(stdout, "%%global gitcommit %s\n", commit); else if (strncmp("%define lname", buf, 12) == 0) @@ -43,6 +43,8 @@ int main(int argc, char **argv) fprintf(stdout, "%%define dname %s\n", dname[os]); else if (strncmp("%license", buf, 8) == 0 && !license[os]) /* skip */; + else if (strncmp("echo \"\" > version", buf, 17) == 0) + fprintf(stdout, "echo \"%s\" > version\n", VERSION); else fprintf(stdout, "%s", buf); } diff --git a/contrib/ndctl.spec.in b/contrib/ndctl.spec.in index 9e64a44e97c6..61fa525d1e87 100644 --- a/contrib/ndctl.spec.in +++ b/contrib/ndctl.spec.in @@ -4,7 +4,7 @@ Name: ndctl Version: -Release: 1%{?gitcommit:.git%{gitcommit}}%{?dist} +Release: 1%{?dist} Summary: Manage "libnvdimm" subsystem devices (Non-volatile Memory) License: GPL-2.0 URL: https://github.com/pmem/ndctl @@ -52,11 +52,9 @@ Libraries for %{name} %prep %setup -q %{?gitcommit:-n %{name}-git%{gitcommit}} - %build -%if %{defined gitcommit} - ./autogen.sh -%endif +echo "" > version +./autogen.sh %configure --disable-static make %{?_smp_mflags} diff --git a/git-version-gen b/git-version-gen new file mode 100755 index 000000000000..782a5f214c04 --- /dev/null +++ b/git-version-gen @@ -0,0 +1,47 @@ +#!/bin/sh + +dirty() { + git update-index -q --refresh + if test -z "$(git diff-index --name-only HEAD --)"; then + echo "$1" + else + echo "${1}.dirty" + fi +} + +GVF=version.m4 +DEF_VER=v41 + +LF=' +' + +# First see if there is a version file (included in release tarballs), +# then try git-describe, then default. +if test -f version; then + VN=$(cat version) || VN="$DEF_VER" +elif test -d ${GIT_DIR:-.git} -o -f .git && + VN=$(git describe --match "v[0-9]*" --abbrev=7 HEAD 2>/dev/null) && + case "$VN" in + *$LF*) (exit 1) ;; + v[0-9]*) + VN="$(dirty $VN)" + esac; then + VN=$(echo "$VN" | sed -e 's/-/./g'); +else + read COMMIT COMMIT_SUBJECT <&2 "GIT_VERSION = $VN" + echo "m4_define([GIT_VERSION], [$VN])" >$GVF + exit 0 +} diff --git a/ndctl.c b/ndctl.c index 93cc25e1d564..8d806d3adb30 100644 --- a/ndctl.c +++ b/ndctl.c @@ -22,9 +22,7 @@ struct cmd_struct { static int cmd_version(int argc, const char **argv) { - static const char ndctl_version_string[] = "ndctl " VERSION; - - printf("%s\n", ndctl_version_string); + printf("%s\n", VERSION); return 0; }