1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# Script
# wmakePrintBuild
#
# Description
# Print the version used when building the project
#
#------------------------------------------------------------------------------
# Environment defaults
: "${WM_DIR:-$WM_PROJECT_DIR/wmake}"
#--------
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} [OPTION]
options:
-check check the git head commit vs. \$WM_PROJECT_DIR/.build
(exit code 0 for no changes)
-major report \$WM_PROJECT_VERSION only and exit
-update update \$WM_PROJECT_DIR/.build from the git information
-pkg TAG specify packager/release tag ('none' marks an empty packager)
-short report short version information (ie, without pkg tag)
-version VER specify an alternative version
-api report wmake value of OPENFOAM/OPENFOAM_API/OPENFOAM_PLUS
-help
Print the version used when building the project, in this order of precedence:
* the git head commit
* \$WM_PROJECT_DIR/.build
* \$WM_PROJECT_VERSION
USAGE
exit 1
}
# Report error and exit
die()
{
exec 1>&2
echo
echo "Error encountered:"
while [ "$#" -ge 1 ]; do echo " $1"; shift; done
echo
echo "See '${0##*/} -help' for usage"
echo
exit 1
}
#------------------------------------------------------------------------------
cat << WARN_OBSOLETE 1>&2
###############################################################################
## The wmakePrintBuild utility is OBSOLETE (Dec-2018). ##
## The wmakeBuildInfo utility is to be used instead. ##
###############################################################################
WARN_OBSOLETE
#------------------------------------------------------------------------------
# Parse arguments and options
#------------------------------------------------------------------------------
unset checkOnly update package version optApi optShort
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help*)
usage
;;
-c | -check)
checkOnly=true
;;
-major)
echo ${WM_PROJECT_VERSION:-unknown}
exit 0
;;
-u | -update)
update=true
;;
-pkg | -package)
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
# Mark empty as 'none', disallow '!' in string
package=$(echo "${2:-none}" | sed -e 's/!//g')
shift
;;
-short)
optShort=true
;;
-v | -version)
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
version="$2"
shift
;;
-api | -plus)
optApi=true
break
;;
*)
die "unknown option/argument: '$1'"
;;
esac
shift
done
#------------------------------------------------------------------------------
# Persistent build tag
build="$WM_PROJECT_DIR/.build"
#------------------------------------------------------------------------------
# Retrieve old values from the $WM_PROJECT_DIR/.build cache, stored as
# version [packager]
#------------------------------------------------------------------------------
unset oldPackage oldVersion
getOldValues()
{
set -- $(tail -1 $build 2>/dev/null)
oldVersion="$1"
[ "$#" -gt 0 ] && shift
oldPackage="$@"
[ "${oldPackage:-none}" = none ] && unset oldPackage
}
#------------------------------------------------------------------------------
# printTag - output the build tag, reuses the old -package tag if needed
#------------------------------------------------------------------------------
printTag()
{
if [ "${package:-${oldPackage:-none}}" = none ]
then
echo "$version"
else
echo "$version ${package:-$oldPackage}"
fi
}
#------------------------------------------------------------------------------
# Get the version
#------------------------------------------------------------------------------
if [ -n "$optApi" ]
then
# Extract API version from $WM_DIR/rules/General/general
# Any of OPENFOAM=<digits>, OPENFOAM_API=<digits>, OPENFOAM_COM=<digits>
# OPENFOAM_PLUS=<digits>
version=$(
sed -ne 's@^.*OPENFOAM\(_API\|_COM\|_PLUS\)*=\([0-9][0-9]*\).*@\2@p' \
$WM_DIR/rules/General/general 2>/dev/null
)
if [ -n "$version" ]
then
echo "$version"
exit 0
else
echo "no wmake definition for OPENFOAM API" 1>&2
exit 1
fi
elif [ -n "$version" ]
then
# Specified a version - no error possible
rc=0
else
# Abbrev commit hash + data
# Date format (YYMMDD) for authoring of the commit
version="$(git --git-dir=$WM_PROJECT_DIR/.git log -1 --date='format:%y%m%d' --format='%h-%ad' 2>/dev/null)"
test -n "$version"
rc=$?
fi
# Retrieve old values (oldPackage oldVersion)
getOldValues
if [ -n "$optShort" ]
then
unset package oldPackage
fi
#------------------------------------------------------------------------------
# Update persistent build tag if possible
#------------------------------------------------------------------------------
if [ $rc -eq 0 -a -n "$update" ]
then
if [ "$version:$package" != "$oldVersion:$oldPackage" ]
then
if [ -w "$build" -o \( -w "$WM_PROJECT_DIR" -a ! -e "$build" \) ]
then
printTag >| "$build" 2>/dev/null
fi
fi
fi
#------------------------------------------------------------------------------
# Check git vs. persistent build tag
#------------------------------------------------------------------------------
if [ -n "$checkOnly" ]
then
if [ $rc -eq 0 ]
then
test "$version:${package:-$oldPackage}" = "$oldVersion:$oldPackage"
rc=$?
if [ $rc -eq 0 ]
then
echo "same version as previous build" 1>&2
else
echo "version changed from previous build" 1>&2
fi
exit $rc
else
echo "no git description found" 1>&2
exit 0
fi
fi
#------------------------------------------------------------------------------
# Cannot get git information or -version version
#------------------------------------------------------------------------------
if [ $rc -ne 0 ]
then
if [ -n "$oldVersion" ]
then
# Use previous version info
version="$oldVersion"
else
# Fallback to WM_PROJECT_VERSION alone
version="${WM_PROJECT_VERSION:-unknown}"
fi
fi
#------------------------------------------------------------------------------
# Output the tag
#------------------------------------------------------------------------------
printTag
#------------------------------------------------------------------------------
|