Make version output more human-friendly

Our main version string is designed for release engineering purposes:
it matches file name conventions used for versioned tarballs and the
versions sort lexicographically while containing all pertinent
information.

With this commit we add in parentheses a more human-friendly rendering
of the version string: we spell out the meaning of each field and
render the datetime in RFC 822 notation.
This commit is contained in:
Travis Cross 2012-07-20 07:33:40 +00:00
parent cae357e784
commit a8019d803c
10 changed files with 48 additions and 6 deletions

View File

@ -422,7 +422,10 @@ src/include/switch_version.h: src/include/switch_version.h.in Makefile build/pri
@cat $< > $@; \
if [ -d .git ] && [ -n "$$(which git)" ]; then \
xver="$$(./build/print_git_revision)"; \
sed -e "/#define *SWITCH_VERSION_REVISION/{s/\"\([^\"]*\)\"/\"\1$$xver\"/;}" \
xhver="$$(./build/print_git_revision -h)"; \
sed \
-e "/#define *SWITCH_VERSION_REVISION\W/{s/\"\([^\"]*\)\"/\"\1$$xver\"/;}" \
-e "/#define *SWITCH_VERSION_REVISION_HUMAN\W/{s/\"\([^\"]*\)\"/\"\1$$xhver\"/;}" \
$< > $@; \
fi;

View File

