getinfo: add version information

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2016-09-14 05:22:41 +09:30
parent e5b2cacd3f
commit 5b3bde715a
5 changed files with 13 additions and 1 deletions

View File

@ -305,7 +305,7 @@ doc/full-states.dot: test/test_state_coverage
gen_version.h: FORCE gen_version.h: FORCE
@(echo "#define VERSION \"`git describe --always --dirty`\"" && echo "#define VERSION_NAME \"$(NAME)\"" && echo "#define BUILD_FEATURES \"$(FEATURES)\"") > $@.new @(echo "#define VERSION \"`git describe --always --dirty`\"" && echo "#define VERSION_NAME \"$(NAME)\"" && echo "#define BUILD_FEATURES \"$(FEATURES)\"") > $@.new
@if cmp $@.new $@ >/dev/null 2>&2; then rm -f $@.new; else mv $@.new $@; fi @if cmp $@.new $@ >/dev/null 2>&2; then rm -f $@.new; else mv $@.new $@; echo Version updated; fi
version.o: gen_version.h version.o: gen_version.h

View File

@ -6,6 +6,7 @@
#include "lightningd.h" #include "lightningd.h"
#include "log.h" #include "log.h"
#include "peer.h" #include "peer.h"
#include "version.h"
#include <ccan/array_size/array_size.h> #include <ccan/array_size/array_size.h>
#include <ccan/err/err.h> #include <ccan/err/err.h>
#include <ccan/io/io.h> #include <ccan/io/io.h>
@ -266,6 +267,7 @@ static void json_getinfo(struct command *cmd,
if (cmd->dstate->portnum) if (cmd->dstate->portnum)
json_add_num(response, "port", cmd->dstate->portnum); json_add_num(response, "port", cmd->dstate->portnum);
json_add_bool(response, "testnet", cmd->dstate->config.testnet); json_add_bool(response, "testnet", cmd->dstate->config.testnet);
json_add_string(response, "version", version());
json_object_end(response); json_object_end(response);
command_success(cmd, response); command_success(cmd, response);
} }

View File

@ -439,6 +439,10 @@ if ! check "$LCLI3 getlog 2>/dev/null | $FGREP Hello"; then
exit 1 exit 1
fi fi
# Version should be correct
VERSION=`$LCLI1 getinfo | sed -n 's/.*"version" : "\([^"]*\)".*/\1/p'`
[ $VERSION = `git describe --always --dirty` ] || (echo Wrong version $VERSION >&2; exit 1)
ID1=`$LCLI1 getlog | sed -n 's/.*"ID: \([0-9a-f]*\)".*/\1/p'` ID1=`$LCLI1 getlog | sed -n 's/.*"ID: \([0-9a-f]*\)".*/\1/p'`
[ `$LCLI1 getinfo | sed -n 's/.*"id" : "\([0-9a-f]*\)".*/\1/p'` = $ID1 ] [ `$LCLI1 getinfo | sed -n 's/.*"id" : "\([0-9a-f]*\)".*/\1/p'` = $ID1 ]
ID2=`$LCLI2 getlog | sed -n 's/.*"ID: \([0-9a-f]*\)".*/\1/p'` ID2=`$LCLI2 getlog | sed -n 's/.*"ID: \([0-9a-f]*\)".*/\1/p'`

View File

@ -2,6 +2,11 @@
#include "version.h" #include "version.h"
#include <stdio.h> #include <stdio.h>
const char *version(void)
{
return VERSION;
}
char *version_and_exit(const void *unused) char *version_and_exit(const void *unused)
{ {
printf("%s\n" printf("%s\n"

View File

@ -4,6 +4,7 @@
#include <ccan/opt/opt.h> #include <ccan/opt/opt.h>
char *version_and_exit(const void *unused); char *version_and_exit(const void *unused);
const char *version(void);
#define opt_register_version() \ #define opt_register_version() \
opt_register_noarg("--version|-V", version_and_exit, NULL, \ opt_register_noarg("--version|-V", version_and_exit, NULL, \