Skip to content

Commit 515819f

Browse files
committed
Clean up and add comments.
1 parent 31a0018 commit 515819f

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

makexpi.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ APP_NAME=https-everywhere
1717

1818
cd "`dirname $0`"
1919
RULESETS_UNVALIDATED="$PWD/pkg/rulesets.unvalidated.sqlite"
20-
RULESETS_SQLITE="$PWD/src/defaults/rulesets.sqlite"
20+
RULESETS_JSON="$PWD/src/defaults/rulesets.json"
2121
ANDROID_APP_ID=org.mozilla.firefox
2222
VERSION=`echo $1 | cut -d "-" -f 2`
2323

@@ -55,7 +55,7 @@ if [ -n "$1" ] && [ "$2" != "--no-recurse" ] ; then
5555
exit 0
5656
fi
5757

58-
# Only generate the sqlite database if any rulesets have changed. Tried
58+
# Only generate the ruleset database if any rulesets have changed. Tried
5959
# implementing this with make, but make is very slow with 15k+ input files.
6060
needs_update() {
6161
find src/chrome/content/rules/ -newer $RULESETS_UNVALIDATED |\
@@ -69,7 +69,7 @@ if [ ! -f "$RULESETS_UNVALIDATED" ] || needs_update ; then
6969
# Those cover everything but it wouldn't matter if they didn't
7070
nohup cat src/chrome/content/rules/"$firstchar"*.xml >/dev/null 2>/dev/null &
7171
done
72-
echo "Generating sqlite DB"
72+
echo "Generating ruleset DB"
7373
python2.7 ./utils/make-sqlite.py
7474
fi
7575

@@ -81,11 +81,7 @@ die() {
8181
exit 1
8282
}
8383

84-
# If the unvalidated rulesets have changed, validate and copy to the validated
85-
# rulesets file.
86-
if [ "$RULESETS_UNVALIDATED" -nt "$RULESETS_SQLITE" ] ; then
87-
bash utils/validate.sh
88-
fi
84+
bash utils/validate.sh
8985

9086
# The name/version of the XPI we're building comes from src/install.rdf
9187
XPI_NAME="pkg/$APP_NAME-`grep em:version src/install.rdf | sed -e 's/[<>]/ /g' | cut -f3`"
@@ -128,7 +124,7 @@ rm -f "${XPI_NAME}-amo.xpi"
128124
python2.7 utils/create_xpi.py -n "${XPI_NAME}-eff.xpi" -x ".build_exclusions" "pkg/xpi-eff"
129125
python2.7 utils/create_xpi.py -n "${XPI_NAME}-amo.xpi" -x ".build_exclusions" "pkg/xpi-amo"
130126

131-
echo >&2 "Total included rules: `sqlite3 $RULESETS_SQLITE 'select count(*) from rulesets'`"
127+
echo >&2 "Total included rules: `find src/chrome/content/rules -name "*.xml" | wc -l`"
132128
echo >&2 "Rules disabled by default: `find src/chrome/content/rules -name "*.xml" | xargs grep -F default_off | wc -l`"
133129
echo >&2 "Created ${XPI_NAME}-eff.xpi and ${XPI_NAME}-amo.xpi"
134130

src/chrome/content/code/HTTPSRules.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,16 @@ const HTTPSRules = {
402402
return;
403403
},
404404

405+
/**
406+
* Read and parse the ruleset JSON.
407+
* Note: This only parses the outer JSON wrapper. Each ruleset is itself an
408+
* XML string, which will be parsed on an as-needed basis.
409+
*/
405410
loadTargets: function() {
406411
var file = new FileUtils.File(RuleWriter.chromeToPath("chrome://https-everywhere/content/rulesets.json"));
407412
var rules = JSON.parse(RuleWriter.read(file));
408413
this.targets = rules.targets;
409-
this.rules_list = rules.rules_list;
414+
this.rulesetStrings = rules.rulesetStrings;
410415
},
411416

412417
checkMixedContentHandling: function() {
@@ -562,7 +567,7 @@ const HTTPSRules = {
562567

563568
// Load a ruleset by numeric id, e.g. 234
564569
loadRulesetById: function(ruleset_id) {
565-
RuleWriter.readFromString(this.rules_list[ruleset_id], this, ruleset_id);
570+
RuleWriter.readFromString(this.rulesetStrings[ruleset_id], this, ruleset_id);
566571
},
567572

568573
// Get all rulesets matching a given target, lazy-loading from DB as necessary.

utils/make-sqlite.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env python2.7
22
#
3-
# Builds an sqlite DB containing all the rulesets, indexed by target.
3+
# Builds an sqlite DB and a JSON DB containing all the rulesets, indexed by target.
4+
# The sqlite DB is used by trivial-validate.py. The JSON DB is used by the
5+
# Firefox addon.
6+
#
47

58
import glob
69
import locale
@@ -37,7 +40,7 @@
3740
ruleset_id INTEGER)''')
3841

3942
json_output = {
40-
"rules_list": [],
43+
"rulesetStrings": [],
4144
"targets": collections.defaultdict(list)
4245
}
4346

@@ -99,8 +102,8 @@
99102
c.execute('''INSERT INTO targets (host, ruleset_id) VALUES(?, ?)''', (target, ruleset_id))
100103
# id is the current length of the rules list - i.e. the offset at which
101104
# this rule will be added in the list.
102-
json_output["targets"][target].append(len(json_output["rules_list"]))
103-
json_output["rules_list"].append(etree.tostring(tree))
105+
json_output["targets"][target].append(len(json_output["rulesetStrings"]))
106+
json_output["rulesetStrings"].append(etree.tostring(tree))
104107

105108
conn.commit()
106109
conn.execute("VACUUM")

0 commit comments

Comments
 (0)