tools/ and fs/procfs: Simplify .version file generation

1.merge CONFIG_GIT_REVISION_STR into CONFIG_VERSION_BUILD
2.merge gen_getrev.sh into version.sh
3.generate version number if needed

Here is a sample output:
nsh> uname -a
NuttX  8.2 59fd8e12d3-dirty Dec 12 2019 15:48:00 sim sim
nsh> cat /proc/version
NuttX version 8.2 59fd8e12d3-dirty Dec 12 2019 15:48:01
This commit is contained in:
anchao 2019-12-12 11:17:11 -06:00 committed by Gregory Nutt
parent 1d60bc20a9
commit 1c91aec6ae
5 changed files with 13 additions and 234 deletions

View File

@ -220,13 +220,7 @@ static ssize_t version_read(FAR struct file *filep, FAR char *buffer,
if (filep->f_pos == 0)
{
#ifdef CONFIG_GIT_REVISION_STR
linesize = snprintf(attr->line, VERSION_LINELEN,
"NuttX version %s %s\n"
"%s\n",
CONFIG_VERSION_STRING, CONFIG_VERSION_BUILD,
CONFIG_GIT_REVISION_STR);
#elif defined(__DATE__) && defined(__TIME__)
#if defined(__DATE__) && defined(__TIME__)
linesize = snprintf(attr->line, VERSION_LINELEN,
"NuttX version %s %s %s %s\n",
CONFIG_VERSION_STRING, CONFIG_VERSION_BUILD,

View File

@ -36,17 +36,9 @@
TOPDIR := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/.version
include $(TOPDIR)/tools/Config.mk
-include $(TOPDIR)/Make.defs
# In case .version file does not exist
CONFIG_VERSION_STRING ?= "Unversioned"
CONFIG_VERSION_MAJOR ?= 0
CONFIG_VERSION_MINOR ?= 0
CONFIG_VERSION_BUILD ?= "0"
# Control build verbosity
#
# V=1,2: Enable echo of commands
@ -187,7 +179,7 @@ NUTTXNAME = nuttx
BIN = $(NUTTXNAME)$(EXEEXT)
all: $(BIN)
.PHONY: dirlinks context clean_context check_context config oldconfig menuconfig nconfig qconfig gconfig export subdir_clean clean subdir_distclean distclean apps_clean apps_distclean version_info
.PHONY: dirlinks context clean_context check_context config oldconfig menuconfig nconfig qconfig gconfig export subdir_clean clean subdir_distclean distclean apps_clean apps_distclean
ifeq ($(GIT_DIR),y)
.PHONY: $(TOPDIR)/.version
endif
@ -271,10 +263,7 @@ tools/mkversion$(HOSTEXEEXT):
$(TOPDIR)/.version:
$(Q) echo "Create .version"
$(Q) tools/version.sh -s $(CONFIG_VERSION_STRING) -v $(CONFIG_VERSION_MAJOR).$(CONFIG_VERSION_MINOR) -b $(CONFIG_VERSION_BUILD) .version
ifeq ($(GIT_DIR),y)
$(Q) tools/gen_gitrev.sh -t $(TOPDIR) >> .version
endif
$(Q) tools/version.sh .version
$(Q) chmod 755 .version
include/nuttx/version.h: $(TOPDIR)/.version tools/mkversion$(HOSTEXEEXT)

View File

@ -78,13 +78,6 @@ discover.py
Example script for discovering devices in the local network.
It is the counter part to apps/netutils/discover
gen_getrev.sh
-------------
Creates a GIT revision string and echos the string to stdout. This is
used by the top-level Makefile to generate part of the information in
the .version file.
gencromfs.c
-----------

View File

@ -1,188 +0,0 @@
#!/usr/bin/env bash
###########################################################################
#
# Copyright 2017, 2018, 2019 David S. Alessio, All rights reserved.
# Author: David S. Alessio <david.s.alessio@gmail.com>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. 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.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# 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.
#
###########################################################################
#
# This bash script queries the git repo for info/status
# and generates a header file with version info #defs
#
# Date : 25-Aug-2019
###########################################################################
#
# Global Vars
#
# full pathname to utils used
declare WHO=/usr/bin/whoami
declare GIT=/usr/bin/git
declare TR=/usr/bin/tr
declare WC=/usr/bin/wc
declare DATE=date
declare HOSTNAME=hostname
###########################################################################
#
# define -- helper function to define vars with HEREDOC
#
define() { IFS='\n' read -r -d '' ${1} || true; }
###########################################################################
#
# usage
#
usage() {
define usage_str <<EOT
Usage: $0 [option...]
-f <fname> version info filename
-t <dir> top directory
-h show usage
-v increase verbosity
EOT
echo "$usage_str" >&2
exit 1
}
###########################################################################
#
# parse args
#
declare -i verbosity=0
declare TOP_DIR=
while getopts ":ht:v" opt; do
case $opt in
h) usage
;;
t) TOP_DIR=$OPTARG
;;
v) verbosity=$(($verbosity+1))
;;
\?) echo "Invalid option: -$OPTARG" >&2
usage
;;
:) echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
shift $((OPTIND-1))
[[ $OPTIND -gt 1 ]] || usage
if [[ -z "$TOP_DIR" ]]; then
echo "@@@"
echo "@@@ TOP DIR not specified"
echo "@@@ Exiting with Error!"
echo "@@@"
exit 1
fi
# bail out if .git directory doesn't exist
[[ -d $TOP_DIR/.git ]] || exit 0
###########################################################################
#
# Git info vars
#
declare BUILD_DATE=`$DATE +"%a %d-%b-%Y %T %Z" | $TR -d '\n'`
declare BUILD_MACH=`$HOSTNAME | $TR -d '\n'`
declare BUILD_USER=`$WHO`
declare GIT_BRANCH=`$GIT rev-parse --abbrev-ref HEAD`
declare GIT_FW_DESCR=`$GIT describe --long --tags --dirty='+' --always`
declare GIT_SHORT_HASH=`$GIT rev-parse --short HEAD`
# Create the git revision string
declare GIT_REVISION_STR="$GIT_FW_DESCR, $GIT_BRANCH, $BUILD_MACH/$BUILD_USER, $BUILD_DATE"
###########################################################################
#
# Dump vars to stderr
#
show_vars() {
define vars <<EOT
Branch : $GIT_BRANCH
Hash : $GIT_SHORT_HASH
Build Machine : $BUILD_MACH
Build User : $BUILD_USER
Build Date : $BUILD_DATE
FW Version : $GIT_FW_DESCR
Git Rev str : $GIT_REVISION_STR
EOT
echo "$vars" >&2
}
if [[ verbosity -ge 1 ]]; then
show_vars
fi
###########################################################################
#
# update .version file with the following:
#
echo "CONFIG_GIT_REVISION_STR=\"$GIT_REVISION_STR\""

