OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Rewrites paths in -I, -L and other option to be relative to a sysroot.""" | 6 """Rewrites paths in -I, -L and other option to be relative to a sysroot.""" |
7 | 7 |
8 import sys | 8 import sys |
9 import os | 9 import os |
10 | 10 |
11 REWRITE_PREFIX = ['-I', | 11 REWRITE_PREFIX = ['-I', |
12 '-idirafter', | 12 '-idirafter', |
13 '-imacros', | 13 '-imacros', |
14 '-imultilib', | 14 '-imultilib', |
15 '-include', | 15 '-include', |
16 '-iprefix', | 16 '-iprefix', |
17 '-iquote', | 17 '-iquote', |
18 '-isystem', | 18 '-isystem', |
19 '-L'] | 19 '-L'] |
20 | 20 |
21 def RewritePath(path, sysroot): | 21 def RewritePath(path, sysroot): |
22 """Rewrites a path by prefixing it with the sysroot if it is absolute.""" | 22 """Rewrites a path by prefixing it with the sysroot if it is absolute.""" |
23 if os.path.isabs(path): | 23 if os.path.isabs(path) and not path.startswith(sysroot): |
24 path = path.lstrip('/') | 24 path = path.lstrip('/') |
25 return os.path.join(sysroot, path) | 25 return os.path.join(sysroot, path) |
26 else: | 26 else: |
27 return path | 27 return path |
28 | 28 |
29 def RewriteLine(line, sysroot): | 29 def RewriteLine(line, sysroot): |
30 """Rewrites all the paths in recognized options.""" | 30 """Rewrites all the paths in recognized options.""" |
31 args = line.split() | 31 args = line.split() |
32 count = len(args) | 32 count = len(args) |
33 i = 0 | 33 i = 0 |
(...skipping 21 matching lines...) Expand all Loading... |
55 sys.stderr.write('usage: %s /path/to/sysroot\n' % argv[0]) | 55 sys.stderr.write('usage: %s /path/to/sysroot\n' % argv[0]) |
56 return 1 | 56 return 1 |
57 | 57 |
58 for line in sys.stdin.readlines(): | 58 for line in sys.stdin.readlines(): |
59 line = RewriteLine(line.strip(), sysroot) | 59 line = RewriteLine(line.strip(), sysroot) |
60 print line | 60 print line |
61 return 0 | 61 return 0 |
62 | 62 |
63 if __name__ == '__main__': | 63 if __name__ == '__main__': |
64 sys.exit(main(sys.argv)) | 64 sys.exit(main(sys.argv)) |
OLD | NEW |