Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: build/linux/rewrite_dirs.py

Issue 199016: linux: improve support for cross-compiling (Closed)
Patch Set: Address review comments Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/linux/pkg-config-wrapper ('k') | build/linux/system.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2
3 """Rewrites paths in -I, -L and other option to be relative to a sysroot."""
4
5 import sys
6 import os
7
8 REWRITE_PREFIX = ['-I',
9 '-idirafter',
10 '-imacros',
11 '-imultilib',
12 '-include',
13 '-iprefix',
14 '-iquote',
15 '-isystem',
16 '-L']
17
18 def RewritePath(path, sysroot):
19 """Rewrites a path by prefixing it with the sysroot if it is absolute."""
20 if os.path.isabs(path):
21 path = path.lstrip('/')
22 return os.path.join(sysroot, path)
23 else:
24 return path
25
26 def RewriteLine(line, sysroot):
27 """Rewrites all the paths in recognized options."""
28 args = line.split()
29 count = len(args)
30 i = 0
31 while i < count:
32 for prefix in REWRITE_PREFIX:
33 # The option can be either in the form "-I /path/to/dir" or
34 # "-I/path/to/dir" so handle both.
35 if args[i] == prefix:
36 i += 1
37 try:
38 args[i] = RewritePath(args[i], sysroot)
39 except IndexError:
40 sys.stderr.write('Missing argument following %s\n' % prefix)
41 break
42 elif args[i].startswith(prefix):
43 args[i] = prefix + RewritePath(args[i][len(prefix):], sysroot)
44 i += 1
45
46 return ' '.join(args)
47
48 def main(argv):
49 try:
50 sysroot = argv[1]
51 except IndexError:
52 sys.stderr.write('usage: %s /path/to/sysroot\n' % argv[0])
53 return 1
54
55 for line in sys.stdin.readlines():
56 line = RewriteLine(line.strip(), sysroot)
57 print line
58 return 0
59
60 if __name__ == '__main__':
61 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « build/linux/pkg-config-wrapper ('k') | build/linux/system.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698