Improvements to header installation on user machines. Internally, we can
[cvc5.git] / contrib / cut-release
1 #!/bin/bash
2 #
3 # usage: cut-release [-n] version-designation [make-args...]
4 #
5
6 function isthatright {
7 echo -n "Does that look right? [y/n] "
8 while read yn; do
9 if [ "$yn" = y -o "$yn" = Y -o "$yn" = yes -o "$yn" = YES -o "$yn" = Yes ]; then
10 break
11 elif [ "$yn" = n -o "$yn" = N -o "$yn" = no -o "$yn" = NO -o "$yn" = No ]; then
12 echo "Aborting as per user request." >&2
13 exit 1
14 else
15 echo -n "[y/n] "
16 fi
17 done
18 }
19
20 if [ "$1" = -n ]; then
21 dryrun=true
22 shift
23 else
24 dryrun=false
25 fi
26
27 if [ $# -lt 1 ]; then
28 echo "Usage: $(basename "$0") [-n] version-designation [make-args...]" >&2
29 echo "-n does a dry run (i.e., do sanity checks and build but don't touch the repository)"
30 exit 1
31 fi
32
33 if ! [ -e src/expr/node.h -a -e .svn ]; then
34 echo "$(basename "$0"): ERROR: You should run this from the top-level of a CVC4 subversion working directory" >&2
35 exit 1
36 fi
37
38 version="$1"
39 shift
40
41 if echo "$version" | grep '[^a-zA-Z0-9_.+(){}^%#-]' &>/dev/null; then
42 echo "$(basename "$0"): ERROR: Version designation \`$version' contains illegal characters" >&2
43 exit 1
44 fi
45
46 vs=($(echo "$version" | sed 's,^\([0-9]*\)\.\([0-9]*\)\(\.\([0-9]*\)\)\?\(.*\),\1 \2 \4 \5,'))
47 major=${vs[0]}
48 minor=${vs[1]}
49 release=${vs[2]-0}
50 extra=${vs[3]}
51 echo
52 echo "Major : $major"
53 echo "Minor : $minor"
54 echo "Release: $release"
55 echo "Extra : $extra"
56 echo
57 version="$major.$minor"
58 if [ "$release" != 0 ]; then
59 version="$version.$release"
60 fi
61 version="$version$extra"
62 echo "Version: $version"
63 echo
64 isthatright
65
66 echo "Checking whether release \`$version' already exists..."
67 if ! svn ls "https://subversive.cims.nyu.edu/cvc4/cvc4/tags/releases/$version" 2>&1 >/dev/null | grep non-existent >/dev/null; then
68 echo "$(basename "$0"): ERROR: Subversion repo already contains a release \`$version'" >&2
69 $dryrun || exit 1
70 fi
71
72 echo "Checking working directory for local modifications..."
73 if $dryrun; then
74 if [ -n "$(svn status -q configure.ac)" ]; then
75 echo "$(basename "$0"): ERROR: In dry-run mode, cannot operate properly with local modifications to \"configure.ac\", sorry" >&2
76 exit 1
77 fi
78 elif [ -n "$(svn status -q)" ]; then
79 echo "$(basename "$0"): ERROR: \"svn status\" indicates there are local modifications; please commit first" >&2
80 exit 1
81 fi
82
83 root="$(svn info | grep "^Repository Root: https://subversive.cims.nyu.edu/.*" | cut -f3 -d' ')"
84 if [ -z "$root" ]; then
85 echo "$(basename "$0"): ERROR: Can't get repository root URL" 2>&1
86 $dryrun || exit 1
87 fi
88
89 echo "Checking repo for unmerged updates..."
90 if [ `svn -uq status | wc -l` -ne 1 ]; then
91 echo "$(basename "$0"): ERROR: This working directory isn't up to date" 2>&1
92 $dryrun || exit 1
93 fi
94
95 echo "Checking sources for broken public headers..."
96 suspect_files="\
97 $(grep -r --exclude-dir=.svn '^[ \t]*#[ \t]*include[ \t]*"[^/]*"' src |
98 grep -v '"cvc4parser_public\.h"' |
99 grep -v '"cvc4_public\.h"' |
100 grep -v '"cvc4_private\.h"' |
101 grep -v '"cvc4autoconfig\.h"' |
102 grep -v '"cvc4parser_private\.h"' |
103 cut -f1 -d: |
104 sort -u |
105 xargs grep -l '^[ \t]*#[ \t]*include[ \t]*"cvc4.*public\.h"' |
106 xargs echo)"
107 if [ -n "$suspect_files" ]; then
108 echo "$(basename "$0"): ERROR: The following publicly-installed headers appear" 2>&1
109 echo "$(basename "$0"): ERROR: to have relative #includes and may be broken up" 2>&1
110 echo "$(basename "$0"): ERROR: on install: $suspect_files" 2>&1
111 $dryrun || exit 1
112 fi
113
114 echo "Adjusting version info lines in configure.ac..."
115 if ! grep '^m4_define(_CVC4_MAJOR, *[0-9][0-9]* *)' configure.ac &>/dev/null ||
116 ! grep '^m4_define(_CVC4_MINOR, *[0-9][0-9]* *)' configure.ac &>/dev/null ||
117 ! grep '^m4_define(_CVC4_RELEASE, *[0-9][0-9]* *)' configure.ac &>/dev/null ||
118 ! grep '^m4_define(_CVC4_EXTRAVERSION, *\[.*\] *)' configure.ac &>/dev/null; then
119 echo "$(basename "$0"): ERROR: Cannot locate the version info lines of configure.ac" >&2
120 $dryrun || exit 1
121 fi
122 perl -pi -e 's/^m4_define\(_CVC4_MAJOR, ( *)[0-9]+( *)\)/m4_define(_CVC4_MAJOR, ${1}'"$major"'$2)/;
123 s/^m4_define\(_CVC4_MINOR, ( *)[0-9]+( *)\)/m4_define(_CVC4_MINOR, ${1}'"$minor"'$2)/;
124 s/^m4_define\(_CVC4_RELEASE, ( *)[0-9]+( *)\)/m4_define(_CVC4_RELEASE, ${1}'"$release"'$2)/;
125 s/^m4_define\(_CVC4_EXTRAVERSION, ( *)\[.*\]( *)\)/m4_define(_CVC4_EXTRAVERSION, $1\['"$extra"'\]$2)/' configure.ac
126
127 trap 'echo; echo; echo "Aborting in error."; svn revert configure.ac; echo' EXIT
128
129 echo
130 echo 'Made the following change to configure.ac:'
131 echo
132 svn diff configure.ac
133 echo
134 isthatright
135
136 if ! grep '^m4_define(_CVC4_MAJOR, *'"$major"' *)' configure.ac &>/dev/null ||
137 ! grep '^m4_define(_CVC4_MINOR, *'"$minor"' *)' configure.ac &>/dev/null ||
138 ! grep '^m4_define(_CVC4_RELEASE, *'"$release"' *)' configure.ac &>/dev/null ||
139 ! grep '^m4_define(_CVC4_EXTRAVERSION, *\['"$extra"'\] *)' configure.ac &>/dev/null; then
140 echo "$(basename "$0"): INTERNAL ERROR: Cannot find the modified version info lines in configure.ac, bailing..." >&2
141 exit 1
142 fi
143 if [ -z "$(svn status -q configure.ac)" ]; then
144 echo "$(basename "$0"): INTERNAL ERROR: \"svn status\" indicates there are no local modifications to configure.ac; I expected the ones I just made!" >&2
145 exit 1
146 fi
147
148 echo "Building and checking distribution \`cvc4-$version'..."
149 if ! $SHELL -c '\
150 version="'$version'"; \
151 set -ex; \
152 ./autogen.sh; \
153 mkdir "release-$version"; \
154 cd "release-$version"; \
155 ../configure production-cln-staticbinary --disable-shared --enable-unit-testing --with-cudd --with-readline; \
156 make dist "$@"; \
157 tar xf "cvc4-$version.tar.gz"; \
158 cd "cvc4-$version"; \
159 ./configure production-cln-staticbinary --disable-shared --enable-unit-testing --with-cudd --with-readline; \
160 make check "$@"; \
161 make distcheck "$@"; \
162 '; then
163 exit 1
164 fi
165
166 if ! [ -e release-$version/cvc4-$version.tar.gz ]; then
167 echo "$(basename "$0"): INTERNAL ERROR: Cannot find the distribution tarball I just built" >&2
168 exit 1
169 fi
170 if ! [ -e release-$version/src/main/cvc4 ]; then
171 echo "$(basename "$0"): INTERNAL ERROR: Cannot find the binary I just built" >&2
172 exit 1
173 fi
174
175 echo
176 echo 'This release of CVC4 will identify itself as:'
177 echo
178 release-$version/src/main/cvc4 --version
179 echo
180 isthatright
181
182 echo
183 echo 'This binary release of CVC4 will identify itself as being configured like this:'
184 echo
185 release-$version/src/main/cvc4 --show-config
186 echo
187 isthatright
188
189 echo
190 echo "Signing tarball..."
191 cp -p "release-$version/cvc4-$version.tar.gz" .
192 gpg -b --armor "cvc4-$version.tar.gz"
193
194 echo
195 echo "Signing binary..."
196 cp -p "release-$version/src/main/cvc4" "cvc4-$version"
197 gpg -b --armor "cvc4-$version"
198
199 echo
200 echo "About to run: svn commit -m \"Cutting release $version.\""
201 isthatright
202 $dryrun || svn commit -m "Cutting release $version."
203
204 echo
205 echo "About to run: svn copy -m \"Cutting release $version.\" \"$root\" \"https://subversive.cims.nyu.edu/cvc4/cvc4/tags/releases/$version\""
206 isthatright
207 $dryrun || svn copy -m "Cutting release $version." "$root" "https://subversive.cims.nyu.edu/cvc4/cvc4/tags/releases/$version"
208
209 trap '' EXIT
210