Browse Source

Use `git describe` to generate version.h to avoid user confusion over builds from git

Luke Dashjr 11 years ago
parent
commit
4f231186c3
9 changed files with 65 additions and 1 deletions
  1. 2 0
      .gitignore
  2. 7 0
      Makefile.am
  3. 1 0
      api.c
  4. 5 0
      autogen.sh
  5. 24 0
      gen-version.sh
  6. 1 0
      httpsrv.c
  7. 1 0
      make-release
  8. 23 1
      miner.c
  9. 1 0
      util.c

+ 2 - 0
.gitignore

@@ -51,6 +51,8 @@ lib/string.h
 lib/stdint.h
 lib/warn-on-use.h
 iospeeds_local.h
+version.h
+version.h.new
 
 mkinstalldirs
 

+ 7 - 0
Makefile.am

@@ -76,6 +76,13 @@ bfgminer_SOURCES += miner.h compat.h  \
 		   sha2.c sha2.h api.c
 EXTRA_bfgminer_DEPENDENCIES =
 
+.PHONY: update-version
+update-version:
+	./gen-version.sh >version.h.new
+	cmp version.h version.h.new && rm version.h.new || mv version.h.new version.h
+version.h: update-version
+bfgminer_SOURCES += version.h
+
 SUBDIRS += $(LIBBLKMAKER_SUBDIRS)
 LIBBLKMAKER_SUBDIRS =
 if NEED_LIBBLKMAKER

+ 1 - 0
api.c

@@ -35,6 +35,7 @@
 #include "util.h"
 #include "driver-cpu.h" /* for algo_names[], TODO: re-factor dependency */
 #include "driver-opencl.h"
+#include "version.h"
 
 #define HAVE_AN_FPGA 1
 

+ 5 - 0
autogen.sh

@@ -23,3 +23,8 @@ echo 'Running autoreconf -if...'
 	rm -f aclocal.m4 ltmain.sh
 	autoreconf -if ${AC_FLAGS}
 )
+
+echo 'Updating version.h...'
+if ./gen-version.sh >version.h.new; then
+	cmp version.h version.h.new && rm version.h.new || mv version.h.new version.h
+fi

+ 24 - 0
gen-version.sh

@@ -0,0 +1,24 @@
+#!/bin/sh
+gitdesc=
+if [ -e .git ]; then
+	# Some versions of git require `git diff` to scan and update dirty-or-not status
+	git diff >/dev/null 2>/dev/null
+	
+	gitdesc=$(git describe)
+fi
+if [ -z "$gitdesc" ]; then
+	current=$(sed 's/^\#define[[:space:]]\+BFG_GIT_DESCRIBE[[:space:]]\+\"\(.*\)\"$/\1/;t;d' version.h)
+	if [ -z "$current" ]; then
+		gitdesc='"PACKAGE_VERSION"-unknown'
+	else
+		gitdesc="$current"
+	fi
+fi
+version=$(sed 's/^bfgminer-//' <<<"$gitdesc")
+cat <<EOF
+#define BFG_GIT_DESCRIBE "$gitdesc"
+#ifdef VERSION
+#  undef VERSION
+#endif
+#define VERSION "$version"
+EOF

+ 1 - 0
httpsrv.c

@@ -29,6 +29,7 @@
 
 #include "logging.h"
 #include "util.h"
+#include "version.h"
 
 static struct MHD_Daemon *httpsrv;
 

+ 1 - 0
make-release

@@ -48,6 +48,7 @@ git submodule update --init
 		git archive --prefix "$sw/ccan-upstream/" --format tar HEAD ccan/{build_assert,cast,compiler,opt,typesafe_cb} licenses/{CC0,GPL-3,LGPL-2.1}
 	)
 } | tar -xivp
+./gen-version.sh >"$sw"/version.h
 cd "$sw"
 NOSUBMODULES=1 \
 NOCONFIGURE=1 \

+ 23 - 1
miner.c

@@ -99,6 +99,8 @@
 #include "scrypt.h"
 #endif
 
+#include "version.h"
+
 #if defined(USE_AVALON) || defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_MODMINER) || defined(USE_NANOFURY) || defined(USE_X6500) || defined(USE_ZTEX)
 #	define USE_FPGA
 #endif
@@ -3934,6 +3936,15 @@ void bfg_hline(WINDOW *win, int y)
 		mvwhline(win, y, 0, '-', maxx);
 }
 
+static
+int bfg_win_linelen(WINDOW * const win)
+{
+	int maxx;
+	int __maybe_unused y;
+	getmaxyx(win, y, maxx);
+	return maxx;
+}
+
 // Spaces until end of line, using current attributes (ie, not completely clear)
 static
 void bfg_wspctoeol(WINDOW * const win, const int offset)
@@ -3982,7 +3993,18 @@ static void curses_print_status(const int ts)
 	efficiency = total_bytes_xfer ? total_diff_accepted * 2048. / total_bytes_xfer : 0.0;
 
 	wattron(statuswin, attr_title);
-	cg_mvwprintw(statuswin, 0, 0, " " PACKAGE " version " VERSION " - Started: %s", datestamp);
+	const int linelen = bfg_win_linelen(statuswin);
+	int titlelen = 1 + strlen(PACKAGE) + 1 + strlen(VERSION) + 3 + 21 + 3 + 19;
+	cg_mvwprintw(statuswin, 0, 0, " " PACKAGE " ");
+	if (titlelen + 17 < linelen)
+		cg_wprintw(statuswin, "version ");
+	cg_wprintw(statuswin, VERSION " - ");
+	if (titlelen + 9 < linelen)
+		cg_wprintw(statuswin, "Started: ");
+	else
+	if (titlelen + 7 <= linelen)
+		cg_wprintw(statuswin, "Start: ");
+	cg_wprintw(statuswin, "%s", datestamp);
 	timer_set_now(&now);
 	{
 		unsigned int days, hours;

+ 1 - 0
util.c

@@ -59,6 +59,7 @@
 #include "miner.h"
 #include "compat.h"
 #include "util.h"
+#include "version.h"
 
 #define DEFAULT_SOCKWAIT 60