View File

@ -36,13 +36,12 @@ WD=`pwd`
# Get command line parameters
USAGE="USAGE: $0 [-d|-h] [-b <build>] [-s <version-string>] -v <major.minor> <outfile-path>"
USAGE="USAGE: $0 [-d|-h] [-b <build>] [-v <major.minor>] <outfile-path>"
ADVICE="Try '$0 -h' for more information"
unset VERSION
unset BUILD
unset OUTFILE
unset VERSION_STRING
while [ ! -z "$1" ]; do
case $1 in
@ -53,10 +52,6 @@ while [ ! -z "$1" ]; do
-d )
set -x
;;
-s )
shift
VERSION_STRING=$1
;;
-v )
shift
VERSION=$1
@ -90,6 +85,10 @@ done
OUTFILE=$1
if [ -z ${VERSION} ] ; then
VERSION=`git tag --sort=taggerdate | tail -1 | cut -d'-' -f2`
fi
# Make sure we know what is going on
if [ -z ${VERSION} ] ; then
@ -106,12 +105,6 @@ if [ -z ${OUTFILE} ] ; then
exit 1
fi
# If the version string was not provided, then set it to the version
if [ -z "${VERSION_STRING}" ]; then
VERSION_STRING=${VERSION}
fi
# Get the major and minor version numbers
MAJOR=`echo ${VERSION} | cut -d'.' -f1`
@ -126,15 +119,13 @@ MINOR=`echo ${VERSION} | cut -d'.' -f2`
# Get GIT information (if not provided on the command line)
if [ -z "${BUILD}" ]; then
GITINFO=`git log 2>/dev/null | head -1`
if [ -z "${GITINFO}" ]; then
BUILD=`git log --oneline -1 | cut -d' ' -f1 2>/dev/null`
if [ -z "${BUILD}" ]; then
echo "GIT version information is not available"
exit 3
fi
BUILD=`echo ${GITINFO} | cut -d' ' -f2`
if [ -z "${BUILD}" ]; then
echo "GIT build information not found"
exit 4
if [ -n "`git diff-index --name-only HEAD | head -1`" ]; then
BUILD=${BUILD}-dirty
fi
fi
@ -143,7 +134,7 @@ fi
echo "#!/bin/bash" >${OUTFILE}
echo "" >>${OUTFILE}
echo "CONFIG_VERSION_STRING=\"${VERSION_STRING}\"" >>${OUTFILE}
echo "CONFIG_VERSION_STRING=\"${VERSION}\"" >>${OUTFILE}
echo "CONFIG_VERSION_MAJOR=${MAJOR}" >>${OUTFILE}
echo "CONFIG_VERSION_MINOR=${MINOR}" >>${OUTFILE}
echo "CONFIG_VERSION_BUILD=\"${BUILD}\"" >>${OUTFILE}