@ -42,7 +42,7 @@ static int sys1(char *buf, int buflen, char *cmd) {
return 0;
}
int main(int argc, char **argv) {
static int print_version(void) {
char xver[256], xdate[256], xfdate[256], xcommit[256];
time_t xdate_t; struct tm *xdate_tm;
if ((sys1(xdate,sizeof(xdate),"git log -n1 --format='%ct' HEAD"))) return 1;
@ -63,3 +63,31 @@ int main(int argc, char **argv) {
return 0;
}
static int print_human_version(void) {
char xver[256], xdate[256], xfdate[256], xcommit[256];
time_t xdate_t; struct tm *xdate_tm;
if ((sys1(xdate,sizeof(xdate),"git log -n1 --format='%ct' HEAD"))) return 1;
xdate_t=(time_t)atoi(xdate);
if (!(xdate_tm=gmtime(&xdate_t))) return 1;
strftime(xfdate,sizeof(xfdate),"%a, %d %b %Y %H:%M:%S Z",xdate_tm);
if ((sys1(xcommit,sizeof(xcommit),"git rev-list -n1 --abbrev=10 --abbrev-commit HEAD")))
return 1;
snprintf(xver,sizeof(xver),"; git at commit %s on %s",xcommit,xfdate);
if (show_unclean && (sys(NULL,0,"git diff-index --quiet HEAD"))) {
char buf[256], now[256]; time_t now_t=time(NULL); struct tm *now_tm;
if (!(now_tm=gmtime(&now_t))) return 1;
strftime(now,sizeof(now),"%a, %d %b %Y %H:%M:%S Z",now_tm);
snprintf(buf,sizeof(buf),"%s; unclean git build on %s",xver,now);
strncpy(xver,buf,sizeof(xver));
}
printf("%s\n",xver);
return 0;
}
int main(int argc, char **argv) {
if (argc > 1 && !strcasecmp(argv[1],"-h"))
return print_human_version();
else
return print_version();
}

View File

@ -8,6 +8,7 @@ AC_SUBST(SWITCH_VERSION_MAJOR, [1])
AC_SUBST(SWITCH_VERSION_MINOR, [2])
AC_SUBST(SWITCH_VERSION_MICRO, [0])
AC_SUBST(SWITCH_VERSION_REVISION, [-rc2])
AC_SUBST(SWITCH_VERSION_REVISION_HUMAN, [-rc2])
AC_CONFIG_FILES([src/include/switch_version.h.in:src/include/switch_version.h.template])

View File

@ -98,15 +98,18 @@ parse_version () {
}
set_fs_ver () {
local ver="$1" major="$2" minor="$3" micro="$4" rev="$5"
local ver="$1" major="$2" minor="$3" micro="$4" rev="$5" hrev="$6"
sed -e "s|\(AC_SUBST(SWITCH_VERSION_MAJOR, \[\).*\(\])\)|\1$major\2|" \
-e "s|\(AC_SUBST(SWITCH_VERSION_MINOR, \[\).*\(\])\)|\1$minor\2|" \
-e "s|\(AC_SUBST(SWITCH_VERSION_MICRO, \[\).*\(\])\)|\1$micro\2|" \
-e "s|\(AC_INIT(\[freeswitch\], \[\).*\(\], BUG-REPORT-ADDRESS)\)|\1$ver\2|" \
-i configure.in
if [ -n "$rev" ]; then
[ -n "$hrev" ] || hrev="$rev"
sed -e "s|\(AC_SUBST(SWITCH_VERSION_REVISION, \[\).*\(\])\)|\1$rev\2|" \
-e "s|\(AC_SUBST(SWITCH_VERSION_REVISION_HUMAN, \[\).*\(\])\)|\1$hrev\2|" \
-e "s|#\(AC_SUBST(SWITCH_VERSION_REVISION\)|\1|" \
-e "s|#\(AC_SUBST(SWITCH_VERSION_REVISION_HUMAN\)|\1|" \
-i configure.in
fi
}

View File

@ -44,7 +44,9 @@ sed -e "s|\(AC_SUBST(SWITCH_VERSION_MAJOR, \[\).*\(\])\)|\1$major\2|" \
if [ -n "$rev" ]; then
sed -e "s|\(AC_SUBST(SWITCH_VERSION_REVISION, \[\).*\(\])\)|\1$rev\2|" \
-e "s|\(AC_SUBST(SWITCH_VERSION_REVISION_HUMAN, \[\).*\(\])\)|\1$rev\2|" \
-e "s|#\(AC_SUBST(SWITCH_VERSION_REVISION\)|\1|" \
-e "s|#\(AC_SUBST(SWITCH_VERSION_REVISION_HUMAN\)|\1|" \
-i configure.in
fi

View File

@ -41,7 +41,9 @@ extern "C" {
#define SWITCH_VERSION_MINOR "@freeswitch_MINOR_VERSION@"
#define SWITCH_VERSION_MICRO "@freeswitch_PATCH_LEVEL@"
#define SWITCH_VERSION_REVISION "@Project_WC_REVISION@"
#define SWITCH_VERSION_REVISION_HUMAN "@Project_WC_REVISION@"
#define SWITCH_VERSION_FULL SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO SWITCH_VERSION_REVISION
#define SWITCH_VERSION_FULL_HUMAN SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO SWITCH_VERSION_REVISION_HUMAN
#ifdef __cplusplus
}

View File

@ -41,7 +41,9 @@ extern "C" {
#define SWITCH_VERSION_MINOR "@SWITCH_VERSION_MINOR@"
#define SWITCH_VERSION_MICRO "@SWITCH_VERSION_MICRO@"
#define SWITCH_VERSION_REVISION "@SWITCH_VERSION_REVISION@"
#define SWITCH_VERSION_REVISION_HUMAN "@SWITCH_VERSION_REVISION_HUMAN@"
#define SWITCH_VERSION_FULL SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO SWITCH_VERSION_REVISION
#define SWITCH_VERSION_FULL_HUMAN SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO SWITCH_VERSION_REVISION_HUMAN
#ifdef __cplusplus
}

View File

@ -285,7 +285,7 @@ SWITCH_STANDARD_API(shutdown_function)
SWITCH_STANDARD_API(version_function)
{
stream->write_function(stream, "FreeSWITCH Version %s\n", SWITCH_VERSION_FULL);
stream->write_function(stream, "FreeSWITCH Version %s (%s)\n", SWITCH_VERSION_FULL, SWITCH_VERSION_FULL_HUMAN);
return SWITCH_STATUS_SUCCESS;
}

View File

@ -577,7 +577,7 @@ int main(int argc, char *argv[])
}
else if (!strcmp(local_argv[x], "-version")) {
fprintf(stdout, "FreeSWITCH version: %s\n", SWITCH_VERSION_FULL);
fprintf(stdout, "FreeSWITCH version: %s (%s)\n", SWITCH_VERSION_FULL, SWITCH_VERSION_FULL_HUMAN);
exit(EXIT_SUCCESS);
}
#endif

View File

@ -1959,7 +1959,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init_and_modload(switch_core_flag_t
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,
"\nFreeSWITCH Version %s Started.\nMax Sessions[%u]\nSession Rate[%d]\nSQL [%s]\n", SWITCH_VERSION_FULL,
"\nFreeSWITCH Version %s (%s) Started.\nMax Sessions[%u]\nSession Rate[%d]\nSQL [%s]\n",
SWITCH_VERSION_FULL, SWITCH_VERSION_FULL_HUMAN,
switch_core_session_limit(0),
switch_core_sessions_per_second(0), switch_test_flag((&runtime), SCF_USE_SQL) ? "Enabled" : "Disabled");