media/libopus/gen-sources.py

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 # This file takes the .mk files from an upstream opus repo and generates the
michael@0 6 # sources.mozbuild file. It is invoked as part of update.sh
michael@0 7
michael@0 8 import sys
michael@0 9 import re
michael@0 10
michael@0 11 def add_value(values, text):
michael@0 12 text = text.replace('\\', '')
michael@0 13 text = text.strip()
michael@0 14 if text:
michael@0 15 values.append(text)
michael@0 16
michael@0 17 def write_values(output, values):
michael@0 18 for value in sorted(values, key=lambda x: x.lower()):
michael@0 19 output.write(" '%s',\n" % value)
michael@0 20 output.write(']\n\n')
michael@0 21
michael@0 22 def generate_sources_mozbuild(path):
michael@0 23 makefiles = [
michael@0 24 'celt_sources.mk',
michael@0 25 'opus_sources.mk',
michael@0 26 'silk_sources.mk',
michael@0 27 ]
michael@0 28
michael@0 29 var_definition = re.compile('([A-Z_]*) = (.*)')
michael@0 30 with open('sources.mozbuild', 'w') as output:
michael@0 31
michael@0 32 output.write('# THIS FILE WAS AUTOMATICALLY GENERATED BY %s. DO NOT EDIT.\n' % sys.argv[0])
michael@0 33 for makefile in makefiles:
michael@0 34 values = []
michael@0 35 definition_started = False
michael@0 36
michael@0 37 with open('%s/%s' % (path, makefile), 'r') as mk:
michael@0 38 for line in mk:
michael@0 39 line = line.rstrip()
michael@0 40 result = var_definition.match(line)
michael@0 41 if result:
michael@0 42 if definition_started:
michael@0 43 write_values(output, values)
michael@0 44 values = []
michael@0 45 definition_started = True
michael@0 46
michael@0 47 # Some variable definitions have the first entry on the
michael@0 48 # first line. Eg:
michael@0 49 #
michael@0 50 # CELT_SOURCES = celt/bands.c
michael@0 51 #
michael@0 52 # So we treat the first group as the variable name and
michael@0 53 # the second group as a potential value.
michael@0 54 #
michael@0 55 # Note that we write the variable name in lower case (so
michael@0 56 # "CELT_SOURCES" in the .mk file becomes "celt_sources"
michael@0 57 # in the .mozbuild file) because moz.build reserves
michael@0 58 # upper-case variable names for build system outputs.
michael@0 59 output.write('%s = [\n' % result.group(1).lower())
michael@0 60 add_value(values, result.group(2))
michael@0 61 else:
michael@0 62 add_value(values, line)
michael@0 63 write_values(output, values)
michael@0 64
michael@0 65 if __name__ == '__main__':
michael@0 66 if len(sys.argv) != 2:
michael@0 67 print "Usage: %s /path/to/opus" % (sys.argv[0])
michael@0 68 sys.exit(1)
michael@0 69
michael@0 70 generate_sources_mozbuild(sys.argv[1])

mercurial