[rtems commit] cpukit: Add a Version API.

Chris Johns chrisj at rtems.org
Fri Nov 10 02:42:49 UTC 2017


Module:    rtems
Branch:    master
Commit:    6f3fb8a547f5700416744a7dc82b3cb83177c7a8
Changeset: http://git.rtems.org/rtems/commit/?id=6f3fb8a547f5700416744a7dc82b3cb83177c7a8

Author:    Chris Johns <chrisj at rtems.org>
Date:      Tue Nov  7 16:43:11 2017 +1100

cpukit: Add a Version API.

Provide functions to get the version string, major, minor and revision
numbers and the version control identifer that is a unique tag for
the version control system.

Update #3199.

---

 cpukit/sapi/Makefile.am                        | 38 ++++++++++++-
 cpukit/sapi/include/rtems/version.h            | 77 ++++++++++++++++++++++++++
 cpukit/sapi/preinstall.am                      |  4 ++
 cpukit/sapi/src/version.c                      | 63 +++++++++++++++++++++
 cpukit/sapi/vc-key.sh                          | 39 +++++++++++++
 cpukit/sapi/version-vc-key.h.in                |  7 +++
 testsuites/sptests/Makefile.am                 |  1 +
 testsuites/sptests/configure.ac                |  1 +
 testsuites/sptests/spversion01/Makefile.am     | 20 +++++++
 testsuites/sptests/spversion01/init.c          | 58 +++++++++++++++++++
 testsuites/sptests/spversion01/spversion01.doc | 24 ++++++++
 testsuites/sptests/spversion01/spversion01.scn | 21 +++++++
 12 files changed, 352 insertions(+), 1 deletion(-)

diff --git a/cpukit/sapi/Makefile.am b/cpukit/sapi/Makefile.am
index 50d065b..a38d863 100644
--- a/cpukit/sapi/Makefile.am
+++ b/cpukit/sapi/Makefile.am
@@ -22,6 +22,7 @@ include_rtems_HEADERS += include/rtems/rbtree.h
 include_rtems_HEADERS += include/rtems/scheduler.h
 include_rtems_HEADERS += include/rtems/timecounter.h
 include_rtems_HEADERS += include/rtems/timespec.h
+include_rtems_HEADERS += include/rtems/version.h
 
 EXTRA_DIST = include/rtems/README
 
@@ -34,7 +35,7 @@ libsapi_a_SOURCES = src/extension.c src/extensioncreate.c \
     src/getversionstring.c \
     src/chainappendnotify.c src/chaingetnotify.c src/chaingetwait.c \
     src/chainprependnotify.c src/rbheap.c src/interrtext.c \
-    src/fatalsrctext.c
+    src/fatalsrctext.c src/version.c
 libsapi_a_SOURCES += src/chainprotected.c
 libsapi_a_SOURCES += src/cpucounterconverter.c
 libsapi_a_SOURCES += src/delayticks.c
@@ -47,5 +48,40 @@ libsapi_a_SOURCES += src/profilingreportxml.c
 libsapi_a_SOURCES += src/tcsimpleinstall.c
 libsapi_a_CPPFLAGS = $(AM_CPPFLAGS)
 
+#
+# Create a new Version VC Key header if the VC state has changed.
+#
+vc_key_stamp = $(am__leading_dot)vc-key-stamp
+
+libsapi_a_CPPFLAGS += -I.
+
+BUILT_SOURCES = version-vc-key.h
+
+.PHONY: $(vc_key_stamp)
+
+$(vc_key_stamp):
+
+version-vc-key.h: $(vc_key_stamp)
+	@+current_vc_key=""; \
+	if test -f $(vc_key_stamp); then \
+	 current_vc_key=`cat $(vc_key_stamp)`; \
+	fi; \
+	vc_key=`$(top_srcdir)/sapi/vc-key.sh $(top_srcdir) $$current_vc_key`; \
+	if test "$$vc_key" != "matches"; then \
+	 echo "Generating version-vc-key.h"; \
+	 if test "$$vc_key" == "release"; then \
+	  vc_header_key="\/\* No version control key found; release\? \*\/"; \
+	 else \
+	  vc_header_key="#define RTEMS_VERSION_VC_KEY \"$$vc_key\""; \
+	 fi; \
+	 cat $(top_srcdir)/sapi/version-vc-key.h.in | \
+	  sed -e "s/@VERSION_VC_KEY@/$$vc_header_key/g" > version-vc-key.h; \
+	 echo "$$vc_key" > $(vc_key_stamp); \
+	fi
+
+version.$(OBJEXT):$ version-vc-key.h
+
+all-local: version-vc-key.h
+
 include $(srcdir)/preinstall.am
 include $(top_srcdir)/automake/local.am
