2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
8 #-------------------------------------------------------------------------------
10 # This file is part of OpenFOAM.
12 # OpenFOAM is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 # You should have received a copy of the GNU General Public License
23 # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
29 # Print the version used when building the project
31 #------------------------------------------------------------------------------
32 # persistent build tag
33 build
="$WM_PROJECT_DIR/.build"
38 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
40 usage: ${0##*/} [OPTION]
42 -check check the git head commit vs. \$WM_PROJECT_DIR/.build
43 (exit code 0 for no changes)
44 -major report \$WM_PROJECT_VERSION only and exit
45 -update update \$WM_PROJECT_DIR/.build from the git information
46 -pkg TAG specify packager/release tag ('none' marks an empty packager)
47 -short report short version information (ie, without pkg tag)
48 -version VER specify an alternative version
50 Print the version used when building the project, in this order of precedence:
51 * the git head commit (prefixed with \$WM_PROJECT_VERSION)
52 * \$WM_PROJECT_DIR/.build
53 * \$WM_PROJECT_VERSION
58 #------------------------------------------------------------------------------
60 unset checkOnly update package version shortOpt
74 echo ${WM_PROJECT_VERSION:-unknown}
82 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
83 # mark empty as 'none', disallow '!' in string
84 package
=$
(echo "${2:-none}" |
sed -e 's/!//g')
92 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
97 usage
"unknown option/argument: '$*'"
102 #------------------------------------------------------------------------------
105 # retrieve old values from the $WM_PROJECT_DIR/.build cache, stored as
108 unset oldPackage oldVersion
111 set -- $
(tail -1 $build 2>/dev
/null
)
113 [ "$#" -gt 0 ] && shift
115 [ "${oldPackage:-none}" = none
] && unset oldPackage
119 # printTag - output the build tag
120 # reuses the old -package tag if needed
124 if [ "${package:-${oldPackage:-none}}" = none
]
128 echo "$version ${package:-$oldPackage}"
136 # specified a version - no error possible
139 # get the head SHA1 when building under git
140 # if there are multiple values (eg, HEAD, origin/HEAD, ...)
141 # only take the first one, which is 'HEAD'
143 cd $WM_PROJECT_DIR 2>/dev
/null
&& \
144 git show-ref
--hash=12 --head HEAD
2>/dev
/null |
head -1
149 # mark as success and prefix with WM_PROJECT_VERSION
151 version
="${WM_PROJECT_VERSION}-$version"
159 # retrieve old values
162 if [ "$shortOpt" = true
]
164 unset package oldPackage
168 # update persistent build tag if possible
170 if [ $rc -eq 0 -a -n "$update" ]
172 if [ "$version:$package" != "$oldVersion:$oldPackage" ]
174 if [ -w "$build" -o \
( -w "$WM_PROJECT_DIR" -a ! -e "$build" \
) ]
176 printTag
>|
"$build" 2>/dev
/null
185 # oldVersion='$oldVersion'
186 # oldPackage='$oldPackage'
190 # check git vs. persistent build tag
191 if [ -n "$checkOnly" ]
195 test "$version:${package:-$oldPackage}" = "$oldVersion:$oldPackage"
199 echo "same version as previous build" 1>&2
201 echo "version changed from previous build" 1>&2
204 echo "no git description found" 1>&2
211 # cannot get git information or -version version
215 if [ -n "$oldVersion" ]
217 # use previous version info
218 version
="$oldVersion"
220 # fallback to WM_PROJECT_VERSION alone
221 version
="${WM_PROJECT_VERSION:-unknown}"
229 #------------------------------------------------------------------------------