File: build.sh

package info (click to toggle)
conkeror 0.9~git080629-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,132 kB
  • ctags: 906
  • sloc: sh: 340; ansic: 246; xml: 105; makefile: 77
file content (345 lines) | stat: -rwxr-xr-x 8,884 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#! /bin/bash

# (C) Copyright 2004-2007 Shawn Betts
# (C) Copyright 2007-2008 John J. Foerch
# (C) Copyright 2007-2008 Jeremy Maitin-Shepard
#
# Use, modification, and distribution are subject to the terms specified in the
# COPYING file.

SDK_DIR="/usr/lib/xulrunner"

XPIDL="${SDK_DIR}/xpidl"
XPIDL_INCLUDE="${SDK_DIR}/idl"

TARGET='help'

## ETAGSDIR
##
##   This variable is for target `etags'.  It specifies the destination
##   directory for the TAGS file.
##
ETAGSDIR=""

case "$1" in
    xulapp)
        TARGET=xulapp ;;
    dist-tar)
        TARGET=dist-tar ;;
    release)
        TARGET=release ;;
    announce)
        TARGET=announce ;;
    etags)
        TARGET=etags
        ETAGSDIR="$2"
        shift ;;
    notes)
        TARGET=notes ;;
    help|-help|--help)
        TARGET=help ;;
    *)
        echo 'bad usage. please read the source.'
        exit 1
esac
shift


VERSION=$(grep '^Version=' application.ini | cut -d '=' -f 2)


## if this is not an official release, tag on a build date.
##
## if this is an official release, strip the subminor.
##
MILESTONE="${VERSION##*.}"
BUILD_DATE=$(date +%Y%m%d)
SHORT_VERSION="$VERSION"

case "$TARGET" in
    release|announce)
        VERSION="${VERSION%.*}" ;;
    *)
        VERSION="$VERSION.$BUILD_DATE"
esac
echo "build target: $TARGET, $VERSION"


### UTILITIES
###
###



## SCRATCH
##
##   Temporary directory for build process.
##
SCRATCH=""

function get_scratch () {
    if [[ -z "$SCRATCH" ]]; then
        SCRATCH=$(mktemp -d conkeror-XXXXXX)
    fi
}


function do_cleanup () {
    if [[ -n "$SCRATCH" ]]; then
        rm -r "$SCRATCH"
        SCRATCH=""
    fi
}


function assert_conkeror_src () {
    if  [[ ! -e application.ini ]]; then
        echo "The current directory does not appear to contain the Conkeror source code."
        exit 1
    fi
}


function copy_tree_sans_boring () {
    src="$1"
    dest="$2"
    mkdir -p "$dest"
    O=$IFS
    IFS=$'\n'
    ( cd "$src"; find . -type d -and \! -name '*[~#]' -print0 ) \
        | ( cd "$dest"; xargs -0 mkdir -p )
    files=($( cd "$src"; find . -type f -and \! -name '*[~#]' -print ))
    for file in "${files[@]}" ; do cp "$src/$file" "$dest/$file" ; done
    IFS=$O
}



