2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright held by original author
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 the
14 # Free Software Foundation; either version 2 of the License, or (at your
15 # 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, write to the Free Software Foundation,
24 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 # Print the version used when building the project.
32 #------------------------------------------------------------------------------
36 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
38 usage: $Script [OPTION]
40 -check check the git head commit vs. \$WM_PROJECT_DIR/.build
41 (exit code 0 for no changes)
42 -major report \$WM_PROJECT_VERSION only and exit
43 -update update \$WM_PROJECT_DIR/.build from the git information
44 -version VER specify an alternative version
46 Print the version used when building the project, in this order of precedence:
47 * the git head commit (prefixed with \$WM_PROJECT_VERSION)
48 * \$WM_PROJECT_DIR/.build
49 * \$WM_PROJECT_VERSION
54 #------------------------------------------------------------------------------
56 unset checkOnly update version
70 echo ${WM_PROJECT_VERSION:-unknown}
78 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
83 usage
"unknown option/argument: '$*'"
88 #------------------------------------------------------------------------------
91 # persistent build tag
93 build
="$WM_PROJECT_DIR/.build"
94 previous
=$
(tail -1 $build 2>/dev
/null
)
98 # specified a version - no error possible
101 # get the head SHA1 when building under git
102 # if there are multiple values (eg, HEAD, origin/HEAD, ...)
103 # only take the first one, which is 'HEAD'
104 version
=$
(git show-ref
--hash=12 --head HEAD
2>/dev
/null |
head -1)
108 # mark as success and prefix with WM_PROJECT_VERSION
110 version
="${WM_PROJECT_VERSION}-$version"
118 # update persistent build tag if possible
119 if [ $rc -eq 0 -a -n "$update" -a "$version" != "$previous" ]
121 if [ -w "$build" -o \
( -w "$WM_PROJECT_DIR" -a ! -e "$build" \
) ]
123 echo $version >|
"$build" 2>/dev
/null
128 # check git vs. persistent build tag
129 if [ -n "$checkOnly" ]
133 test "$version" = "$previous"
137 echo "same version as previous build"
139 echo "version changed from previous build"
142 echo "no git description found"
150 # output the git information or the -version version
152 elif [ -n "$previous" ]
154 # use previous build tag
157 # fallback to WM_PROJECT_VERSION alone
158 echo ${WM_PROJECT_VERSION:-unknown}
161 #------------------------------------------------------------------------------