2019-08-10 17:57:26 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-01-19 18:03:11 +01:00
|
|
|
# tools/version.sh
|
2011-04-14 18:46:17 +02:00
|
|
|
#
|
2019-09-07 17:14:21 +02:00
|
|
|
# Copyright (C) 2011, 2019 Gregory Nutt. All rights reserved.
|
2012-09-13 20:32:24 +02:00
|
|
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
2011-04-14 18:46:17 +02:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
2020-06-23 00:33:43 +02:00
|
|
|
WD=$(dirname $0)
|
2011-04-14 18:46:17 +02:00
|
|
|
|
|
|
|
# Get command line parameters
|
|
|
|
|
2020-04-18 20:47:04 +02:00
|
|
|
USAGE="USAGE: $0 [-d|-h] [-b <build>] [-v <major.minor.patch>] <outfile-path>"
|
2011-04-14 18:46:17 +02:00
|
|
|
ADVICE="Try '$0 -h' for more information"
|
|
|
|
|
|
|
|
unset VERSION
|
|
|
|
unset BUILD
|
|
|
|
unset OUTFILE
|
|
|
|
|
2014-04-14 00:22:22 +02:00
|
|
|
while [ ! -z "$1" ]; do
|
2020-01-05 17:29:59 +01:00
|
|
|
case $1 in
|
|
|
|
-b )
|
|
|
|
shift
|
|
|
|
BUILD=$1
|
|
|
|
;;
|
|
|
|
-d )
|
|
|
|
set -x
|
|
|
|
;;
|
|
|
|
-v )
|
|
|
|
shift
|
|
|
|
VERSION=$1
|
|
|
|
;;
|
|
|
|
-h )
|
|
|
|
echo "$0 is a tool for generation of proper version files for the NuttX build"
|
|
|
|
echo ""
|
|
|
|
echo $USAGE
|
|
|
|
echo ""
|
|
|
|
echo "Where:"
|
|
|
|
echo " -b <build>"
|
|
|
|
echo " Use this build identification string. Default: use GIT build ID"
|
|
|
|
echo " NOTE: GIT build information may not be available in a snapshot"
|
|
|
|
echo " -d"
|
|
|
|
echo " Enable script debug"
|
|
|
|
echo " -h"
|
|
|
|
echo " show this help message and exit"
|
2020-04-18 20:47:04 +02:00
|
|
|
echo " -v <major.minor.patch>"
|
|
|
|
echo " The NuttX version number expressed as a major, minor and patch"
|
2020-12-12 16:26:15 +01:00
|
|
|
echo " number separated by a period"
|
2020-01-05 17:29:59 +01:00
|
|
|
echo " <outfile-path>"
|
|
|
|
echo " The full path to the version file to be created"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
* )
|
2020-03-21 14:23:44 +01:00
|
|
|
break
|
2020-01-05 17:29:59 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2011-04-14 18:46:17 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
OUTFILE=$1
|
|
|
|
|
2019-12-12 18:17:11 +01:00
|
|
|
if [ -z ${VERSION} ] ; then
|
2020-12-17 10:57:35 +01:00
|
|
|
VERSION=`git -C ${WD} describe 2>/dev/null | tail -1 | cut -d'-' -f2`
|
2020-04-18 20:47:04 +02:00
|
|
|
|
2020-12-18 02:28:33 +01:00
|
|
|
# If the VERSION does not match X.Y.Z, retrieve version from the tag
|
|
|
|
|
|
|
|
if [[ ! ${VERSION} =~ ([0-9]+)\.([0-9]+)\.([0-9]+) ]] ; then
|
2021-01-03 08:37:39 +01:00
|
|
|
VERSION=`git -C ${WD} tag --sort=v:refname | grep -E "nuttx-[0-9]+\.[0-9]+\.[0-9]+" | tail -1 | cut -d'-' -f2`
|
2020-04-18 20:47:04 +02:00
|
|
|
fi
|
2020-12-18 02:28:33 +01:00
|
|
|
|
2019-12-12 18:17:11 +01:00
|
|
|
fi
|
|
|
|
|
2011-04-14 18:46:17 +02:00
|
|
|
# Make sure we know what is going on
|
|
|
|
|
|
|
|
if [ -z ${VERSION} ] ; then
|
2020-01-05 17:29:59 +01:00
|
|
|
echo "Missing versioning information"
|
|
|
|
echo $USAGE
|
|
|
|
echo $ADVICE
|
|
|
|
exit 1
|
2011-04-14 18:46:17 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z ${OUTFILE} ] ; then
|
2020-01-05 17:29:59 +01:00
|
|
|
echo "Missing path to the output file"
|
|
|
|
echo $USAGE
|
|
|
|
echo $ADVICE
|
2020-04-18 20:47:04 +02:00
|
|
|
exit 2
|
2011-04-14 18:46:17 +02:00
|
|
|
fi
|
|
|
|
|
2020-04-18 20:47:04 +02:00
|
|
|
# Get the major, minor and patch version numbers
|
2011-04-14 18:46:17 +02:00
|
|
|
|
|
|
|
MAJOR=`echo ${VERSION} | cut -d'.' -f1`
|
|
|
|
if [ "X${MAJOR}" = "X${VERSION}" ]; then
|
2020-01-05 17:29:59 +01:00
|
|
|
echo "Missing minor version number"
|
|
|
|
echo $USAGE
|
|
|
|
echo $ADVICE
|
2020-04-18 20:47:04 +02:00
|
|
|
exit 3
|
2011-04-14 18:46:17 +02:00
|
|
|
fi
|
2020-04-18 20:47:04 +02:00
|
|
|
|
2011-04-14 18:46:17 +02:00
|
|
|
MINOR=`echo ${VERSION} | cut -d'.' -f2`
|
2020-04-18 20:47:04 +02:00
|
|
|
if [ "X${MAJOR}.${MINOR}" = "X${VERSION}" ]; then
|
|
|
|
echo "Missing patch version number"
|
|
|
|
echo $USAGE
|
|
|
|
echo $ADVICE
|
|
|
|
exit 4
|
|
|
|
fi
|
|
|
|
PATCH=`echo ${VERSION} | cut -d'.' -f3`
|
2011-04-14 18:46:17 +02:00
|
|
|
|
2013-04-20 02:35:06 +02:00
|
|
|
# Get GIT information (if not provided on the command line)
|
2011-04-14 18:46:17 +02:00
|
|
|
|
|
|
|
if [ -z "${BUILD}" ]; then
|
2020-06-23 00:33:43 +02:00
|
|
|
BUILD=`git -C ${WD} log --oneline -1 | cut -d' ' -f1 2>/dev/null`
|
2020-01-05 17:29:59 +01:00
|
|
|
if [ -z "${BUILD}" ]; then
|
|
|
|
echo "GIT version information is not available"
|
2020-04-18 20:47:04 +02:00
|
|
|
exit 5
|
2020-01-05 17:29:59 +01:00
|
|
|
fi
|
2020-06-23 00:33:43 +02:00
|
|
|
if [ -n "`git -C ${WD} diff-index --name-only HEAD | head -1`" ]; then
|
2020-01-05 17:29:59 +01:00
|
|
|
BUILD=${BUILD}-dirty
|
|
|
|
fi
|
2011-04-14 18:46:17 +02:00
|
|
|
fi
|
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
# Write a version file into the NuttX directory. The syntax of file is such that it
|
2011-04-14 18:46:17 +02:00
|
|
|
# may be sourced by a bash script or included by a Makefile.
|
|
|
|
|
|
|
|
echo "#!/bin/bash" >${OUTFILE}
|
|
|
|
echo "" >>${OUTFILE}
|
2019-12-12 18:17:11 +01:00
|
|
|
echo "CONFIG_VERSION_STRING=\"${VERSION}\"" >>${OUTFILE}
|
2011-04-14 18:46:17 +02:00
|
|
|
echo "CONFIG_VERSION_MAJOR=${MAJOR}" >>${OUTFILE}
|
|
|
|
echo "CONFIG_VERSION_MINOR=${MINOR}" >>${OUTFILE}
|
2020-04-18 20:47:04 +02:00
|
|
|
echo "CONFIG_VERSION_PATCH=${PATCH}" >>${OUTFILE}
|
2013-05-01 17:21:13 +02:00
|
|
|
echo "CONFIG_VERSION_BUILD=\"${BUILD}\"" >>${OUTFILE}
|