-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
build.sh
210 lines (182 loc) · 5.16 KB
/
build.sh
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
#! /usr/bin/env bash
# Copyright (C) 2005-2024 Giorgio Maone <https://maone.net>
#
# SPDX-License-Identifier: GPL-3.0-or-later
BASE="$PWD"
SRC="$BASE/src"
BUILD="$BASE/build"
MANIFEST_IN="$SRC/manifest.json"
MANIFEST_OUT="$BUILD/manifest.json"
if [ "$1" == "watch" ]; then
while :; do
$0 -u debug
inotifywait -e 'create,modify,move,delete' -r "$SRC"
done
fi
UNPACKED_ONLY=
if [ "$1" == '-u' ]; then
UNPACKED_ONLY=1
shift
fi
strip_rc_ver() {
MANIFEST="$1"
if [[ "$2" == "rel" ]]; then
# release: truncate alpha/beta/rc suffixes (or *.9xx with increment)
replace='s/("version":.*)[a-z]+\d+/$1/, s/("version":.*)\b(\d+)\.9\d{2}/{ $1 . ($2 + 1) }/e'
else
# turn alpha/beta/rc format into *.9xx with decrement
replace='s/("version":.*?)\b(\d+)(?:\.0)*[a-z]+(\d+)/{ $1 . ($2 - 1) . "." . (900 + $3) }/e'
fi
perl -pi.bak -e "$replace" "$MANIFEST" && rm -f "$MANIFEST".bak
}
VER=$(grep '"version":' "$MANIFEST_IN" | sed -re 's/.*": "(.*?)".*/\1/')
if [ "$1" == "tag" ]; then
# ensure nscl is up-to-date git-wise
./nscl_gitsync.sh
OPTS=""
if [ "$2" != "quiet" ]; then
OPTS="-e"
fi
echo "Tagging at $VER"
git tag -a "$VER" $OPTS -m"$(gitcl 2>/dev/null)"
git push && git push origin "$VER"
exit 0
fi
if [[ "$1" =~ ^r(el(ease)?)?$ ]]; then
strip_rc_ver "$MANIFEST_IN" rel
"$0" && "$0" bump
exit
fi
if [[ "$1" == "bump" ]]; then
if [[ "$2" ]]; then
NEW_VER="$2"
if [[ "$2" == *.* ]]; then # full dotted version number
pattern='"\d+.*?'
NEW_VER='"'"$2"
elif [[ "$2" == *rc* ]]; then # new RC after release
if [[ "$2" == rc* ]]; then
if [[ ! "$VER" == *rc* ]]; then
echo >&2 "Please specify next release version (like 12rc1). Current is $VER"
exit 1
else
pattern='rc\d+'
fi
else
pattern='\b(?:\d+rc)?\d+'
fi
else # incremental version
pattern='\b\d+'
fi
REPLACE_EXPR='s/(?<PREAMBLE>"version":.*)'"$pattern"'"/$+{PREAMBLE}'"$NEW_VER"'"/'
perl -pi.bak -e $REPLACE_EXPR "$MANIFEST_IN" && "$0" bump
rm -f "$MANIFEST_IN".bak
exit
fi
echo "Bumping to $VER"
git add "$MANIFEST_IN"
git commit -m "Version bump: $VER."
if ! ([[ $VER == *rc* ]] || [[ $VER =~ \.9[0-9][0-9]$ ]]); then
# it's a stable release: let's lock nscl and tag
git submodule update
"$0" tag
fi
exit
fi
XPI_DIR="$BASE/xpi"
XPI="$XPI_DIR/noscript-$VER"
LIB="$SRC/lib"
NSCL="$SRC/nscl"
rm -rf "$BUILD" "$XPI"
cp -pR "$SRC" "$BUILD"
cp -p LICENSE "$BUILD"/
BUILD_CMD="web-ext"
BUILD_OPTS="build --overwrite-dest"
# save Chromium build settings from Mozilla signing overwrite
CHROMIUM_BUILD_CMD="$BUILD_CMD"
CHROMIUM_BUILD_OPTS="$BUILD_OPTS"
if [[ "$1" =~ ^sign(ed)?$ ]]; then
if [[ $VER == *rc* ]]; then
BUILD_CMD="$BASE/../../we-sign"
BUILD_OPTS=""
else
echo >&2 "WARNING: won't auto-sign a release version, please manually upload to AMO."
fi
fi
if [ "$1" != "debug" ]; then
DBG=""
for file in "$BUILD"/**/*.js "$BUILD"/nscl/**/*.js; do
if grep -P '\/\/\s(REL|DEV)_ONLY' "$file" >/dev/null; then
sed -i -r -e 's/\s*\/\/\s*(\S.*)\s*\/\/\s*REL_ONLY.*/\1/' -e 's/.*\/\/\s*DEV_ONLY.*//' "$file"
fi
done
else
DBG="-dbg"
fi
UNPACKED_BASE="$BASE/unpacked"
mkdir -p "$UNPACKED_BASE"
if ! [ "$UNPACKED_ONLY" ]; then
echo "Creating $XPI.xpi..."
mkdir -p "$XPI_DIR"
fi
CYGPATH=$(which cypath)
COMMON_BUILD_OPTS="--ignore-files='test/**' 'embargoed/**' content/experiments.js"
fix_manifest() {
node manifest.js "$1" "$MANIFEST_IN" "$MANIFEST_OUT"
}
build() {
UNPACKED_DIR="$UNPACKED_BASE/${1:-out}"
rm -rf "$UNPACKED_DIR"
cp -rp "$BUILD" "$UNPACKED_DIR" && echo >&2 "Copied $BUILD to $UNPACKED_DIR"
# include only the actually used nscl dependencies
rm -rf "$UNPACKED_DIR/nscl"
"$BUILD/nscl/include.sh" "$UNPACKED_DIR"
if [ "$UNPACKED_ONLY" ]; then
return
fi
if [ "$CYGPATH" ]; then
WEBEXT_IN="$(cygpath -w "$UNPACKED_DIR")"
WEBEXT_OUT="$(cygpath -w "$XPI_DIR")"
else
WEBEXT_IN="$UNPACKED_DIR"
WEBEXT_OUT="$XPI_DIR"
fi
"$BUILD_CMD" $BUILD_OPTS \
--source-dir="$WEBEXT_IN" \
--artifacts-dir="$WEBEXT_OUT" \
$COMMON_BUILD_OPTS | \
grep 'ready: .*\.zip' | sed -re 's/.* ready: //'
}
fix_manifest mv2firefox
build firefox
SIGNED="$XPI_DIR/noscript_security_suite-$VER-an+fx.xpi"
if [ -f "$SIGNED" ]; then
mv "$SIGNED" "$XPI.xpi"
elif [ -f "$XPI.zip" ]; then
if unzip -l "$XPI.xpi" | grep "META-INF/mozilla.rsa" >/dev/null 2>&1; then
echo "A signed $XPI.xpi already exists, not overwriting."
else
[[ "$VER" == *rc* ]] && xpicmd="mv" || xpicmd="cp"
$xpicmd "$XPI.zip" "$XPI$DBG.xpi"
echo "Created $XPI$DBG.xpi"
fi
fi
if [ -f "$XPI.xpi" ]; then
ln -fs "$XPI.xpi" "$BASE/latest.xpi"
elif ! [ "$UNPACKED_ONLY" ]; then
echo >&2 "ERROR: Could not create $XPI$DBG.xpi!"
exit 3
fi
# create Chromium pre-release
BUILD_CMD="$CHROMIUM_BUILD_CMD"
BUILD_OPTS="$CHROMIUM_BUILD_OPTS"
fix_manifest mv3edge
ZIP=$(build edge)
[ -f "$ZIP" ] && mv "$ZIP" "$XPI$DBG-edge.zip"
fix_manifest mv3chrome
ZIP=$(build chromium)
[ -f "$ZIP" ] && mv "$ZIP" "$XPI$DBG-chrome.zip"
if [ "$SIGNED" ] && ! [ "$UNPACKED_ONLY" ]; then
"$0" tag quiet
nscl
../../we-publish "$XPI.xpi"
fi