Skip to content

Commit 1deb06b

Browse files
author
Michał Góral
committedApr 21, 2014
Improved version control
subconvert_version.sh script checks for Subconvert version in the following order: 1) .tarball-version file contents (only generated for dist tarballs) 2) git describe 3) fallback version (currently 1.x-unknown) Additionaly, it is invoked every time make is called and version.py __version__ variable is changed with sed (unfortunate hack). It means that version.py will not take into account @PACKAGE_VERSION@ variable.
1 parent 4bfe1ca commit 1deb06b

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed
 

‎Makefile.am

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ EXTRA_DIST = \
1717
CHANGELOG \
1818
resources.qrc \
1919
$(subconvert_SCRIPTS) \
20-
$(desktop_DATA)
20+
$(desktop_DATA) \
21+
tools/subconvert_version.sh
2122

2223
SUBCONVERT_DIR = ./subconvert
2324
COVERAGE_DIR = "coverage"
25+
VERSION = $(shell sh tools/subconvert_version.sh)
2426

2527
gen:
2628
$(PYRCC) -py3 -o $(SUBCONVERT_DIR)/resources.py resources.qrc
29+
$(SED) -i 's/__version__ = .\+/__version__ = "$(VERSION)"/' subconvert/utils/version.py
2730

2831
test: gen
2932
@nosetests3 -v
@@ -45,6 +48,9 @@ install-data-hook:
4548
cd $(DESTDIR)$(bindir) && \
4649
$(LN_S) $(DESTDIR)$(datadir)/subconvert/subconvert.py subconvert
4750

51+
dist-hook:
52+
echo $(VERSION) > $(distdir)/.tarball-version
53+
4854
reinstall:
4955
make uninstall
5056
make install

‎configure.ac

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([Subconvert], [m4_esyscmd_s([git describe --abbrev=4 --dirty --always --tags])], [https://github.com/mgoral/subconvert/issues])
1+
AC_INIT([Subconvert], [m4_esyscmd_s([sh tools/subconvert_version.sh])], [https://github.com/mgoral/subconvert/issues])
22
AM_INIT_AUTOMAKE([foreign -Wall])
33

44
AC_PREFIX_DEFAULT([/usr])
@@ -27,6 +27,11 @@ GETTEXT_PACKAGE=AC_PACKAGE_TARNAME
2727
AC_SUBST(GETTEXT_PACKAGE)
2828
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [gettext package])
2929

30+
AC_CHECK_PROGS([SED], [sed], [:])
31+
if test "$SED" = :; then
32+
AC_MSG_ERROR([Could not find program: sed])
33+
fi
34+
3035
AC_CHECK_PROGS([PYRCC], [pyrcc4], [:])
3136
if test "$PYRCC" = :; then
3237
AC_MSG_ERROR([Could not find program: pyrcc4])

‎tools/subconvert_version.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
# Very simple version generator
4+
# First, we'll check for .tarball-version file (present only in dist tarballs). If it exists, we'll
5+
# take version number from there. Second, we'll try to create git-based version and use it. If all
6+
# methods above fail, we'll set some kind of fallback version number.
7+
#
8+
# Version number is changed in subconvert/utils/version.py every time make is invoked, so
9+
# Subconvert will always display a proper version number. It's a little hacky, but it works.
10+
11+
VERSION_FILE=".tarball-version"
12+
VERSION=""
13+
FALLBACK="1.x-unknown"
14+
15+
nl='
16+
'
17+
18+
if [ -f $VERSION_FILE ]; then
19+
VERSION=`cat $VERSION_FILE` || VERSION=""
20+
fi
21+
22+
if [ "$VERSION" = "" ]; then
23+
if [ -d .git ]; then
24+
VERSION=`git describe --abbrev=4 --dirty --always --tags`
25+
fi
26+
fi
27+
28+
if [ "$VERSION" = "" ]; then
29+
VERSION=$FALLBACK
30+
fi
31+
32+
echo $VERSION | tr -d "$nl"

0 commit comments

Comments
 (0)