changeset 1159:05f74dc19c49

Include source rev number in version information when available
author Sebastien Decugis <sdecugis@freediameter.net>
date Fri, 31 May 2013 11:20:27 +0800
parents f1cadf58b86f
children 7de036e9e8fd
files cmake/Modules/GetVersionWithHg.cmake freeDiameterd/main.c include/freeDiameter/CMakeLists.txt include/freeDiameter/libfdcore.h include/freeDiameter/libfdproto.h include/freeDiameter/version.h.in libfdcore/CMakeLists.txt libfdcore/core.c libfdcore/version.c libfdproto/CMakeLists.txt libfdproto/version.c
diffstat 11 files changed, 170 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake/Modules/GetVersionWithHg.cmake	Fri May 31 11:20:27 2013 +0800
@@ -0,0 +1,25 @@
+# This file is called at build time. It regenerates the version.h file based on the hg version.
+
+message(STATUS "Calling script")
+
+EXECUTE_PROCESS(
+	COMMAND ${HGCOMMAND} id -i
+	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+	RESULT_VARIABLE reshash
+	OUTPUT_VARIABLE verhash
+	ERROR_QUIET
+	OUTPUT_STRIP_TRAILING_WHITESPACE)
+EXECUTE_PROCESS(
+	COMMAND ${HGCOMMAND} id -n
+	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+	RESULT_VARIABLE resval
+	OUTPUT_VARIABLE verval
+	ERROR_QUIET
+	OUTPUT_STRIP_TRAILING_WHITESPACE)
+	
+if (reshash EQUAL 0) 
+	SET(FD_PROJECT_VERSION_HG "${verval}(${verhash})")
+ 	message(STATUS "Source version: ${FD_PROJECT_VERSION_HG}")
+endif (reshash EQUAL 0)
+
+CONFIGURE_FILE(${SRC} ${DST})
--- a/freeDiameterd/main.c	Fri May 31 11:19:35 2013 +0800
+++ b/freeDiameterd/main.c	Fri May 31 11:20:27 2013 +0800
@@ -110,23 +110,7 @@
 /* Display package version */
 static void main_version_core(void)
 {
-	printf("%s, version %d.%d.%d"
-#ifdef HG_VERSION
-		" (r%s"
-# ifdef PACKAGE_HG_REVISION
-		"/%s"
-# endif /* PACKAGE_HG_VERSION */
-		")"
-#endif /* HG_VERSION */
-		" (libfdcore: %s)\n", 
-		FD_PROJECT_NAME, FD_PROJECT_VERSION_MAJOR, FD_PROJECT_VERSION_MINOR, FD_PROJECT_VERSION_REV
-#ifdef HG_VERSION
-		, HG_VERSION
-# ifdef PACKAGE_HG_REVISION
-		, PACKAGE_HG_REVISION
-# endif /* PACKAGE_HG_VERSION */
-#endif /* HG_VERSION */
-		, fd_core_version());
+	printf("%s, version %s\n", FD_PROJECT_NAME, fd_core_version);
 }
 
 /* Display package version and general info */
--- a/include/freeDiameter/CMakeLists.txt	Fri May 31 11:19:35 2013 +0800
+++ b/include/freeDiameter/CMakeLists.txt	Fri May 31 11:20:27 2013 +0800
@@ -186,6 +186,33 @@
 
 ##########################
 