diff --git a/cpukit/sapi/include/rtems/version.h b/cpukit/sapi/include/rtems/version.h
new file mode 100644
index 0000000..b806cb8
--- /dev/null
+++ b/cpukit/sapi/include/rtems/version.h
@@ -0,0 +1,77 @@
+/**
+ * @file
+ *
+ * @brief Version API.
+ */
+
+/*
+ *  Copyright (C) 2017.
+ *  Chris Johns <chrisj at rtems.org>
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.org/license/LICENSE.
+ */
+
+#ifndef _RTEMS_VERSION_H
+#define _RTEMS_VERSION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup ClassicVersion Version
+ *
+ * @ingroup ClassicVersion
+ *
+ * @brief The Version API provides functions to return the version or parts of
+ * the version of RTEMS you are using.
+ */
+/**@{**/
+
+/**
+ * @brief Returns the version string.
+ *
+ * @retval text The version as a string.
+ */
+const char *rtems_version( void );
+
+/**
+ * @brief Returns the version's major number.
+ *
+ * @retval int The version's major number.
+ */
+int rtems_version_major( void );
+
+/**
+ * @brief Returns the version's minor number.
+ *
+ * @retval int The version's minor number.
+ */
+int rtems_version_minor( void );
+
+/**
+ * @brief Returns the version's revision number.
+ *
+ * @retval int The version's revision number.
+ */
+int rtems_version_revision( void );
+
+/**
+ * @brief Returns the version control key for the current version of code that
+ * has been built. The key is specific to the version control system being used
+ * and allows the built version to be identified.
+ *
+ * @retval int The version's version control key.
+ */
+const char *rtems_version_control_key( void );
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/preinstall.am b/cpukit/sapi/preinstall.am
index b1bdf48..a6b0ba3 100644
--- a/cpukit/sapi/preinstall.am
+++ b/cpukit/sapi/preinstall.am
@@ -94,3 +94,7 @@ $(PROJECT_INCLUDE)/rtems/timespec.h: include/rtems/timespec.h $(PROJECT_INCLUDE)
 	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/timespec.h
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/timespec.h
 
+$(PROJECT_INCLUDE)/rtems/version.h: include/rtems/version.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/version.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/version.h
+
diff --git a/cpukit/sapi/src/version.c b/cpukit/sapi/src/version.c
new file mode 100644
index 0000000..d240b1b
--- /dev/null
+++ b/cpukit/sapi/src/version.c
@@ -0,0 +1,63 @@
+/**
+ * @file
+ *
+ * @brief Creates the version strings from the various pieces of version
+ * information. The main version number is part of the build system and is
+ * stamped into rtems/score/cpuopts.h. The version control key string is
+ * extracted from the version control tool when the code is being built and is
+ * updated if it has changed. The key may indicate there are local
+ * modification.
+ *
+ * @ingroup ClassicVersion
+ */
+
+/*
+ *  Copyright (C) 2017.
+ *  Chris Johns <chrisj at rtems.org>
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/version.h>
+
+#include "version-vc-key.h"
+
+const char *rtems_version( void )
+{
+#ifdef RTEMS_VERSION_VC_KEY
+  return RTEMS_VERSION "." RTEMS_VERSION_VC_KEY;
+#else
+  return RTEMS_VERSION;
+#endif
+}
+
+int rtems_version_major( void )
+{
+  return __RTEMS_MAJOR__;
+}
+
+int rtems_version_minor( void )
+{
+  return __RTEMS_MINOR__;
+}
+
+int rtems_version_revision( void )
+{
+  return __RTEMS_REVISION__;
+}
+
+const char *rtems_version_control_key( void )
+{
+#ifdef RTEMS_VERSION_VC_KEY
+  return RTEMS_VERSION_VC_KEY;
+#else
+  return NULL;
+#endif
+}
diff --git a/cpukit/sapi/vc-key.sh b/cpukit/sapi/vc-key.sh
new file mode 100755
index 0000000..c628a1e
--- /dev/null
+++ b/cpukit/sapi/vc-key.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+
+git=$(command -v git)
+
+#
+# Git command not found or not a valid git repo is a release.
+#
+vc_ident="release"
+
+if test $# -ge 1; then
+ repo=$1
+ shift
+ if test -d $repo; then
+  cwd=$(pwd)
+  cd $repo
+  if test -n ${git}; then
+   git rev-parse --git-dir > /dev/null 2>&1
+   if test $? == 0; then
+    git status > /dev/null 2>&1
+    if git diff-index --quiet HEAD --; then
+     modified=""
+    else
+     modified="-modified"
+    fi
+    vc_ident="$(git rev-parse --verify HEAD)${modified}"
+    if test $# -ge 1; then
+     if test "${vc_ident}" == "$1"; then
+      vc_ident="matches"
+     fi
+    fi
+   fi
+  fi
+  cd $cwd
+ fi
+fi
+
+echo ${vc_ident}
+
+exit 0
diff --git a/cpukit/sapi/version-vc-key.h.in b/cpukit/sapi/version-vc-key.h.in
new file mode 100644
index 0000000..738e24d
--- /dev/null
+++ b/cpukit/sapi/version-vc-key.h.in
@@ -0,0 +1,7 @@
+/*
+ * Automatically generated. Do not edit.
+ */
+#if !defined(_RTEMS_VERSION_VC_KEY_H_)
+#define _RTEMS_VERSION_VC_KEY_H_
+ at VERSION_VC_KEY@
+#endif
diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am
index 843116c..e52316a 100644
--- a/testsuites/sptests/Makefile.am
+++ b/testsuites/sptests/Makefile.am
@@ -82,6 +82,7 @@ _SUBDIRS += sptimer_err01 sptimer_err02
 _SUBDIRS += sptimerserver01
 _SUBDIRS += spclock_err02
 _SUBDIRS += spcpuset01
