Skip to content

Commit 27e83da

Browse files
committed
Improved cross-browser and cross-manifest development and build ergonomics.
1 parent 0131600 commit 27e83da

File tree

4 files changed

+52
-37
lines changed

4 files changed

+52
-37
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
**/embargoed/**
33
# build artifacts
44
build
5+
unpacked
56
chromium
67
xpi
78
*.xpi

build.sh

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ if [ "$1" == "watch" ]; then
1717
done
1818
fi
1919

20-
UNPACKED=
20+
UNPACKED_ONLY=
2121
if [ "$1" == '-u' ]; then
22-
UNPACKED=1
22+
UNPACKED_ONLY=1
2323
shift
2424
fi
2525

@@ -95,70 +95,75 @@ NSCL="$SRC/nscl"
9595

9696
rm -rf "$BUILD" "$XPI"
9797
cp -pR "$SRC" "$BUILD"
98-
99-
# include nscl dependencies
100-
"$NSCL/include.sh" "$BUILD"
101-
10298
cp -p LICENSE "$BUILD"/
10399

104100
BUILD_CMD="web-ext"
105101
BUILD_OPTS="build --overwrite-dest"
102+
103+
# save Chromium build settings from Mozilla signing overwrite
106104
CHROMIUM_BUILD_CMD="$BUILD_CMD"
107105
CHROMIUM_BUILD_OPTS="$BUILD_OPTS"
108106

109-
if [[ $VER == *rc* ]]; then
110-
if [[ "$1" =~ ^sign(ed)?$ ]]; then
107+
if [[ "$1" =~ ^sign(ed)?$ ]]; then
108+
if [[ $VER == *rc* ]]; then
111109
BUILD_CMD="$BASE/../../we-sign"
112110
BUILD_OPTS=""
113-
fi
114-
else
115-
if [[ "$1" == "sign" ]]; then
111+
else
116112
echo >&2 "WARNING: won't auto-sign a release version, please manually upload to AMO."
117113
fi
118114
fi
119115

120116
if [ "$1" != "debug" ]; then
121117
DBG=""
122-
pushd "$SRC"
123-
for file in **/*.js nscl/**/*.js; do
118+
for file in "$BUILD"/**/*.js "$BUILD"/nscl/**/*.js; do
124119
if grep -P '\/\/\s(REL|DEV)_ONLY' "$file" >/dev/null; then
125-
sed -re 's/\s*\/\/\s*(\S.*)\s*\/\/\s*REL_ONLY.*/\1/' -e 's/.*\/\/\s*DEV_ONLY.*//' "$file" > "$BUILD/$file"
120+
sed -i -r -e 's/\s*\/\/\s*(\S.*)\s*\/\/\s*REL_ONLY.*/\1/' -e 's/.*\/\/\s*DEV_ONLY.*//' "$file"
126121
fi
127122
done
128-
popd
129123
else
130124
DBG="-dbg"
131125
fi
132126

133-
if ! [ "$UNPACKED" ]; then
127+
UNPACKED_BASE="$BASE/unpacked"
128+
mkdir -p "$UNPACKED_BASE"
129+
130+
if ! [ "$UNPACKED_ONLY" ]; then
134131
echo "Creating $XPI.xpi..."
135132
mkdir -p "$XPI_DIR"
136133
fi
137134

138-
if which cygpath; then
139-
WEBEXT_IN="$(cygpath -w "$BUILD")"
140-
WEBEXT_OUT="$(cygpath -w "$XPI_DIR")"
141-
else
142-
WEBEXT_IN="$BUILD"
143-
WEBEXT_OUT="$XPI_DIR"
144-
fi
145-
135+
CYGPATH=$(which cypath)
146136
COMMON_BUILD_OPTS="--ignore-files='test/**' 'embargoed/**' content/experiments.js"
147137

148138
fix_manifest() {
149139
node manifest.js "$1" "$MANIFEST_IN" "$MANIFEST_OUT"
150140
}
151141

