config/expandlibs_gen.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 '''Given a list of object files and library names, prints a library
michael@0 6 descriptor to standard output'''
michael@0 7
michael@0 8 from __future__ import with_statement
michael@0 9 import sys
michael@0 10 import os
michael@0 11 import expandlibs_config as conf
michael@0 12 from expandlibs import LibDescriptor, isObject, ensureParentDir, ExpandLibsDeps
michael@0 13 from optparse import OptionParser
michael@0 14
michael@0 15 def generate(args):
michael@0 16 desc = LibDescriptor()
michael@0 17 for arg in args:
michael@0 18 if isObject(arg):
michael@0 19 if os.path.exists(arg):
michael@0 20 desc['OBJS'].append(os.path.abspath(arg))
michael@0 21 else:
michael@0 22 raise Exception("File not found: %s" % arg)
michael@0 23 elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
michael@0 24 if os.path.exists(arg) or os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
michael@0 25 desc['LIBS'].append(os.path.abspath(arg))
michael@0 26 else:
michael@0 27 raise Exception("File not found: %s" % arg)
michael@0 28 return desc
michael@0 29
michael@0 30 if __name__ == '__main__':
michael@0 31 parser = OptionParser()
michael@0 32 parser.add_option("--depend", dest="depend", metavar="FILE",
michael@0 33 help="generate dependencies for the given execution and store it in the given file")
michael@0 34 parser.add_option("-o", dest="output", metavar="FILE",
michael@0 35 help="send output to the given file")
michael@0 36
michael@0 37 (options, args) = parser.parse_args()
michael@0 38 if not options.output:
michael@0 39 raise Exception("Missing option: -o")
michael@0 40
michael@0 41 ensureParentDir(options.output)
michael@0 42 with open(options.output, 'w') as outfile:
michael@0 43 print >>outfile, generate(args)
michael@0 44 if options.depend:
michael@0 45 ensureParentDir(options.depend)
michael@0 46 with open(options.depend, 'w') as depfile:
michael@0 47 deps = ExpandLibsDeps(args)
michael@0 48 depfile.write("%s : %s\n" % (options.output, ' '.join(deps)))
michael@0 49 for dep in deps:
michael@0 50 depfile.write("%s :\n" % dep)

mercurial