+_SUBDIRS += spversion01
 
 include $(top_srcdir)/../automake/subdirs.am
 include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/sptests/configure.ac b/testsuites/sptests/configure.ac
index aeb9702..0872f67 100644
--- a/testsuites/sptests/configure.ac
+++ b/testsuites/sptests/configure.ac
@@ -253,5 +253,6 @@ spcpuset01/Makefile
 spregion_err01/Makefile
 sppartition_err01/Makefile
 sprmsched01/Makefile
+spversion01/Makefile
 ])
 AC_OUTPUT
diff --git a/testsuites/sptests/spversion01/Makefile.am b/testsuites/sptests/spversion01/Makefile.am
new file mode 100644
index 0000000..0ab6da4
--- /dev/null
+++ b/testsuites/sptests/spversion01/Makefile.am
@@ -0,0 +1,20 @@
+
+rtems_tests_PROGRAMS = spversion01
+spversion01_SOURCES = init.c
+
+dist_rtems_tests_DATA = spversion01.scn spversion01.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(spversion01_OBJECTS)
+LINK_LIBS = $(spversion01_LDLIBS)
+
+spversion01$(EXEEXT): $(spversion01_OBJECTS) $(spversion01_DEPENDENCIES)
+	@rm -f spversion01$(EXEEXT)
+	$(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/sptests/spversion01/init.c b/testsuites/sptests/spversion01/init.c
new file mode 100644
index 0000000..3fc6f0a
--- /dev/null
+++ b/testsuites/sptests/spversion01/init.c
@@ -0,0 +1,58 @@
+/*
+ *  COPYRIGHT (c) 1989-2011.
+ *  On-Line Applications Research Corporation (OAR).
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.org/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/version.h>
+
+#include <tmacros.h>
+
+const char rtems_test_name[] = "VERSION 1";
+
+static rtems_task Init(
+  rtems_task_argument argument
+)
+{
+  TEST_BEGIN();
+
+  printf("Release  : %s\n", rtems_version());
+  printf("Major    : %d\n", rtems_version_major());
+  printf("Minor    : %d\n", rtems_version_minor());
+  printf("Revision : %d\n", rtems_version_revision());
+  printf("VC Key   : %s\n", rtems_version_control_key());
+
+  TEST_END();
+
+  rtems_test_exit(0);
+}
+
+/* configuration information */
+
+#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_EXTRA_TASK_STACKS         (4 * RTEMS_MINIMUM_STACK_SIZE)
+#define CONFIGURE_MAXIMUM_TASKS             2
+
+#define CONFIGURE_DISABLE_SMP_CONFIGURATION
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
+
+/* global variables */
+
+/* end of include file */
diff --git a/testsuites/sptests/spversion01/spversion01.doc b/testsuites/sptests/spversion01/spversion01.doc
new file mode 100644
index 0000000..c0783a4
--- /dev/null
+++ b/testsuites/sptests/spversion01/spversion01.doc
@@ -0,0 +1,24 @@
+#  Copyright (C) 2017
+#  Chris Johns <chrisj at rtems.org>
+#
+#  The license and distribution terms for this file may be
+#  found in the file LICENSE in this distribution or at
+#  http://www.rtems.org/license/LICENSE.
+#
+
+This file describes the directives and concepts tested by this test set.
+
+test set name:  spversion01
+
+directives:
+
+  rtems_version - return the RTEMS version string with VC indent if present.
+  rtems_major - return the RTEMS major version number.
+  rtems_minor - return the RTEMS minor version number.
+  rtems_release - return the RTEMS version release number.
+  rtems_version_control_key - return the RTEMS Version Control (VC) key string.
+
+concepts:
+
++ Ensure the files are correctly generated and the headers can be built and
+  the API is usable.
diff --git a/testsuites/sptests/spversion01/spversion01.scn b/testsuites/sptests/spversion01/spversion01.scn
new file mode 100644
index 0000000..a0f2282
--- /dev/null
+++ b/testsuites/sptests/spversion01/spversion01.scn
@@ -0,0 +1,21 @@
+Valid version control:
+
+*** BEGIN OF TEST VERSION 1 ***
+Release  : 4.11.99.0.d71542c8bef50261bc3904ef6a17f0b6087d04d9-modified
+Major    : 4
+Minor    : 11
+Revision : 99
+VC Key   : d71542c8bef50261bc3904ef6a17f0b6087d04d9-modified
+
+*** END OF TEST VERSION 1 ***
+
+No valid version control:
+
+*** BEGIN OF TEST VERSION 1 ***
+Release  : 4.11.99.0
+Major    : 4
+Minor    : 11
+Revision : 99
+VC Key   : (null)
+
+*** END OF TEST VERSION 1 ***




More information about the vc mailing list