[PATCH] cpukit: Add a Version API.
Chris Johns
chrisj at rtems.org
Tue Nov 7 05:46:44 UTC 2017
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 | 35 +++++++++++-
cpukit/sapi/include/rtems/version.h | 76 ++++++++++++++++++++++++++
cpukit/sapi/preinstall.am | 4 ++
cpukit/sapi/src/version.c | 61 +++++++++++++++++++++
cpukit/sapi/vc-ident.sh | 38 +++++++++++++
cpukit/sapi/version-vc-ident.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, 345 insertions(+), 1 deletion(-)
create mode 100644 cpukit/sapi/include/rtems/version.h
create mode 100644 cpukit/sapi/src/version.c
create mode 100755 cpukit/sapi/vc-ident.sh
create mode 100644 cpukit/sapi/version-vc-ident.h.in
create mode 100644 testsuites/sptests/spversion01/Makefile.am
create mode 100644 testsuites/sptests/spversion01/init.c
create mode 100644 testsuites/sptests/spversion01/spversion01.doc
create mode 100644 testsuites/sptests/spversion01/spversion01.scn
diff --git a/cpukit/sapi/Makefile.am b/cpukit/sapi/Makefile.am
index 50d065be7e..b8cd096b47 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,37 @@ libsapi_a_SOURCES += src/profilingreportxml.c
libsapi_a_SOURCES += src/tcsimpleinstall.c
libsapi_a_CPPFLAGS = $(AM_CPPFLAGS)
+#
+# Create a new Version VC Ident header if the VC state has changed.
+#
+.PHONY: version-vc-ident.h
+
+vc_ident_stamp = $(am__leading_dot)vc-ident-stamp
+
+$(vc_ident_stamp): version-vc-ident.h.in vc-ident.sh
+ @+rm -f $(vc_ident_stamp)
+
+version-vc-ident.h: $(vc_ident_stamp) vc-ident.sh version-vc-ident.h.in
+ @+current_vc_ident=""; \
+ if test -f $(vc_ident_stamp); then \
+ current_vc_ident=`cat $(vc_ident_stamp)`; \
+ fi; \
+ vc_ident=`$(top_srcdir)/sapi/vc-ident.sh $(top_srcdir) $$current_vc_ident`; \
+ if test "$$vc_ident" != "matches"; then \
+ echo "Generating version-vc-ident.h"; \
+ if test "$$vc_ident" == "release"; then \
+ vc_ident="\/\* No version control found; release\? \*\/"; \
+ else \
+ vc_ident="#define RTEMS_VERSION_VC_IDENT \"$$vc_ident\""; \
+ fi; \
+ cat $(top_srcdir)/sapi/version-vc-ident.h.in | \
+ sed -e "s/@VERSION_VC_IDENT@/$$vc_ident/g" > ../version-vc-ident.h; \
+ echo "$$vc_ident" > $(vc_ident_stamp); \
+ fi
+
+all-local: version-vc-ident.h
+
+src/version.c: version-vc-ident.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 0000000000..d9fe4d9eff
--- /dev/null
+++ b/cpukit/sapi/include/rtems/version.h
@@ -0,0 +1,76 @@
+/**
+ * @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's VC ident. This is specific to the VC being
+ * used.
+ *
+ * @retval int The version's VC ident.
+ */
+const char *rtems_version_vc_ident( void );
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/preinstall.am b/cpukit/sapi/preinstall.am
index b1bdf48ac2..a6b0ba30df 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 0000000000..7c1d15b832
--- /dev/null
+++ b/cpukit/sapi/src/version.c
@@ -0,0 +1,61 @@
+/**
+ * @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 VC string is extracted from the VC
+ * tool when the code is being built and updated if it has changed.
+ *
+ * @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-ident.h"
+
+const char *rtems_version( void )
+{
+#ifdef RTEMS_VERSION_VC_IDENT
+ return RTEMS_VERSION "." RTEMS_VERSION_VC_IDENT;
+#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_vc_ident( void )
+{
+#ifdef RTEMS_VERSION_VC_IDENT
+ return RTEMS_VERSION_VC_IDENT;
+#else
+ return NULL;
+#endif
+}
diff --git a/cpukit/sapi/vc-ident.sh b/cpukit/sapi/vc-ident.sh
new file mode 100755
index 0000000000..7c0b3f992b
--- /dev/null
+++ b/cpukit/sapi/vc-ident.sh
@@ -0,0 +1,38 @@
+#! /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
+ 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-ident.h.in b/cpukit/sapi/version-vc-ident.h.in
new file mode 100644
index 0000000000..d2c3b2e820
--- /dev/null
+++ b/cpukit/sapi/version-vc-ident.h.in
@@ -0,0 +1,7 @@
+/*
+ * Automatically generated. Do not edit.
+ */
+#if !defined(_RTEMS_VERSION_VC_IDENT_H_)
+#define _RTEMS_VERSION_VC_IDENT_H_
+ at VERSION_VC_IDENT@
+#endif
diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am
index f02d277142..d068a50aa3 100644
--- a/testsuites/sptests/Makefile.am
+++ b/testsuites/sptests/Makefile.am
@@ -81,6 +81,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 8ecd9b75f1..cca94ebfe5 100644
--- a/testsuites/sptests/configure.ac
+++ b/testsuites/sptests/configure.ac
@@ -252,5 +252,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 0000000000..0ab6da4756
--- /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 0000000000..a5cd4febea
--- /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 Ident : %s\n", rtems_version_vc_ident());
+
+ 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 0000000000..5c82a933dc
--- /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_vc_ident - return the RTEMS Version Control (VC) indent 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 0000000000..092a5924e0
--- /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 Ident : 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 Ident : (null)
+
+*** END OF TEST VERSION 1 ***
--
2.13.2
More information about the devel
mailing list