-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
dobuild
executable file
·158 lines (139 loc) · 3.97 KB
/
dobuild
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
#!/bin/bash
SHORTNAME="removedupes"
TARGET="tbird" # We used to support multiple targets, but no longer
PREPROCESSOR_PARAMS=" -DSHORTNAME=$SHORTNAME"
PREPROCESSOR_PARAMS+=" -DMOZ_THUNDERBIRD"
function die {
local error_message="$1"
echo -e >&2 "$error_message"
exit 1
}
function usage {
echo "Usage: $(basename) [OPTIONS...] [PREPROCESSOR DEFINITIONS...]"
echo "Build script for the $SHORTNAME extension."
echo ""
echo "Options:"
echo " -v | --version VERSION The version to build"
echo " -b | --build-type TYPE Specify the build type: beta, release-candidate, or release"
echo " -s | --subversion SUBVER Specify the subversion number for beta or rc builds (default: 1)"
echo " -h | --help This message"
echo ""
exit
}
declare -a POSITIONAL
while (( $# > 0 )); do
option="$1"
shift
case $option in
-h | --help)
usage
;;
-v | --ver | --version)
VERSION="$1"
shift
;;
-b | --build-type | --type)
BUILD_TYPE="$1"
shift
;;
--beta)
BUILD_TYPE=beta
;;
--release)
BUILD_TYPE=release
;;
--release-candidate|--rc)
BUILD_TYPE=rc
;;
--sub-version-number|--sub-version|--subversion|--sver|--sub|--sv|-s)
SUB_VERSION="$1"
shift
;;
-*)
die "Unsupported option \"$option\""
;;
*)
POSITIONAL+=("$option")
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [[ -z "$VERSION" ]]; then
if [[ -n "${BIDIMAILUI_VERSION}" ]]; then
VERSION="${BIDIMAILUI_VERSION}"
elif [[ -r ".version" ]]; then
VERSION="$(cat .version)"
fi
[[ -n "$VERSION" ]] || die "No version specified"
fi
SUB_VERSION="${SUB_VERSION:-1}"
case "$(echo $BUILD_TYPE | tr [A-Z] [a-z])" in
release )
;;
beta | b | "" )
VERSION="${VERSION}b${SUB_VERSION}"
PREPROCESSOR_PARAMS+=" -DIS_BETA_BUILD"
;;
rc | release-candidate | release_candidate)
VERSION="${VERSION}rc${SUB_VERSION}"
;;
*)
die "Invalid build type $BUILD_TYPE"
;;
esac
PREPROCESSOR_PARAMS+=" -DVERSION=$VERSION"
# all positional arguments after the target app are #define 'd in the XUL preprocessor,
# with a DEBUG_ prefix; so if you want to, say, have debugging code specific
# to the function myFancyFunc(), write it like so:
#
# #ifdef DEBUG_myFancyFunc
# debugging code etc. etc.
# #endif
#
# then invoke
#
# dobuild myFancyFunc
#
# to have your debugging code enabled
if [ $# -ne 0 ]; then
PREPROCESSOR_PARAMS+=" -DDEBUG"
for def in "$@"; do
PREPROCESSOR_PARAMS="$PREPROCESSOR_PARAMS -DDEBUG_$def"
done
else
PREPROCESSOR_PARAMS+=" --no-line-comments"
fi
BUILD_DIR="build/$TARGET"
XPI_NAME="${SHORTNAME}_${VERSION}_${TARGET}.xpi"
LINK_NAME="${SHORTNAME}_${TARGET}.xpi"
BUILD_TOOLS_DIR="buildtools"
export PERL5LIB="`pwd`/$BUILD_TOOLS_DIR"
if [[ ! -d "$BUILD_DIR" ]]; then
mkdir -p "$BUILD_DIR"
else
rm -r "$BUILD_DIR"/*
fi
$BUILD_TOOLS_DIR/preprocessor.pl $PREPROCESSOR_PARAMS jar.mn > $BUILD_DIR/jar.mn
# Our invocation of make-jars.pl doesn't literally make JAR files, it only preprocesses and copies.
$BUILD_TOOLS_DIR/make-jars.pl -q -f flat -z zip -p "$BUILD_TOOLS_DIR/preprocessor.pl $PREPROCESSOR_PARAMS" -s . -d . < $BUILD_DIR/jar.mn || exit
$BUILD_TOOLS_DIR/preprocessor.pl $PREPROCESSOR_PARAMS src/manifest.json > $BUILD_DIR/manifest.json
# Difficult to use the XUL preprocessor with package.json, since npm and IDEs rely on it being well-formed, and JSON doesn't have #-comments
sed -r "s/__VERSION__/${VERSION}/" package.json > $BUILD_DIR/package.json
rm -f installed-chrome.txt
mkdir -p $BUILD_DIR/defaults/preferences
cp src/defaults/preferences/${SHORTNAME}.js $BUILD_DIR/defaults/preferences
mv ${SHORTNAME} $BUILD_DIR/chrome
cp src/background.js $BUILD_DIR/background.js
mkdir -p $BUILD_DIR/api/WindowListener
cp src/api/WindowListener/schema.json $BUILD_DIR/api/WindowListener
cp src/api/WindowListener/implementation.js $BUILD_DIR/api/WindowListener
cp LICENSE $BUILD_DIR
cd $BUILD_DIR
zip --quiet -r $XPI_NAME \
chrome \
defaults/ \
api \
background.js \
LICENSE \
manifest.json || exit
ln $XPI_NAME $LINK_NAME