Merged in david_alessio/nuttx/feature/add-git-revision (pull request #1020)
report git info on /proc/gitrev * report git info on /proc/gitrev git info reported: branch, version, git hash, hostname, usr, build date * use existing .version and procfs for git info * reduce script's coupling Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
parent
3806a01c5d
commit
a0867a7f4f
@ -220,15 +220,23 @@ static ssize_t version_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
|
|
||||||
if (filep->f_pos == 0)
|
if (filep->f_pos == 0)
|
||||||
{
|
{
|
||||||
#if defined(__DATE__) && defined(__TIME__)
|
#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);
|
||||||
|
#else
|
||||||
|
# if defined(__DATE__) && defined(__TIME__)
|
||||||
linesize = snprintf(attr->line, VERSION_LINELEN,
|
linesize = snprintf(attr->line, VERSION_LINELEN,
|
||||||
"NuttX version %s %s %s %s\n",
|
"NuttX version %s %s %s %s\n",
|
||||||
CONFIG_VERSION_STRING, CONFIG_VERSION_BUILD,
|
CONFIG_VERSION_STRING, CONFIG_VERSION_BUILD,
|
||||||
__DATE__, __TIME__);
|
__DATE__, __TIME__);
|
||||||
#else
|
# else
|
||||||
linesize = snprintf(attr->line, VERSION_LINELEN,
|
linesize = snprintf(attr->line, VERSION_LINELEN,
|
||||||
"NuttX version %s %s\n",
|
"NuttX version %s %s\n",
|
||||||
CONFIG_VERSION_STRING, CONFIG_VERSION_BUILD);
|
CONFIG_VERSION_STRING, CONFIG_VERSION_BUILD);
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Save the linesize in case we are re-entered with f_pos > 0 */
|
/* Save the linesize in case we are re-entered with f_pos > 0 */
|
||||||
|
@ -182,8 +182,8 @@ endif
|
|||||||
NUTTXNAME = nuttx
|
NUTTXNAME = nuttx
|
||||||
BIN = $(NUTTXNAME)$(EXEEXT)
|
BIN = $(NUTTXNAME)$(EXEEXT)
|
||||||
|
|
||||||
all: $(BIN)
|
all: version_info $(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
|
.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
|
||||||
|
|
||||||
# Target used to copy include/nuttx/lib/math.h. If CONFIG_ARCH_MATH_H is
|
# Target used to copy include/nuttx/lib/math.h. If CONFIG_ARCH_MATH_H is
|
||||||
# defined, then there is an architecture specific math.h header file
|
# defined, then there is an architecture specific math.h header file
|
||||||
@ -260,15 +260,21 @@ endif
|
|||||||
tools/mkversion$(HOSTEXEEXT):
|
tools/mkversion$(HOSTEXEEXT):
|
||||||
$(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkversion$(HOSTEXEEXT)
|
$(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkversion$(HOSTEXEEXT)
|
||||||
|
|
||||||
|
# create .version iff it doesn't already exist. Note: it may have been
|
||||||
|
# created manually and may contain other info
|
||||||
$(TOPDIR)/.version:
|
$(TOPDIR)/.version:
|
||||||
$(Q) if [ ! -f .version ]; then \
|
$(Q) echo "No .version file found, creating one"
|
||||||
echo "No .version file found, creating one"; \
|
$(Q) tools/version.sh -v 0.0 -b 0 .version
|
||||||
tools/version.sh -v 0.0 -b 0 .version; \
|
$(Q) chmod 755 .version
|
||||||
chmod 755 .version; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
include/nuttx/version.h: $(TOPDIR)/.version tools/mkversion$(HOSTEXEEXT)
|
# version_info will add git-specific info to the .version file
|
||||||
$(Q) tools/mkversion $(TOPDIR) > include/nuttx/version.h
|
# which must already exist. First strip out any existing CONFIG_GIT_ info
|
||||||
|
version_info: $(TOPDIR)/.version
|
||||||
|
$(Q) sed -i '/CONFIG_GIT_/d' $<
|
||||||
|
$(Q) tools/gen_gitrev.sh -t $(TOPDIR) >> $<
|
||||||
|
|
||||||
|
include/nuttx/version.h: $(TOPDIR)/.version tools/mkversion$(HOSTEXEEXT) version_info
|
||||||
|
$(Q) tools/mkversion $(TOPDIR) > $@
|
||||||
|
|
||||||
# Targets used to build include/nuttx/config.h. Creation of config.h is
|
# Targets used to build include/nuttx/config.h. Creation of config.h is
|
||||||
# part of the overall NuttX configuration sequence. Notice that the
|
# part of the overall NuttX configuration sequence. Notice that the
|
||||||
|
203
tools/gen_gitrev.sh
Executable file
203
tools/gen_gitrev.sh
Executable file
@ -0,0 +1,203 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
|
case $OSTYPE in
|
||||||
|
linux-gnu|netbsd|darwin*)
|
||||||
|
declare DATE=/bin/date
|
||||||
|
declare HOSTNAME=/bin/hostname
|
||||||
|
;;
|
||||||
|
cygwin)
|
||||||
|
declare DATE=/usr/bin/date
|
||||||
|
declare HOSTNAME=/usr/bin/hostname
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
declare DATE=/bin/date
|
||||||
|
declare HOSTNAME=/bin/hostname
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
#
|
||||||
|
# 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:
|
||||||
|
#
|
||||||
|
define git_info <<EOT
|
||||||
|
CONFIG_GIT_REVISION_STR="$GIT_REVISION_STR"
|
||||||
|
EOT
|
||||||
|
|
||||||
|
echo "$git_info"
|
Loading…
Reference in New Issue
Block a user