hints.js: Make hint generation robust to the DOM node iterator being invalidated
[conkeror.git] / build.sh
blob5b4e6d0a1e7d7cdc2d76ee4a3a4b23f6450d471a
1 #! /bin/bash
3 SDK_DIR="/usr/lib/xulrunner"
5 XPIDL="${SDK_DIR}/xpidl"
6 XPIDL_INCLUDE="${SDK_DIR}/idl"
8 TARGET='help'
10 ## ETAGSDIR
12 ## This variable is for target `etags'. It specifies the destination
13 ## directory for the TAGS file.
15 ETAGSDIR=""
17 case "$1" in
18 xulapp)
19 TARGET=xulapp ;;
20 dist-tar)
21 TARGET=dist-tar ;;
22 release)
23 TARGET=release ;;
24 announce)
25 TARGET=announce ;;
26 etags)
27 TARGET=etags
28 ETAGSDIR="$2"
29 shift ;;
30 notes)
31 TARGET=notes ;;
32 help|-help|--help)
33 TARGET=help ;;
35 echo 'bad usage. please read the source.'
36 exit 1
37 esac
38 shift
41 VERSION=$(grep '^Version=' application.ini | cut -d '=' -f 2)
44 ## if this is not an official release, tag on a build date.
46 ## if this is an official release, strip the subminor.
48 MILESTONE="${VERSION##*.}"
49 BUILD_DATE=$(date +%Y%m%d)
50 SHORT_VERSION="$VERSION"
52 case "$TARGET" in
53 release|announce)
54 VERSION="${VERSION%.*}" ;;
56 VERSION="$VERSION.$BUILD_DATE"
57 esac
58 echo "build target: $TARGET, $VERSION"
61 ### UTILITIES
62 ###
63 ###
67 ## SCRATCH
69 ## Temporary directory for build process.
71 SCRATCH=""
73 function get_scratch () {
74 if [[ -z "$SCRATCH" ]]; then
75 SCRATCH=$(mktemp -d conkeror-XXXXXX)
80 function do_cleanup () {
81 if [[ -n "$SCRATCH" ]]; then
82 rm -r "$SCRATCH"
83 SCRATCH=""
88 function assert_conkeror_src () {
89 if [[ ! -e application.ini ]]; then
90 echo "The current directory does not appear to contain the Conkeror source code."
91 exit 1
96 function copy_tree_sans_boring () {
97 src="$1"
98 dest="$2"
99 mkdir -p "$dest"
100 O=$IFS
101 IFS=$'\n'
102 ( cd "$src"; find . -type d -and \! -name '*[~#]' -print0 ) \
103 | ( cd "$dest"; xargs -0 mkdir -p )
104 files=($( cd "$src"; find . -type f -and \! -name '*[~#]' -print ))
105 for file in "${files[@]}" ; do cp "$src/$file" "$dest/$file" ; done
106 IFS=$O
111 function do_check_milestone_for_release ()
113 if [[ "$MILESTONE" = "0" ]]; then
114 return
117 dest=VERSION
118 proposed="${VERSION%.*}".$(( ${VERSION#*.} + 1 )).0
120 echo "The version given in the file $dest does not have 0 as its last component."
121 echo -n "Shall I rewrite \`VERSION=$VERSION.$MILESTONE' to \`VERSION=$proposed'? [yN] "
122 read
123 if [[ "$REPLY" = [Yy]* ]]; then
124 perl -pi -e 's/^VERSION='$VERSION'\.'$MILESTONE'$/VERSION='$proposed'/' "$dest"
125 echo "Version changed in $dest. Please run this build program again."
126 exit
127 else
128 echo "Leaving $dest untouched. Continuing with build."
133 function diff_wrapper () {
134 scratch="$1"
135 dest="$2"
136 perlexp="$3"
138 scratchfile="${scratch}/$dest"
139 patchfile="${scratch}/$dest.patch"
141 echo -n "Processing $dest ..."
142 perl -0777 -p -e "$perlexp" "$dest" > "$scratchfile"
143 echo ok
145 if cmp "$dest" "$scratchfile" ; then
146 echo "$dest does not need to be updated"
147 else
148 diff -u "$dest" "$scratchfile" | tee "$patchfile"
149 echo -n "Apply this patch to $dest? [yN] "
150 read
151 if [[ "$REPLY" = [Yy]* ]]; then
152 patch < "$patchfile"
153 else
154 echo "Leaving $dest untouched"
163 ### TARGETS
167 function do_target_xulapp () {
168 echo -n Building XULRunner Application...
170 #build the spawn-process-helper
171 make
173 get_scratch
174 mkdir -p "$SCRATCH/chrome"
175 cp application.ini "$SCRATCH"
176 if [ -n "$CONKEROR_APP_NAME" ]; then
177 sed -i -e "s/Name=conkeror/Name=${CONKEROR_APP_NAME}/" "${SCRATCH}/application.ini"
179 for x in branding chrome components content defaults locale modules search-engines; do
180 copy_tree_sans_boring "$x" "$SCRATCH/$x"
181 done
182 cp spawn-process-helper "${SCRATCH}"
183 if [ -d idl ]; then
184 for x in idl/*; do
185 name="$(basename "$x")"
186 "${XPIDL}" -w -v -m typelib -I "${XPIDL_INCLUDE}" -e "$SCRATCH/components/${name%.idl}.xpt" "$x"
187 done
189 BUILD_ID=$(git rev-parse HEAD 2> /dev/null)
190 if [ "$?" != 0 ]; then
191 BUILD_ID="git"
193 pushd "$SCRATCH" > /dev/null
194 ## begin preprocessing
196 perl -pi -e 's/BuildID=git/BuildID='${BUILD_ID}'/g' application.ini
198 ## end preprocessing
199 zip -r ../conkeror.xulapp * > /dev/null
200 popd > /dev/null
201 do_cleanup
202 echo ok
206 function do_target_dist_tar () {
207 do_target_xulapp
208 get_scratch
209 ## now we have conkeror.xulapp
210 ## package it with install.sh
212 ## some other files should probably go in here.. NEWS, for example
213 mkdir "$SCRATCH/conkeror-$VERSION"
214 mv conkeror.xulapp "$SCRATCH/conkeror-$VERSION/"
215 cp install.sh "$SCRATCH/conkeror-$VERSION/"
216 pushd "$SCRATCH" > /dev/null
217 tar c conkeror-$VERSION | gzip > conkeror-$VERSION.tar.gz
218 popd > /dev/null
219 mv "$SCRATCH/conkeror-$VERSION.tar.gz" .
220 echo -n "Making conkeror-$VERSION.tar.gz ..."
221 do_cleanup
222 echo ok
226 function do_target_release () {
227 do_check_milestone_for_release
228 ## Make any and all release archives.
230 ## Right now, we just make a tar.gz archive that includes an install
231 ## script. In the future, we could consider making an OSX App, a Windows
232 ## Installer EXE, and a Mozilla XPI Installer.
234 do_target_dist_tar
235 echo -n Putting conkeror-$VERSION.tar.gz in downloads directory ...
236 mv conkeror-$VERSION.tar.gz ../downloads
237 echo ok
241 function do_target_announce () {
242 do_check_milestone_for_release
243 echo Entering ../www/ ... ok
244 pushd ../www/ > /dev/null
245 scratch=$(mktemp -d conkeror-XXXXXX)
247 perlexp='s/(?<=<!--\scontrolled\scontent\sinsertion\spoint::whatsnew\s-->\n) ()(?!.*'$VERSION'.*$)/<li>'$VERSION' released! \('"$(date '+%b %d, %Y')"'\)<\/li>\n/mxg'
248 diff_wrapper "$scratch" index.html "$perlexp"
250 perlexp='s/(?<=<!-- begin controlled content. do not edit manually. id:newestlink -->).*?(?=<!-- end controlled content. -->)/<a href="http:\/\/downloads.mozdev.org\/conkeror\/conkeror-'$VERSION'.tar.gz">conkeror-'$VERSION'.tar.gz<\/a>/g'
251 diff_wrapper "$scratch" installation.html "$perlexp"
253 rm -r "$scratch"
254 popd > /dev/null
258 function do_target_etags () {
259 if [[ -z "$ETAGSDIR" ]]; then
260 ETAGSDIR=.
262 ETAGSDIR="${ETAGSDIR%/}/TAGS"
263 echo -n "Building $ETAGSDIR ..."
264 etags -o "$ETAGSDIR" $(find -name \*.js -and \! -name '*[~#]*')
265 echo ok
269 function do_target_notes () {
270 FILES=($(find conkeror -name \*.js))
271 for file in "${FILES[@]}"; do
272 fileo="${file//\//\/}"
273 perl -0777 -ne 's/## BLOCK COMMENTS
274 (.*\/\*\s*[A-Z][A-Z].*:.*$
275 (\n.*$)*?
276 (\n.*\*\/)
277 (?{ $p = pos(); })) |
278 ## LINE COMMENTS
279 (.*\/\/\s*[A-Z][A-Z].*:.*$
280 ((\n.*\/\/.*$)*)
281 (?{ $p = pos(); }))
282 /print "'$fileo':$p\n" . $& . "\n\n"/mexg' < "$file"
283 done
287 function do_target_help () {
288 echo "For this script to work, your current working directory must"
289 echo "be \`<CONKEROR>/src' where <CONKEROR> is the project root."
290 echo "This script expects to find the subdirectory structure,"
291 echo "\`conkeror/content', and VERSION in the current directory,"
292 echo "\`downloads' and \`www' in the parent directory, and possibly"
293 echo "other files."
294 echo
295 echo 'Usage: bash build.sh <TARGET>'
296 echo 'where <TARGET> is one of:'
297 echo
298 echo ' xulapp'
299 echo
300 echo ' dist-tar'
301 echo
302 echo ' release Builds a release xpi and puts it in ../downloads.'
303 echo
304 echo ' announce Modify the website in ../www to announce a release.'
305 echo
306 echo ' etags [DIR] Build TAGS file in etags format. If a'
307 echo ' directory is given, TAGS will be made in'
308 echo ' that directory.'
309 echo
310 echo ' notes Shows specially formatted comments in'
311 echo " \`conkeror/content/*.js' Modifies no files."
312 echo
313 echo ' help Shows this help message. Modifies no files.'
314 echo
322 ### MAIN
326 assert_conkeror_src
328 case "$TARGET" in
329 xulapp) do_target_xulapp ;;
330 dist-tar) do_target_dist_tar ;;
331 release) do_target_release ;;
332 announce) do_target_announce ;;
333 etags) do_target_etags ;;
334 notes) do_target_notes ;;
335 help) do_target_help ;;
336 esac
338 do_cleanup