+# Additional hg version when relevant, stored in version.h
+if (EXISTS "${CMAKE_SOURCE_DIR}/.hg")
+	# Search for hg binary to use
+	FIND_PROGRAM(HGCOMMAND hg)
+	if (HGCOMMAND)
+		# Ok, add the custom target so that hg is executed at every build
+		ADD_CUSTOM_TARGET(version_information
+				   COMMAND ${CMAKE_COMMAND} -D HGCOMMAND="${HGCOMMAND}" -D SRC="${CMAKE_CURRENT_SOURCE_DIR}/version.h.in" -D DST="${CMAKE_CURRENT_BINARY_DIR}/version.h" -P "${CMAKE_SOURCE_DIR}/cmake/Modules/GetVersionWithHg.cmake"
+				   DEPENDS "${CMAKE_SOURCE_DIR}/.hg/dirstate"
+				   WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+				   COMMENT "Retrieving version of the hg repository"
+				   )
+	else (HGCOMMAND)
+		# Display at least "unknown" rev in this case
+		SET(FD_PROJECT_VERSION_HG "unknown")
+		CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
+		ADD_CUSTOM_TARGET(version_information DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/version.h)
+	endif(HGCOMMAND)
+else (EXISTS "${CMAKE_SOURCE_DIR}/.hg")
+	# We use the pure version number without extension
+	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
+	ADD_CUSTOM_TARGET(version_information DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/version.h)
+endif (EXISTS "${CMAKE_SOURCE_DIR}/.hg")
+
+
+##########################
+
 # LFDPROTO_LIBS = libraries required by the libfdproto.
 SET(LFDPROTO_LIBS ${CLOCK_GETTIME_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${IDNA_LIBRARIES} PARENT_SCOPE)
 # And includes paths
--- a/include/freeDiameter/libfdcore.h	Fri May 31 11:19:35 2013 +0800
+++ b/include/freeDiameter/libfdcore.h	Fri May 31 11:20:27 2013 +0800
@@ -60,8 +60,7 @@
 #define CHECK_GNUTLS_GEN( faillevel, __call__, __fallback__  ) { 					\
 		CHECK_PRELUDE(__call__);								\
 		if (__ret__ < 0) {									\
-			__ret__ = errno;								\
-			LOG(faillevel, "ERROR: in '%s' :\t%s",  #__call__ ,  gnutls_strerror(__ret__)); \
+			LOG(faillevel, "TLS ERROR: in '%s' :\t%s",  #__call__ ,  gnutls_strerror(__ret__)); \
 			__fallback__;									\
 		}											\
 }
@@ -75,14 +74,8 @@
 
 #ifndef EXCLUDE_DEPRECATED
 /* Macro for transition, replace with CHECK_GNUTLS_GEN */
-#define CHECK_GNUTLS_DO( __call__, __fallback__ ) {						        \
-		CHECK_PRELUDE(__call__);								\
-		if (__ret__ < 0) {									\
-			__ret__ = errno;								\
-			TRACE_ERROR("ERROR: in '%s' :\t%s",  #__call__ ,  gnutls_strerror(__ret__));    \
-			__fallback__;									\
-		}											\
-}
+#define CHECK_GNUTLS_DO( __call__, __fallback__ )	\
+	CHECK_GNUTLS_GEN( FD_LOG_ERROR, __call__, __fallback__  )
 
 #endif /* EXCLUDE_DEPRECATED */
 
@@ -95,8 +88,8 @@
 /* Initialize the libfdcore internals. This also initializes libfdproto */
 int fd_core_initialize(void);
 
-/* Return a string describing the version of the library */
-const char *fd_core_version(void);
+/* A string describing the version of the library */
+extern const char fd_core_version[];
 
 /* Parse the freeDiameter.conf configuration file, load the extensions */
 int fd_core_parseconf(const char * conffile);
--- a/include/freeDiameter/libfdproto.h	Fri May 31 11:19:35 2013 +0800
+++ b/include/freeDiameter/libfdproto.h	Fri May 31 11:20:27 2013 +0800
@@ -122,6 +122,8 @@
 /* Call this one when the application terminates, to destroy internal threads */
 void fd_libproto_fini(void);
 
+/* Retrieve the version of the binary */
+extern const char fd_libproto_version[];
 
 /*============================================================*/
 /*                          DEBUG                             */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/freeDiameter/version.h.in	Fri May 31 11:20:27 2013 +0800
@@ -0,0 +1,3 @@
+/* Following variable is expended at build time bbased on the result of "hg id" command */
+#cmakedefine FD_PROJECT_VERSION_HG
+#define FD_PROJECT_VERSION_HG_VAL "@FD_PROJECT_VERSION_HG@"
--- a/libfdcore/CMakeLists.txt	Fri May 31 11:19:35 2013 +0800
+++ b/libfdcore/CMakeLists.txt	Fri May 31 11:20:27 2013 +0800
@@ -34,6 +34,7 @@
 	routing_dispatch.c
 	server.c
 	tcp.c
+	version.c
 	)
 
 IF(NOT DISABLE_SCTP)
@@ -52,9 +53,11 @@
 
 # Include path
 INCLUDE_DIRECTORIES(${LFDCORE_INCLUDES})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
 
 # Build the executable
 ADD_LIBRARY(libfdcore SHARED ${FDCORE_SRC} ${FDCORE_GEN_SRC})
+ADD_DEPENDENCIES(libfdcore version_information)
 
 # Avoid the liblib name, and set the version
 SET_TARGET_PROPERTIES(libfdcore PROPERTIES 
--- a/libfdcore/core.c	Fri May 31 11:19:35 2013 +0800
+++ b/libfdcore/core.c	Fri May 31 11:20:27 2013 +0800
@@ -165,12 +165,6 @@
 /*********************************/
 /* Public interfaces */
 
-/* Return a string describing the version of the library */
-const char *fd_core_version(void)
-{
-	return _stringize(FD_PROJECT_VERSION_MAJOR) "." _stringize(FD_PROJECT_VERSION_MINOR) "." _stringize(FD_PROJECT_VERSION_REV);
-}
-
 /* Initialize the libfdcore internals. This also initializes libfdproto */
 int fd_core_initialize(void)
 {
@@ -188,11 +182,11 @@
 		return ret;
 	}
 	
-	LOG_N("libfdproto initialized.");
-	
 	/* Name this thread */
 	fd_log_threadname("Main");
 	
+	LOG_N("libfdproto '%s' initialized.", fd_libproto_version);
+	
 	/* Initialize gcrypt and gnutls */
 	#ifndef GNUTLS_VERSION_210
 	GNUTLS_TRACE( (void) gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread) );
@@ -226,6 +220,9 @@
 	
 	core_state_set(CORE_LIBS_INIT);
 	
+	LOG_N("libfdcore '%s' initialized.", fd_core_version);
+	
+	
 	/* Next thing is to parse the config, leave this for a different function */
 	return 0;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libfdcore/version.c	Fri May 31 11:20:27 2013 +0800
@@ -0,0 +1,47 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Sebastien Decugis <sdecugis@freediameter.net>							 *
+*													 *
+* Copyright (c) 2013, WIDE Project and NICT								 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the WIDE Project or NICT nor the 						 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of WIDE Project and 						 *
+*   NICT.												 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+
+#include <fdcore-internal.h>
+#include <freeDiameter/version.h>
+
+#ifdef FD_PROJECT_VERSION_HG
+# define VERSION \
+	_stringize(FD_PROJECT_VERSION_MAJOR) "." _stringize(FD_PROJECT_VERSION_MINOR) "." _stringize(FD_PROJECT_VERSION_REV) "-" FD_PROJECT_VERSION_HG_VAL
+#else
+# define VERSION \
+	_stringize(FD_PROJECT_VERSION_MAJOR) "." _stringize(FD_PROJECT_VERSION_MINOR) "." _stringize(FD_PROJECT_VERSION_REV)
+#endif
+
+const char fd_core_version[] = VERSION;
--- a/libfdproto/CMakeLists.txt	Fri May 31 11:19:35 2013 +0800
+++ b/libfdproto/CMakeLists.txt	Fri May 31 11:20:27 2013 +0800
@@ -1,6 +1,7 @@
 # Name of the subproject
 Project("libfdproto" C)
 
+
 # List of source files for the library
 SET(LFDPROTO_SRC
 	fdproto-internal.h
@@ -17,8 +18,10 @@
 	rt_data.c
 	sessions.c
 	utils.c
+	version.c
 	)
 
+
 # Save the list of files for testcases in the core's directory
 SET(LFDPROTO_SRC ${LFDPROTO_SRC} PARENT_SCOPE)
 
@@ -28,6 +31,8 @@
 # Build as a shared library
 ADD_LIBRARY(libfdproto SHARED ${LFDPROTO_SRC})
 
+ADD_DEPENDENCIES(libfdproto version_information)
+
 # Avoid the liblib name, and set the version
 SET_TARGET_PROPERTIES(libfdproto PROPERTIES 
 	OUTPUT_NAME "fdproto"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libfdproto/version.c	Fri May 31 11:20:27 2013 +0800
@@ -0,0 +1,47 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License)                                                               *
+* Author: Sebastien Decugis <sdecugis@freediameter.net>							 *
+*													 *
+* Copyright (c) 2013, WIDE Project and NICT								 *
+* All rights reserved.											 *
+* 													 *
+* Redistribution and use of this software in source and binary forms, with or without modification, are  *
+* permitted provided that the following conditions are met:						 *
+* 													 *
+* * Redistributions of source code must retain the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer.										 *
+*    													 *
+* * Redistributions in binary form must reproduce the above 						 *
+*   copyright notice, this list of conditions and the 							 *
+*   following disclaimer in the documentation and/or other						 *
+*   materials provided with the distribution.								 *
+* 													 *
+* * Neither the name of the WIDE Project or NICT nor the 						 *
+*   names of its contributors may be used to endorse or 						 *
+*   promote products derived from this software without 						 *
+*   specific prior written permission of WIDE Project and 						 *
+*   NICT.												 *
+* 													 *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
+*********************************************************************************************************/
+
+#include "fdproto-internal.h"
+#include <freeDiameter/version.h>
+
+#ifdef FD_PROJECT_VERSION_HG
+# define VERSION \
+	_stringize(FD_PROJECT_VERSION_MAJOR) "." _stringize(FD_PROJECT_VERSION_MINOR) "." _stringize(FD_PROJECT_VERSION_REV) "-" FD_PROJECT_VERSION_HG_VAL
+#else
+# define VERSION \
+	_stringize(FD_PROJECT_VERSION_MAJOR) "." _stringize(FD_PROJECT_VERSION_MINOR) "." _stringize(FD_PROJECT_VERSION_REV)
+#endif
+
+const char fd_libproto_version[] = VERSION;
"Welcome to our mercurial repository"