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.

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

mercurial