]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Make version output more human-friendly
authorTravis Cross <tc@traviscross.com>
Fri, 20 Jul 2012 07:33:40 +0000 (07:33 +0000)
committerTravis Cross <tc@traviscross.com>
Fri, 20 Jul 2012 07:43:26 +0000 (07:43 +0000)
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.

Makefile.am
build/print_git_revision.c
configure.in
scripts/ci/common.sh
scripts/dailys.sh
src/include/switch_version.h.cmake
src/include/switch_version.h.template
src/mod/applications/mod_commands/mod_commands.c
src/switch.c
src/switch_core.c

index 1aa424f7547983a732b68acab8433438df7f7a7a..1a0759b166560f8faafe49fb43c968e972bd73b1 100644 (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;
 
index 73580038329e816c10e448c5e4fb59c55cf4f14f..0f8e680b37538e97897e75542833cf0a9bc533b7 100644 (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();
+}
+
index 514a9151e4c635269c31f3b33f4a632aecff1e67..899b0b83c286b0d114075274d6e783fec7cfd8b3 100644 (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])
 
index 3aa6bb3441b8aa546f635a1003d7c75368af1b15..059def200ead06c487c16cc34e2d9d88089443b0 100755 (executable)
@@ -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
 }
index 9d0e639cf5a9077d3d299989efbec57aea5e0641..430de62d22df055e23befbc7d47b8fb05b205a37 100755 (executable)
@@ -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
 
index 7cec6489b3b8f07537533767d2d8f78877560b39..c722c2221d30f7371ed427ec508d268d9c6b87cb 100644 (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
 }
index e0c13811d880ba39debd65d83006b4def4a16ae0..dfec6e091e1c68beaeb7dcf3efce55435bd647ed 100644 (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
 }
index 21a1cb3138997534d781fff5d3830c282716622a..1cde9b30ce3a7a11e632285e103b8d0164162057 100644 (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;
 }
 
index 4f257016713dacfeae6b08dd12a6019dbd50a98e..e1b602356e6586d66f95adb6322d04b07f37112b 100644 (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
index 789b2d2c128c35b502b0bc62a774387cb2505391..c00f13ab78a90cb5da615603cfeeb8fa45ebfec9 100644 (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");