Make: Support shallow git clones for testing

Since commit 1ec9b94, we derive the version number from git tags with
build-aux/git-version-gen.  When a shallow clone doesn't include a
suitable tag, this fails, and make refuses to build anything.  Since
Travis uses git-clone --depth=50, it'll break as soon as we've got
more than 50 commits since the last release.

Support arbitrarily shallow clones for limited purposes like testing
by falling back from a proper V.N-H version number to UNKNOWN-H.

To guard against use of such builds for other purposes, log a warning
on server startup, and print one on player login.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2017-09-02 17:18:30 +02:00
parent 41ce9e37fd
commit 5e1b590867
4 changed files with 16 additions and 5 deletions

View file

@ -48,12 +48,16 @@ all:
ifeq ($(revctrl),git) ifeq ($(revctrl),git)
src := $(shell cd $(srcdir) && git ls-files | uniq) src := $(shell cd $(srcdir) && git ls-files | uniq)
version := $(shell cd $(srcdir) && build-aux/git-version-gen /dev/null) version := $(shell cd $(srcdir) && build-aux/git-version-gen /dev/null)
ifeq ($(version),UNKNOWN)
$(warning cannot figure out version number, falling back to git hash)
version := UNKNOWN-$(shell cd $(srcdir) && git-rev-parse --verify --short HEAD || echo "UNKNOWN")
endif
else else
include $(srcdir)/sources.mk include $(srcdir)/sources.mk
version := $(shell cat $(srcdir)/.tarball-version || echo "UNKNOWN") version := $(shell cat $(srcdir)/.tarball-version || echo "UNKNOWN")
endif endif
ifeq ($(version),UNKNOWN) ifeq ($(version),UNKNOWN)
$(error cannot figure out version) $(error cannot figure out version number)
endif endif
dirs := $(sort $(dir $(src))) dirs := $(sort $(dir $(src)))
csrc := $(filter %.c, $(src)) csrc := $(filter %.c, $(src))

View file

@ -28,7 +28,7 @@
* *
* Known contributors to this file: * Known contributors to this file:
* Steve McClure, 2000 * Steve McClure, 2000
* Markus Armbruster, 2004-2014 * Markus Armbruster, 2004-2017
* Ron Koenderink, 2004-2009 * Ron Koenderink, 2004-2009
*/ */
@ -42,7 +42,7 @@
#include "optlist.h" #include "optlist.h"
#include "player.h" #include "player.h"
#include "prototypes.h" #include "prototypes.h"
#include "version.h"
static int command(void); static int command(void);
static int status(void); static int status(void);
@ -63,6 +63,11 @@ player_main(struct player *p)
pr("\n" pr("\n"
"*** Server configured for testing ***\n" "*** Server configured for testing ***\n"
"*** If you see this in a game, it is misconfigured! ***\n"); "*** If you see this in a game, it is misconfigured! ***\n");
else if (strstr(version, "UNKNOWN-"))
pr("\n"
"*** Server version is unknown ***\n"
"*** If you see this in a game, it was built incorrectly! ***\n");
if (init_nats() < 0) { if (init_nats() < 0) {
pr("Server confused, try again later\n"); pr("Server confused, try again later\n");
return; return;

View file

@ -31,7 +31,7 @@
* Steve McClure, 1996, 1998 * Steve McClure, 1996, 1998
* Doug Hay, 1998 * Doug Hay, 1998
* Ron Koenderink, 2004-2009 * Ron Koenderink, 2004-2009
* Markus Armbruster, 2005-2014 * Markus Armbruster, 2005-2017
*/ */
#include <config.h> #include <config.h>
@ -380,6 +380,8 @@ start_server(int flags)
logerror("Empire server (pid %d) started", (int)pid); logerror("Empire server (pid %d) started", (int)pid);
if (running_test_suite) if (running_test_suite)
logerror("Configured for testing"); logerror("Configured for testing");
else if (strstr(version, "UNKNOWN-"))
logerror("Warning: version number unknown");
empth_init((void **)&player, flags); empth_init((void **)&player, flags);

View file

@ -91,7 +91,7 @@ while (<>) {
or /^[0-9]+ (sector|ship|plane|unit|nuke|lost item)/)); or /^[0-9]+ (sector|ship|plane|unit|nuke|lost item)/));
### Version ### Version
s/(Wolfpack( |\\\\040)Empire( |\\\\040))[0-9][^ "]*/${1}4.4.0/; s/(Wolfpack( |\\\\040)Empire( |\\\\040))(UNKNOWN-|[0-9])[^ "]*/${1}4.4.0/;
### Formatted time ### Formatted time
# nat_timeused in prompt # nat_timeused in prompt
s/^\[[0-9]+(:[0-9]+\] Command \:)/[0$1/; s/^\[[0-9]+(:[0-9]+\] Command \:)/[0$1/;