function do_check_milestone_for_release ()
{
    if [[ "$MILESTONE" = "0" ]]; then
        return
    fi

    dest=VERSION
    proposed="${VERSION%.*}".$(( ${VERSION#*.} + 1 )).0

    echo "The version given in the file $dest does not have 0 as its last component."
    echo -n "Shall I rewrite \`VERSION=$VERSION.$MILESTONE' to \`VERSION=$proposed'? [yN] "
    read
    if [[ "$REPLY" = [Yy]* ]]; then
        perl -pi -e 's/^VERSION='$VERSION'\.'$MILESTONE'$/VERSION='$proposed'/' "$dest"
        echo "Version changed in $dest.  Please run this build program again."
        exit
    else
        echo "Leaving $dest untouched.  Continuing with build."
    fi
}


function diff_wrapper () {
    scratch="$1"
    dest="$2"
    perlexp="$3"

    scratchfile="${scratch}/$dest"
    patchfile="${scratch}/$dest.patch"

    echo -n "Processing $dest ..."
    perl -0777 -p -e "$perlexp" "$dest" > "$scratchfile"
    echo ok

    if cmp "$dest" "$scratchfile" ; then
        echo "$dest does not need to be updated"
    else
        diff -u "$dest" "$scratchfile" | tee "$patchfile"
        echo -n "Apply this patch to $dest? [yN] "
        read
        if [[ "$REPLY" = [Yy]* ]]; then
            patch < "$patchfile"
        else
            echo "Leaving $dest untouched"
        fi
    fi
}





### TARGETS
###
###

function do_target_xulapp () {
    echo -n Building XULRunner Application...

    #build the spawn-process-helper
    make

    get_scratch
    mkdir -p "$SCRATCH/chrome"
    cp application.ini "$SCRATCH"
    if [ -n "$CONKEROR_APP_NAME" ]; then
        sed -i -e "s/Name=conkeror/Name=${CONKEROR_APP_NAME}/" "${SCRATCH}/application.ini"
    fi
    for x in branding chrome components content defaults locale modules search-engines; do
        copy_tree_sans_boring "$x" "$SCRATCH/$x"
    done
    cp spawn-process-helper "${SCRATCH}"
    if [ -d idl ]; then
        for x in idl/*; do
            name="$(basename "$x")"
            "${XPIDL}" -w -v -m typelib -I "${XPIDL_INCLUDE}" -e "$SCRATCH/components/${name%.idl}.xpt" "$x"
        done
    fi
    BUILD_ID=$(git rev-parse HEAD 2> /dev/null)
    if [ "$?" != 0 ]; then
        BUILD_ID="git"
    fi
    pushd "$SCRATCH" > /dev/null
    ## begin preprocessing
    ##
    perl -pi -e 's/BuildID=git/BuildID='${BUILD_ID}'/g' application.ini
    ##
    ## end preprocessing
    zip -r ../conkeror.xulapp * > /dev/null
    popd > /dev/null
    do_cleanup
    echo ok
}


function do_target_dist_tar () {
    do_target_xulapp
    get_scratch
    ## now we have conkeror.xulapp
    ## package it with install.sh
    ##
    ## some other files should probably go in here.. NEWS, for example
    mkdir "$SCRATCH/conkeror-$VERSION"
    mv conkeror.xulapp "$SCRATCH/conkeror-$VERSION/"
    cp install.sh "$SCRATCH/conkeror-$VERSION/"
    pushd "$SCRATCH" > /dev/null
    tar c conkeror-$VERSION | gzip > conkeror-$VERSION.tar.gz
    popd > /dev/null
    mv "$SCRATCH/conkeror-$VERSION.tar.gz" .
    echo -n "Making conkeror-$VERSION.tar.gz ..."
    do_cleanup
    echo ok
}


function do_target_release () {
    do_check_milestone_for_release
    ## Make any and all release archives.
    ##
    ## Right now, we just make a tar.gz archive that includes an install
    ## script.  In the future, we could consider making an OSX App, a Windows
    ## Installer EXE, and a Mozilla XPI Installer.
    ##
    do_target_dist_tar
    echo -n Putting conkeror-$VERSION.tar.gz in downloads directory ...
    mv conkeror-$VERSION.tar.gz ../downloads
    echo ok
}


function do_target_announce () {
    do_check_milestone_for_release
    echo Entering ../www/ ... ok
    pushd ../www/ > /dev/null
    scratch=$(mktemp -d conkeror-XXXXXX)

    perlexp='s/(?<=<!--\scontrolled\scontent\sinsertion\spoint::whatsnew\s-->\n) ()(?!.*'$VERSION'.*$)/<li>'$VERSION' released! \('"$(date '+%b %d, %Y')"'\)<\/li>\n/mxg'
    diff_wrapper "$scratch" index.html "$perlexp"

    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'
    diff_wrapper "$scratch" installation.html "$perlexp"

    rm -r "$scratch"
    popd > /dev/null
}


function do_target_etags () {
    if [[ -z "$ETAGSDIR" ]]; then
        ETAGSDIR=.
    fi
    ETAGSDIR="${ETAGSDIR%/}/TAGS"
    echo -n "Building $ETAGSDIR ..."
    etags -o "$ETAGSDIR" $(find -name \*.js -and \! -name '*[~#]*')
    echo ok
}


function do_target_notes () {
    FILES=($(find conkeror -name \*.js))
    for file in "${FILES[@]}"; do
        fileo="${file//\//\/}"
        perl -0777 -ne 's/## BLOCK COMMENTS
                           (.*\/\*\s*[A-Z][A-Z].*:.*$
                            (\n.*$)*?
                            (\n.*\*\/)
                            (?{ $p = pos(); })) |
                          ## LINE COMMENTS
                           (.*\/\/\s*[A-Z][A-Z].*:.*$
                            ((\n.*\/\/.*$)*)
                            (?{ $p = pos(); }))
                         /print "'$fileo':$p\n" . $& . "\n\n"/mexg' < "$file"
    done
}


function do_target_help () {
    echo "For this script to work, your current working directory must"
    echo "be \`<CONKEROR>/src' where <CONKEROR> is the project root."
    echo "This script expects to find the subdirectory structure,"
    echo "\`conkeror/content', and VERSION in the current directory,"
    echo "\`downloads' and \`www' in the parent directory, and possibly"
    echo "other files."
    echo
    echo 'Usage:  bash build.sh <TARGET>'
    echo 'where <TARGET> is one of:'
    echo
    echo ' xulapp'
    echo
    echo ' dist-tar'
    echo
    echo ' release                Builds a release xpi and puts it in ../downloads.'
    echo
    echo ' announce               Modify the website in ../www to announce a release.'
    echo
    echo ' etags [DIR]            Build TAGS file in etags format.  If a'
    echo '                        directory is given, TAGS will be made in'
    echo '                        that directory.'
    echo
    echo ' notes                  Shows specially formatted comments in'
    echo "                        \`conkeror/content/*.js'  Modifies no files."
    echo
    echo ' help                   Shows this help message.  Modifies no files.'
    echo
}






### MAIN
###
###

assert_conkeror_src

case "$TARGET" in
    xulapp) do_target_xulapp ;;
    dist-tar) do_target_dist_tar ;;
    release) do_target_release ;;
    announce) do_target_announce ;;
    etags) do_target_etags ;;
    notes) do_target_notes ;;
    help) do_target_help ;;
esac

do_cleanup