BUGFIX: 552fd5fd requires calculation of deflated geometry
[foam-extend-3.2.git] / wmake / wmakePrintBuild
blob736aab907684514576cde3994336f70a38834d94
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright held by original author
7 # \\/ M anipulation |
8 #------------------------------------------------------------------------------
9 # License
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
20 # for more details.
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
26 # Script
27 # wmakePrintBuild
29 # Description
30 # Print the version used when building the project.
32 #------------------------------------------------------------------------------
33 Script=${0##*/}
35 usage() {
36 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
37 cat<<USAGE
38 usage: $Script [OPTION]
39 options:
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
51 USAGE
52 exit 1
54 #------------------------------------------------------------------------------
56 unset checkOnly update version
58 # parse options
59 while [ "$#" -gt 0 ]
61 case "$1" in
62 -h | -help)
63 usage
65 -c | -check)
66 checkOnly=true
67 shift
69 -major)
70 echo ${WM_PROJECT_VERSION:-unknown}
71 exit 0
73 -u | -update)
74 update=true
75 shift
77 -v | -version)
78 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
79 version=$2
80 shift 2
83 usage "unknown option/argument: '$*'"
85 esac
86 done
88 #------------------------------------------------------------------------------
91 # persistent build tag
93 build="$WM_PROJECT_DIR/.build"
94 previous=$(tail -1 $build 2>/dev/null)
96 if [ -n "$version" ]
97 then
98 # specified a version - no error possible
99 rc=0
100 else
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)
106 if [ -n "$version" ]
107 then
108 # mark as success and prefix with WM_PROJECT_VERSION
109 rc=0
110 version="${WM_PROJECT_VERSION}-$version"
111 else
112 # mark as failure
113 rc=1
118 # update persistent build tag if possible
119 if [ $rc -eq 0 -a -n "$update" -a "$version" != "$previous" ]
120 then
121 if [ -w "$build" -o \( -w "$WM_PROJECT_DIR" -a ! -e "$build" \) ]
122 then
123 echo $version >| "$build" 2>/dev/null
128 # check git vs. persistent build tag
129 if [ -n "$checkOnly" ]
130 then
131 if [ $rc -eq 0 ]
132 then
133 test "$version" = "$previous"
134 rc=$?
135 if [ $rc -eq 0 ]
136 then
137 echo "same version as previous build"
138 else
139 echo "version changed from previous build"
141 else
142 echo "no git description found"
144 exit $rc
148 if [ $rc -eq 0 ]
149 then
150 # output the git information or the -version version
151 echo $version
152 elif [ -n "$previous" ]
153 then
154 # use previous build tag
155 echo $previous
156 else
157 # fallback to WM_PROJECT_VERSION alone
158 echo ${WM_PROJECT_VERSION:-unknown}
161 #------------------------------------------------------------------------------