1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/trunk/build/linux/rewrite_dirs.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,71 @@ 1.4 +#!/usr/bin/env python 1.5 +# Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.6 +# Use of this source code is governed by a BSD-style license that can be 1.7 +# found in the LICENSE file. 1.8 + 1.9 +"""Rewrites paths in -I, -L and other option to be relative to a sysroot.""" 1.10 + 1.11 +import sys 1.12 +import os 1.13 +import optparse 1.14 + 1.15 +REWRITE_PREFIX = ['-I', 1.16 + '-idirafter', 1.17 + '-imacros', 1.18 + '-imultilib', 1.19 + '-include', 1.20 + '-iprefix', 1.21 + '-iquote', 1.22 + '-isystem', 1.23 + '-L'] 1.24 + 1.25 +def RewritePath(path, opts): 1.26 + """Rewrites a path by stripping the prefix and prepending the sysroot.""" 1.27 + sysroot = opts.sysroot 1.28 + prefix = opts.strip_prefix 1.29 + if os.path.isabs(path) and not path.startswith(sysroot): 1.30 + if path.startswith(prefix): 1.31 + path = path[len(prefix):] 1.32 + path = path.lstrip('/') 1.33 + return os.path.join(sysroot, path) 1.34 + else: 1.35 + return path 1.36 + 1.37 + 1.38 +def RewriteLine(line, opts): 1.39 + """Rewrites all the paths in recognized options.""" 1.40 + args = line.split() 1.41 + count = len(args) 1.42 + i = 0 1.43 + while i < count: 1.44 + for prefix in REWRITE_PREFIX: 1.45 + # The option can be either in the form "-I /path/to/dir" or 1.46 + # "-I/path/to/dir" so handle both. 1.47 + if args[i] == prefix: 1.48 + i += 1 1.49 + try: 1.50 + args[i] = RewritePath(args[i], opts) 1.51 + except IndexError: 1.52 + sys.stderr.write('Missing argument following %s\n' % prefix) 1.53 + break 1.54 + elif args[i].startswith(prefix): 1.55 + args[i] = prefix + RewritePath(args[i][len(prefix):], opts) 1.56 + i += 1 1.57 + 1.58 + return ' '.join(args) 1.59 + 1.60 + 1.61 +def main(argv): 1.62 + parser = optparse.OptionParser() 1.63 + parser.add_option('-s', '--sysroot', default='/', help='sysroot to prepend') 1.64 + parser.add_option('-p', '--strip-prefix', default='', help='prefix to strip') 1.65 + opts, args = parser.parse_args(argv[1:]) 1.66 + 1.67 + for line in sys.stdin.readlines(): 1.68 + line = RewriteLine(line.strip(), opts) 1.69 + print line 1.70 + return 0 1.71 + 1.72 + 1.73 +if __name__ == '__main__': 1.74 + sys.exit(main(sys.argv))