Incorporate some git information into NetHack
Incorporate some git information into NetHack so that it
is potentially visible to a player. That's useful when
collecting details about the version that they are
running and, if the gitinfo is present, it can tie the
code to a specific git commit in the repository.
This modifies 'makedefs -v' to check for the presence of a data file
called dat/gitinfo.txt and if it is there, parse out its
contents, then write additional lines to include/date.h beyond
what 'makedefs -v' was previously putting in there, similar to
this sample:
#define NETHACK_GIT_SHA "0c84e564c78e2024e562d39539376ce2e21eec8e"
#define NETHACK_GIT_BRANCH "NetHack-3.6.0"
The contents of an appropriate dat/gitinfo.txt are as follows,
and trailing/leading whitespace is not significant:
githash = 0c84e564c78e2024e562d39539376ce2e21eec8e
gitbranch = NetHack-3.6.0
It also adjusts the contents of the 'v' version information to
include the additional git info when available.
Also adds some hooks DEVEL/hooksdir and a perl file to DEVEL
for simplifying and automating the deposit of dat/gitinfo.txt
so that it generally reflects the most current git commit.
DEVEL/gitinfo.pl can be used to build dat/gitinfo.txt at any
time without doing a commit, merge, or checkout.
perl DEVEL/gitinfo.pl
command line --version and -version support
To complement the extra information being provided in the
version by the 'v' command, this also adds support for the
following new command line arguments:
--version
-version Output the NetHack version string then exit.
--version:paste Output the NetHack version string and also copy it to
-version:paste the platform's paste buffer for insertion somewhere,
then exit.
If the paste variation of -version is requested on a platform that
hasn't incorporated any support for the capability, it will deliver
the version info then an error message, prior to exiting.
To support the extended -version:paste variation, a port needs to:
- provide a port-specific routine to perform
the paste buffer copy in a port code file.
- #define RUNTIME_PASTEBUF_SUPPORT in the include/portconf.h header file.
--skeleton--
void port_insert_pastebuf(buf)
char *buf;
{
/* insert code to copy the version info from buf into
platform's paste buffer in a supported way */
}
macosx and Windows have both added support for RUNTIME_PASTEBUF_SUPPORT
This commit is contained in:
@@ -72,6 +72,7 @@ static const char SCCS_Id[] = "@(#)makedefs.c\t3.6\t2016/02/12";
|
||||
#define QTXT_O_FILE "quest.dat"
|
||||
#define VIS_TAB_H "vis_tab.h"
|
||||
#define VIS_TAB_C "vis_tab.c"
|
||||
#define GITINFO_FILE "gitinfo.txt"
|
||||
/* locations for those files */
|
||||
#ifdef AMIGA
|
||||
#define FILE_PREFIX
|
||||
@@ -177,6 +178,7 @@ static char *FDECL(bannerc_string, (char *, const char *));
|
||||
static char *FDECL(xcrypt, (const char *));
|
||||
static unsigned long FDECL(read_rumors_file,
|
||||
(const char *, int *, long *, unsigned long));
|
||||
static boolean FDECL(get_gitinfo, (char *, char *));
|
||||
static void FDECL(do_rnd_access_file, (const char *));
|
||||
static boolean FDECL(d_filter, (char *));
|
||||
static boolean FDECL(h_filter, (char *));
|
||||
@@ -209,6 +211,7 @@ static char *FDECL(fgetline, (FILE*));
|
||||
static char *FDECL(tmpdup, (const char *));
|
||||
static char *FDECL(limit, (char *, int));
|
||||
static char *FDECL(eos, (char *));
|
||||
static int FDECL(case_insensitive_comp, (const char *, const char *));
|
||||
|
||||
/* input, output, tmp */
|
||||
static FILE *ifp, *ofp, *tfp;
|
||||
@@ -1239,6 +1242,7 @@ do_date()
|
||||
#else
|
||||
time_t clocktim = 0;
|
||||
#endif
|
||||
char githash[BUFSZ], gitbranch[BUFSZ];
|
||||
char *c, cbuf[60], buf[BUFSZ];
|
||||
const char *ul_sfx;
|
||||
|
||||
@@ -1372,6 +1376,10 @@ do_date()
|
||||
Fprintf(ofp, "#define COPYRIGHT_BANNER_C \\\n \"%s\"\n",
|
||||
bannerc_string(buf, cbuf));
|
||||
Fprintf(ofp, "\n");
|
||||
if (get_gitinfo(githash, gitbranch)) {
|
||||
Fprintf(ofp, "#define NETHACK_GIT_SHA \"%s\"\n", githash);
|
||||
Fprintf(ofp, "#define NETHACK_GIT_BRANCH \"%s\"\n", gitbranch);
|
||||
}
|
||||
#ifdef AMIGA
|
||||
{
|
||||
struct tm *tm = localtime((time_t *) &clocktim);
|
||||
@@ -1386,6 +1394,84 @@ do_date()
|
||||
return;
|
||||
}
|
||||
|
||||
boolean
|
||||
get_gitinfo(githash, gitbranch)
|
||||
char *githash, *gitbranch;
|
||||
{
|
||||
FILE *gifp;
|
||||
size_t len;
|
||||
char infile[600];
|
||||
char *line, *strval, *opt, *c, *end;
|
||||
boolean havebranch = FALSE, havehash = FALSE;
|
||||
|
||||
if (!githash || !gitbranch) return FALSE;
|
||||
|
||||
Sprintf(infile, DATA_IN_TEMPLATE, GITINFO_FILE);
|
||||
if (!(gifp = fopen(infile, RDTMODE))) {
|
||||
/* perror(infile); */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* read the gitinfo file */
|
||||
while ((line = fgetline(gifp)) != 0) {
|
||||
strval = index(line, '=');
|
||||
if (strval && strlen(strval) < (BUFSZ-1)) {
|
||||
opt = line;
|
||||
*strval++ = '\0';
|
||||
/* strip off the '\n' */
|
||||
if ((c = index(strval, '\n')) != 0)
|
||||
*c = '\0';
|
||||
if ((c = index(opt, '\n')) != 0)
|
||||
*c = '\0';
|
||||
/* strip leading and trailing white space */
|
||||
while (*strval == ' ' || *strval == '\t')
|
||||
strval++;
|
||||
end = eos(strval);
|
||||
while (--end >= strval && (*end == ' ' || *end == '\t'))
|
||||
*end = '\0';
|
||||
while (*opt == ' ' || *opt == '\t')
|
||||
opt++;
|
||||
end = eos(opt);
|
||||
while (--end >= opt && (*end == ' ' || *end == '\t'))
|
||||
*end = '\0';
|
||||
|
||||
len = strlen(opt);
|
||||
if ((len >= strlen("gitbranch")) && !case_insensitive_comp(opt, "gitbranch")) {
|
||||
Strcpy(gitbranch, strval);
|
||||
havebranch = TRUE;
|
||||
}
|
||||
if ((len >= strlen("githash")) && !case_insensitive_comp(opt, "githash")) {
|
||||
Strcpy(githash, strval);
|
||||
havehash = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
Fclose(gifp);
|
||||
if (havebranch && havehash)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
case_insensitive_comp(s1, s2)
|
||||
const char *s1;
|
||||
const char *s2;
|
||||
{
|
||||
uchar u1, u2;
|
||||
|
||||
for (;; s1++, s2++) {
|
||||
u1 = (uchar) *s1;
|
||||
if (isupper(u1))
|
||||
u1 = tolower(u1);
|
||||
u2 = (uchar) *s2;
|
||||
if (isupper(u2))
|
||||
u2 = tolower(u2);
|
||||
if (u1 == '\0' || u1 != u2)
|
||||
break;
|
||||
}
|
||||
return u1 - u2;
|
||||
}
|
||||
|
||||
static char save_bones_compat_buf[BUFSZ];
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user