2 #------------------------------------------------------------------------------
4 # \\ / F ield | foam-extend: Open Source CFD
5 # \\ / O peration | Version: 3.2
6 # \\ / A nd | Web: http://www.foam-extend.org
7 # \\/ M anipulation | For copyright notice see file Copyright
8 #------------------------------------------------------------------------------
10 # This file is part of foam-extend.
12 # foam-extend 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 3 of the License, or (at your
15 # option) any later version.
17 # foam-extend is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
29 # Print the version used when building the project.
31 #------------------------------------------------------------------------------
35 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
37 usage: $Script [OPTION]
39 -check check the git head commit vs. \$WM_PROJECT_DIR/.build
40 (exit code 0 for no changes)
41 -major report \$WM_PROJECT_VERSION only and exit
42 -update update \$WM_PROJECT_DIR/.build from the git information
43 -version VER specify an alternative version
45 Print the version used when building the project, in this order of precedence:
46 * the git head commit (prefixed with \$WM_PROJECT_VERSION)
47 * \$WM_PROJECT_DIR/.build
48 * \$WM_PROJECT_VERSION
53 #------------------------------------------------------------------------------
55 unset checkOnly update version
69 echo ${WM_PROJECT_VERSION:-unknown}
77 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
82 usage
"unknown option/argument: '$*'"
87 #------------------------------------------------------------------------------
90 # persistent build tag
92 build
="$WM_PROJECT_DIR/.build"
93 previous
=$
(tail -1 $build 2>/dev
/null
)
97 # specified a version - no error possible
100 # get the head SHA1 when building under git
101 # if there are multiple values (eg, HEAD, origin/HEAD, ...)
102 # only take the first one, which is 'HEAD'
103 version
=$
(git show-ref
--hash=12 --head HEAD
2>/dev
/null |
head -1)
107 # mark as success and prefix with WM_PROJECT_VERSION
109 version
="${WM_PROJECT_VERSION}-$version"
117 # update persistent build tag if possible
118 if [ $rc -eq 0 -a -n "$update" -a "$version" != "$previous" ]
120 if [ -w "$build" -o \
( -w "$WM_PROJECT_DIR" -a ! -e "$build" \
) ]
122 echo $version >|
"$build" 2>/dev
/null
127 # check git vs. persistent build tag
128 if [ -n "$checkOnly" ]
132 test "$version" = "$previous"
136 echo "same version as previous build"
138 echo "version changed from previous build"
141 echo "no git description found"
149 # output the git information or the -version version
151 elif [ -n "$previous" ]
153 # use previous build tag
156 # fallback to WM_PROJECT_VERSION alone
157 echo ${WM_PROJECT_VERSION:-unknown}
160 #------------------------------------------------------------------------------