From b3f0821dc41c4d2067a07b1545f32501fb9bb25a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20=C5=9Alusarz?= <marcin.slusarz@intel.com> Date: Fri, 3 Aug 2018 19:37:09 +0200 Subject: [PATCH] common: fix reported version There are many problems: On Linux we were using git commit id of the parent repository if zip/tar.gz package was uncompressed inside of git repository (and this is the case for Fedora). We can't rely on GIT_VERSION for releases, because its contents depends on state of the branch the tag was created from. This file contains all refs that point to the tagged commit, so immediately after 1.4.1 release it contained both "1.4.1" and "stable-1.4", but after merging the first PR to "stable-1.4" branch it contained only "1.4.1". This means that the checksum of the released version changed! This is why vcpkg build from master fails now (it contains initial checksum). The fix is to remove the automatically filled GIT_VERSION file and add static VERSION file before the release and revert this commit after. Version reported by debug libraries was empty if libraries were built from directories other than / and /src. On Windows reported version for point releases was wrong. --- Makefile | 1 - src/Makefile | 1 - src/common.inc | 10 ++++ utils/SRCVERSION.ps1 | 72 ++++++++++++++++---------- src/version.inc => utils/version.sh | 80 +++++++++++++++++++---------- 5 files changed, 107 insertions(+), 57 deletions(-) rename src/version.inc => utils/version.sh (55%) mode change 100644 => 100755 diff --git a/Makefile b/Makefile index 224a315f6..f0e94d966 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,6 @@ # e.g.: "make install prefix=/usr" include src/common.inc -include src/version.inc RPM_BUILDDIR=rpmbuild DPKG_BUILDDIR=dpkgbuild diff --git a/src/Makefile b/src/Makefile index 4b50dd8b5..b301c01ec 100644 --- a/src/Makefile +++ b/src/Makefile @@ -34,7 +34,6 @@ # TOP := $(dir $(lastword $(MAKEFILE_LIST))).. include $(TOP)/src/common.inc -include $(TOP)/src/version.inc TARGETS = libpmem libvmem libpmemblk libpmemlog libpmemobj libpmempool\ libpmemcto libvmmalloc tools diff --git a/src/common.inc b/src/common.inc index f631745d4..56bf0b468 100644 --- a/src/common.inc +++ b/src/common.inc @@ -54,6 +54,16 @@ COVERAGE = 0 PKG_CONFIG ?= pkg-config HEADERS = $(wildcard *.h) $(wildcard *.hpp) +ifeq ($(SRCVERSION),) +export SRCVERSION := $(shell $(TOP)/utils/version.sh $(TOP)) +else +export SRCVERSION +endif + +ifeq ($(SRCVERSION),) +$(error Cannot evaluate version) +endif + ifeq ($(CLANG_FORMAT),) ifeq ($(shell command -v clang-format-3.8 > /dev/null && echo y || echo n), y) export CLANG_FORMAT ?= clang-format-3.8 diff --git a/utils/SRCVERSION.ps1 b/utils/SRCVERSION.ps1 index e612ce6c6..966c7450d 100644 --- a/utils/SRCVERSION.ps1 +++ b/utils/SRCVERSION.ps1 @@ -28,28 +28,38 @@ # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # -# SRCVERSION.PS1 -- script to create SCRVERSION macro on windows +# SRCVERSION.PS1 -- script to create SCRVERSION macro and generate srcversion.h # # -# Expected Values: -# +--------------------+-----+-----+-----+--------+------+-------+----------+ -# |git describe --long |MAJOR|MINOR|BUILD|REVISION|BUGFIX|PRIVATE|PRERELEASE| -# +--------------------+-----+-----+-----+--------+------+-------+----------+ -# |1.2-0-12345678 | 1| 2| 0| 1000| false| false| false| -# |1.2-32-123345678 | 1| 2| 32| 1000| false| true| false| -# |1.2-XXX-0-12345678 | 1| 2| 0| 0| false| false| true| -# |1.2-rc2-0-12345678 | 1| 2| 0| 2| false| false| true| -# |1.2-rc3-32-12345678 | 1| 2| 32| 3| false| true| true| -# |1.2+b3-0-12345678 | 1| 2| 0| 1003| true| false| false| -# |1.2+b2-327-12345678 | 1| 2| 327| 1002| true| true| false| -# +--------------------+-----+-----+-----+--------+------+-------+----------+ +# Windows dll versioning supports only fixed number of fields. The most +# important are MAJOR, MINOR and REVISION. We have 3-compoment releases +# (e.g. 1.4.1) with release candidates, so we have to encode this information +# into this fixed number of fields. That's why we abuse REVISION to encode both +# 3rd component and rc status. +# REVISION = 3RDCOMP * 10000 + (!is_rc) * 1000 + rc. +# +# Examples: +# +---------------------+-----+-----+--------+-----+------+-------+----------+ +# |git describe --long |MAJOR|MINOR|REVISION|BUILD|BUGFIX|PRIVATE|PRERELEASE| +# +---------------------+-----+-----+--------+-----+------+-------+----------+ +# |1.4-rc2-0-12345678 | 1| 4| 2| 0| false| false| true| +# |1.4-rc3-6-12345678 | 1| 4| 3| 6| false| true| true| +# |1.4-0-12345678 | 1| 4| 1000| 0| false| false| false| +# |1.4-6-123345678 | 1| 4| 1000| 6| false| true| false| +# |1.4.2-rc1-0-12345678 | 1| 4| 20001| 0| true| false| true| +# |1.4.2-rc4-6-12345678 | 1| 4| 20004| 6| true| true| true| +# |1.4.2-0-12345678 | 1| 4| 21000| 0| true| false| false| +# |1.4.2-6-12345678 | 1| 4| 21000| 6| true| true| false| +# +---------------------+-----+-----+--------+-----+------+-------+----------+ # $scriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition $file_path = $scriptPath + "\..\src\windows\include\srcversion.h" $git_version_file = $scriptPath + "\..\GIT_VERSION" +$version_file = $scriptPath + "\..\VERSION" $git = Get-Command -Name git -ErrorAction SilentlyContinue if (Test-Path $file_path) { @@ -84,6 +94,9 @@ $CUSTOM = $false if ($null -ne $args[0]) { $version = $args[0] $ver_array = $version.split("-+") +} elseif (Test-Path $version_file) { + $version = Get-Content $version_file + $ver_array = $version.split("-+") } elseif ($null -ne $git) { $version = $(git describe) $ver_array = $(git describe --long).split("-+") @@ -111,30 +124,33 @@ if ($null -ne $args[0]) { } if ($null -ne $ver_array) { - $MAJOR = $ver_array[0].split(".")[0] - $MINOR = $ver_array[0].split(".")[1] + $ver_dots = $ver_array[0].split(".") + $MAJOR = $ver_dots[0] + $MINOR = $ver_dots[1] + if ($ver_dots.length -ge 3) { + $REV = $ver_dots[2] + $BUGFIX = $true + } else { + $REV = 0 + } + + $REVISION = 10000 * $REV $BUILD = $ver_array[$ver_array.length - 2] if ($ver_array.length -eq 4) { - # <MAJOR>.<MINOR>-<SUFFIX><REVISION>-<BUILDNUMBER>-<HASH> - # <MAJOR>.<MINOR>+<SUFFIX><REVISION>-<BUILDNUMBER>-<HASH> + # <MAJOR>.<MINOR>[.<BUGFIX>]-<SUFFIX><REVISION>-<BUILD>-<HASH> if ($ver_array[1].StartsWith("rc")) { - # <MAJOR>.<MINOR>-rc<REVISION>-<BUILDNUMBER>-<HASH> - $REVISION = $ver_array[1].Substring("rc".Length) + # <MAJOR>.<MINOR>[.<BUGFIX>]-rc<REVISION>-<BUILD>-<HASH> + $REVISION += $ver_array[1].Substring("rc".Length) $PRERELEASE = $true - } elseif ($ver_array[1].StartsWith("b")) { - # <MAJOR>.<MINOR>+b<REVISION>-<BUILDNUMBER>-<HASH> - $REVISION = 1000 + $ver_array[1].Substring("b".Length) - $BUGFIX = $true } else { - # <MAJOR>.<MINOR>-<SUFFIX><REVISION>-<BUILDNUMBER>-<HASH> - $REVISION = 0 - $PRERELEASE = $true + # <MAJOR>.<MINOR>[.<BUGFIX>]-<SOMETHING>-<BUILD>-<HASH> + throw "Unknown version format" } } else { - # <MAJOR>.<MINOR>-<BUILDNUMBER>-<HASH> - $REVISION = 1000 + # <MAJOR>.<MINOR>[.<BUGFIX>]-<BUILD>-<HASH> + $REVISION += 1000 } if ($BUILD -eq 0) { diff --git a/src/version.inc b/utils/version.sh old mode 100644 new mode 100755 similarity index 55% rename from src/version.inc rename to utils/version.sh index 62758ad42..29d939a09 --- a/src/version.inc +++ b/utils/version.sh @@ -1,5 +1,6 @@ +#!/usr/bin/env bash # -# Copyright 2017, Intel Corporation +# Copyright 2017-2018, Intel Corporation # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -28,35 +29,60 @@ # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - # -# src/version.inc -- common version rules for PMDK makefiles +# utils/version.sh -- determine project's version # +set -e -TOP := $(dir $(lastword $(MAKEFILE_LIST))).. +if [ -f "$1/VERSION" ]; then + cat "$1/VERSION" + exit 0 +fi -VERSION = $(TOP)/.version -GIT_VERSION = $(TOP)/.git_version +if [ -f $1/GIT_VERSION ]; then + echo -n "\$Format:%h %d\$" | cmp -s $1/GIT_VERSION - && true + if [ $? -eq 0 ]; then + PARSE_GIT_VERSION=0 + else + PARSE_GIT_VERSION=1 + fi +else + PARSE_GIT_VERSION=0 +fi -GIT_VERSION_TAG=$(shell cat $(TOP)/GIT_VERSION | grep tag: | sed 's/.*tag: \([0-9a-z.+-]*\).*/\1/') -GIT_VERSION_HASH=$(shell cat $(TOP)/GIT_VERSION | sed -e 's/.Format:%h %d.//g' -e 's/ .*//') +if [ $PARSE_GIT_VERSION -eq 1 ]; then + GIT_VERSION_TAG=$(cat $1/GIT_VERSION | grep tag: | sed 's/.*tag: \([0-9a-z.+-]*\).*/\1/') + GIT_VERSION_HASH=$(cat $1/GIT_VERSION | sed -e 's/ .*//') -ifneq ($(GIT_VERSION_TAG),) -$(shell echo "$(GIT_VERSION_TAG)" > $(GIT_VERSION)) -else -ifneq ($(GIT_VERSION_HASH),) -$(shell echo "$(GIT_VERSION_HASH)" > $(GIT_VERSION)) -else -$(shell rm -f $(GIT_VERSION)) -endif -endif - -export SRCVERSION = $(shell git describe 2>/dev/null ||\ - cat $(VERSION) 2>/dev/null ||\ - git log -1 --format=%h 2>/dev/null ||\ - cat $(GIT_VERSION) 2>/dev/null ||\ - (basename `realpath $(TOP)` | sed 's/pmdk[-]*\([0-9a-z.+-]*\).*/\1/')) - -ifeq ($(SRCVERSION),) -$(error Cannot evaluate version) -endif + if [ -n "$GIT_VERSION_TAG" ]; then + echo "$GIT_VERSION_TAG" + exit 0 + fi + + if [ -n "$GIT_VERSION_HASH" ]; then + echo "$GIT_VERSION_HASH" + exit 0 + fi +fi + +GIT_DESCRIBE=$(git -C $1 describe 2>/dev/null) && true +if [ -n "$GIT_DESCRIBE" ]; then + echo "$GIT_DESCRIBE" + exit 0 +fi + +# try commit it, git describe can fail when there are no tags (e.g. with shallow clone, like on Travis) +GIT_COMMIT=$(git -C $1 log -1 --format=%h) && true +if [ -n "$GIT_COMMIT" ]; then + echo "$GIT_COMMIT" + exit 0 +fi + +# If nothing works, try to get version from directory name +VER=$(basename `realpath $1` | sed 's/pmdk[-]*\([0-9a-z.+-]*\).*/\1/') +if [ -n "$VER" ]; then + echo "$VER" + exit 0 +fi + +exit 1 -- GitLab