Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #!/usr/bin/env python |
michael@0 | 2 | # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
michael@0 | 3 | # Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | # found in the LICENSE file. |
michael@0 | 5 | |
michael@0 | 6 | """Rewrites paths in -I, -L and other option to be relative to a sysroot.""" |
michael@0 | 7 | |
michael@0 | 8 | import sys |
michael@0 | 9 | import os |
michael@0 | 10 | import optparse |
michael@0 | 11 | |
michael@0 | 12 | REWRITE_PREFIX = ['-I', |
michael@0 | 13 | '-idirafter', |
michael@0 | 14 | '-imacros', |
michael@0 | 15 | '-imultilib', |
michael@0 | 16 | '-include', |
michael@0 | 17 | '-iprefix', |
michael@0 | 18 | '-iquote', |
michael@0 | 19 | '-isystem', |
michael@0 | 20 | '-L'] |
michael@0 | 21 | |
michael@0 | 22 | def RewritePath(path, opts): |
michael@0 | 23 | """Rewrites a path by stripping the prefix and prepending the sysroot.""" |
michael@0 | 24 | sysroot = opts.sysroot |
michael@0 | 25 | prefix = opts.strip_prefix |
michael@0 | 26 | if os.path.isabs(path) and not path.startswith(sysroot): |
michael@0 | 27 | if path.startswith(prefix): |
michael@0 | 28 | path = path[len(prefix):] |
michael@0 | 29 | path = path.lstrip('/') |
michael@0 | 30 | return os.path.join(sysroot, path) |
michael@0 | 31 | else: |
michael@0 | 32 | return path |
michael@0 | 33 | |
michael@0 | 34 | |
michael@0 | 35 | def RewriteLine(line, opts): |
michael@0 | 36 | """Rewrites all the paths in recognized options.""" |
michael@0 | 37 | args = line.split() |
michael@0 | 38 | count = len(args) |
michael@0 | 39 | i = 0 |
michael@0 | 40 | while i < count: |
michael@0 | 41 | for prefix in REWRITE_PREFIX: |
michael@0 | 42 | # The option can be either in the form "-I /path/to/dir" or |
michael@0 | 43 | # "-I/path/to/dir" so handle both. |
michael@0 | 44 | if args[i] == prefix: |
michael@0 | 45 | i += 1 |
michael@0 | 46 | try: |
michael@0 | 47 | args[i] = RewritePath(args[i], opts) |
michael@0 | 48 | except IndexError: |
michael@0 | 49 | sys.stderr.write('Missing argument following %s\n' % prefix) |
michael@0 | 50 | break |
michael@0 | 51 | elif args[i].startswith(prefix): |
michael@0 | 52 | args[i] = prefix + RewritePath(args[i][len(prefix):], opts) |
michael@0 | 53 | i += 1 |
michael@0 | 54 | |
michael@0 | 55 | return ' '.join(args) |
michael@0 | 56 | |
michael@0 | 57 | |
michael@0 | 58 | def main(argv): |
michael@0 | 59 | parser = optparse.OptionParser() |
michael@0 | 60 | parser.add_option('-s', '--sysroot', default='/', help='sysroot to prepend') |
michael@0 | 61 | parser.add_option('-p', '--strip-prefix', default='', help='prefix to strip') |
michael@0 | 62 | opts, args = parser.parse_args(argv[1:]) |
michael@0 | 63 | |
michael@0 | 64 | for line in sys.stdin.readlines(): |
michael@0 | 65 | line = RewriteLine(line.strip(), opts) |
michael@0 | 66 | print line |
michael@0 | 67 | return 0 |
michael@0 | 68 | |
michael@0 | 69 | |
michael@0 | 70 | if __name__ == '__main__': |
michael@0 | 71 | sys.exit(main(sys.argv)) |