Skip to content

Commit 44ad704

Browse files
committed
Sort rulesets when building sqlite DB.
Makes builds more deterministic.
1 parent 2c9685b commit 44ad704

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

utils/make-sqlite.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Builds an sqlite DB containing all the rulesets, indexed by target.
44

55
import glob
6+
import locale
67
import os
78
import sqlite3
89
import subprocess
@@ -11,6 +12,12 @@
1112
from collections import Counter
1213
from lxml import etree
1314

15+
# Explicitly set locale so sorting order for filenames is consistent.
16+
# This is important for deterministic builds.
17+
# https://trac.torproject.org/projects/tor/ticket/11630#comment:20
18+
# It's also helpful to ensure consistency for the lowercase check below.
19+
locale.setlocale(locale.LC_ALL, 'en_US.UTF8')
20+
1421
conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), '../src/defaults/rulesets.sqlite'))
1522
c = conn.cursor()
1623
c.execute('''DROP TABLE IF EXISTS rulesets''')
@@ -34,7 +41,8 @@
3441
xpath_host = etree.XPath("/ruleset/target/@host")
3542
xpath_ruleset = etree.XPath("/ruleset")
3643

37-
filenames = glob.glob('src/chrome/content/rules/*')
44+
# Sort filenames so output is deterministic.
45+
filenames = sorted(glob.glob('src/chrome/content/rules/*'))
3846

3947
counted_lowercase_names = Counter([name.lower() for name in filenames])
4048
most_common_entry = counted_lowercase_names.most_common(1)[0]

0 commit comments

Comments
 (0)