152142
build() {
153-
if [ "$1" ]; then
154-
UNPACKED_DIR="$BASE/$1"
155-
rm -rf "$UNPACKED_DIR"
156-
cp -rp "$WEBEXT_IN" "$UNPACKED_DIR" && echo >&2 "Copied $WEBEXT_IN to $UNPACKED_DIR"
143+
UNPACKED_DIR="$UNPACKED_BASE/${1:-out}"
144+
rm -rf "$UNPACKED_DIR"
145+
cp -rp "$BUILD" "$UNPACKED_DIR" && echo >&2 "Copied $BUILD to $UNPACKED_DIR"
146+
# include only the actually used nscl dependencies
147+
rm -rf "$UNPACKED_DIR/nscl"
148+
"$BUILD/nscl/include.sh" "$UNPACKED_DIR"
149+
150+
if [ "$UNPACKED_ONLY" ]; then
151+
return
157152
fi
158-
[ "$UNPACKED" ] || \
159-
( "$BUILD_CMD" $BUILD_OPTS --source-dir="$WEBEXT_IN" \
160-
--artifacts-dir="$WEBEXT_OUT" $COMMON_BUILD_OPTS | \
161-
grep 'ready: .*\.zip' | sed -re 's/.* ready: //' )
153+
154+
if [ "$CYGPATH" ]; then
155+
WEBEXT_IN="$(cygpath -w "$UNPACKED_DIR")"
156+
WEBEXT_OUT="$(cygpath -w "$XPI_DIR")"
157+
else
158+
WEBEXT_IN="$UNPACKED_DIR"
159+
WEBEXT_OUT="$XPI_DIR"
160+
fi
161+
162+
"$BUILD_CMD" $BUILD_OPTS \
163+
--source-dir="$WEBEXT_IN" \
164+
--artifacts-dir="$WEBEXT_OUT" \
165+
$COMMON_BUILD_OPTS | \
166+
grep 'ready: .*\.zip' | sed -re 's/.* ready: //'
162167
}
163168

164169
fix_manifest mv2firefox
@@ -178,7 +183,7 @@ elif [ -f "$XPI.zip" ]; then
178183
fi
179184
if [ -f "$XPI.xpi" ]; then
180185
ln -fs "$XPI.xpi" "$BASE/latest.xpi"
181-
elif ! [ "$UNPACKED" ]; then
186+
elif ! [ "$UNPACKED_ONLY" ]; then
182187
echo >&2 "ERROR: Could not create $XPI$DBG.xpi!"
183188
exit 3
184189
fi
@@ -196,7 +201,7 @@ fix_manifest mv3chrome
196201
ZIP=$(build chromium)
197202
[ -f "$ZIP" ] && mv "$ZIP" "$XPI$DBG-chrome.zip"
198203

199-
if [ "$SIGNED" ] && ! [ "$UNPACKED" ]; then
204+
if [ "$SIGNED" ] && ! [ "$UNPACKED_ONLY" ]; then
200205
"$0" tag quiet
201206
nscl
202207
../../we-publish "$XPI.xpi"

manifest.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,18 @@ if (MANIFEST_VER.includes(3)) {
9191
]) {
9292
permissions.delete(p);
9393
}
94-
}
95-
9694

95+
// TODO: just scan ${MANIFEST_SRC_DIR}/nscl/mv2main/*.js
96+
const mainWorldPatchers = [
97+
"patchWorkers",
98+
"prefetchCSSResources",
99+
"WebGLHook"
100+
];
101+
const mainWorldPatchersRx = new RegExp(`nscl/content/(${mainWorldPatchers.join("|")})\\b`);
102+
(json.content_scripts = json.content_scripts.filter(cs => !cs.world)).forEach(cs => {
103+
cs.js = cs.js.map(src => src.replace(mainWorldPatchersRx, "nscl/mv2main/$1"));
104+
});
105+
}
97106

98107
// remove developer-only stuff
99108
permissions.delete("declarativeNetRequestFeedback");

src/nscl

Submodule nscl updated from 1602236 to 44008d5

0 commit comments

Comments
 (0)