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.
This commit is contained in:
Chris Johns
2017-11-10 13:34:06 +11:00
parent 748a12629a
commit 6f3fb8a547
12 changed files with 352 additions and 1 deletions
+37 -1
View File
@@ -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
+77
View File
@@ -0,0 +1,77 @@
/**
* @file
*
* @brief Version API.
*/
/*
* Copyright (C) 2017.
* Chris Johns <chrisj@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 */
+4
View File
@@ -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
+63
View File
@@ -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@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
}
+39
View File
@@ -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
+7
View File
@@ -0,0 +1,7 @@
/*
* Automatically generated. Do not edit.
*/
#if !defined(_RTEMS_VERSION_VC_KEY_H_)
#define _RTEMS_VERSION_VC_KEY_H_
@VERSION_VC_KEY@
#endif
+1
View File
@@ -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
+1
View File
@@ -253,5 +253,6 @@ spcpuset01/Makefile
spregion_err01/Makefile
sppartition_err01/Makefile
sprmsched01/Makefile
spversion01/Makefile
])
AC_OUTPUT
@@ -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@.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
+58
View File
@@ -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 */
@@ -0,0 +1,24 @@
# Copyright (C) 2017
# Chris Johns <chrisj@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.
@@ -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 ***