From f0b982795c19ff6517e564f4757791df2228db4c Mon Sep 17 00:00:00 2001 From: Stephen Dolan Date: Fri, 24 May 2013 23:34:34 +0100 Subject: [PATCH] Make jq --version report an actual git revision. Closes #129. --- .gitignore | 1 + Makefile.am | 10 +++++----- main.c | 5 +++-- scripts/version | 5 +++++ 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100755 scripts/version diff --git a/.gitignore b/.gitignore index a8250a5..ba354c6 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ jq-*.tar.gz configure aclocal.m4 Makefile.in +version.h diff --git a/Makefile.am b/Makefile.am index 5508e9a..23e9d25 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,7 +33,10 @@ AM_YFLAGS = --warnings=all -d ### Building the jq binary -main.c: config.h +version.h: + @ { $(srcdir)/scripts/version || echo '$(VERSION)'; } | sed 's/.*/#define JQ_VERSION "&"/'> $@ + +main.c: config.h version.h bin_PROGRAMS = jq jq_SOURCES = ${JQ_SRC} main.c @@ -95,16 +98,13 @@ DOC_FILES = docs/content docs/public docs/templates docs/site.yml \ # the developer setup script in the tarball. EXTRA_DIST = config.h.in $(BUILT_SOURCES) $(man_MANS) $(TESTS) \ $(TEST_LOG_COMPILER) gen_utf8_tables.py jq.spec \ - $(DOC_FILES) + $(DOC_FILES) scripts/version # README.md is expected in Github projects, good stuff in it, so we'll # distribute it and install it with the package in the doc directory. docdir = ${datadir}/doc/${PACKAGE} dist_doc_DATA = README.md COPYING AUTHORS README -releasetag: - git tag -s "jq-$$(cat VERSION)" -m "jq release $$(cat VERSION)" - RELEASE ?= 1 rpm: jq @echo "Packaging jq as an RPM ..." diff --git a/main.c b/main.c index 42e309a..1e95184 100644 --- a/main.c +++ b/main.c @@ -9,13 +9,14 @@ #include "execute.h" #include "config.h" /* Autoconf generated header file */ #include "jv_alloc.h" +#include "version.h" int jq_testsuite(int argc, char* argv[]); static const char* progname; static void usage() { - fprintf(stderr, "\njq - commandline JSON processor [version %s]\n", PACKAGE_VERSION); + fprintf(stderr, "\njq - commandline JSON processor [version %s]\n", JQ_VERSION); fprintf(stderr, "Usage: %s [options] [file...]\n\n", progname); fprintf(stderr, "For a description of the command line options and\n"); fprintf(stderr, "how to write jq filters (and why you might want to)\n"); @@ -238,7 +239,7 @@ int main(int argc, char* argv[]) { } else if (isoption(argv[i], 'h', "help")) { usage(); } else if (isoption(argv[i], 'V', "version")) { - fprintf(stderr, "jq version %s\n", PACKAGE_VERSION); + fprintf(stderr, "jq-%s\n", JQ_VERSION); return 0; } else { fprintf(stderr, "%s: Unknown option %s\n", progname, argv[i]); diff --git a/scripts/version b/scripts/version new file mode 100755 index 0000000..fb941a0 --- /dev/null +++ b/scripts/version @@ -0,0 +1,5 @@ +#!/bin/sh +set -e +cd `dirname "$0"` +git rev-parse --verify -q jq-1.0 > /dev/null 2>&1 +git describe --always --match 'jq-*' --dirty | sed 's/^jq-//' -- 2.40.0