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
|
|
|
#
|
2021-02-18 13:48:10 +01:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership. The
|
|
|
|
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
# "License"); you may not use this file except in compliance with the
|
|
|
|
# License. You may obtain a copy of the License at
|
2011-04-14 18:46:17 +02:00
|
|
|
#
|
2021-02-18 13:48:10 +01:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-14 18:46:17 +02:00
|
|
|
#
|
2021-02-18 13:48:10 +01:00
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
2011-04-14 18:46:17 +02:00
|
|
|
#
|
|
|
|
|
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
|
2021-07-13 05:25:19 +02:00
|
|
|
VERSION=`git -C ${WD} describe --match "nuttx-*" 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
|
2022-12-20 05:10:08 +01:00
|
|
|
VERSION=`git -C ${WD} -c 'versionsort.suffix=-' tag --sort=v:refname 2>/dev/null | 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
|
2021-02-26 04:21:07 +01:00
|
|
|
echo "Missing versioning information. Using the dummy value. (0.0.0)"
|
|
|
|
VERSION="0.0.0"
|
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
|
2021-03-18 05:54:33 +01:00
|
|
|
PATCH=`echo ${VERSION} | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+" | 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
|
2022-12-20 05:10:08 +01:00
|
|
|
BUILD=`git -C ${WD} log --oneline -1 2>/dev/null | cut -d' ' -f1`
|
2020-01-05 17:29:59 +01:00
|
|
|
if [ -z "${BUILD}" ]; then
|
|
|
|
echo "GIT version information is not available"
|
|
|
|
fi
|
2022-12-20 05:10:08 +01:00
|
|
|
if [ -n "`git -C ${WD} diff-index --name-only HEAD 2>/dev/null | 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}
|