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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/linux/pkg-config-wrapper ('k') | build/linux/system.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/linux/rewrite_dirs.py
diff --git a/build/linux/rewrite_dirs.py b/build/linux/rewrite_dirs.py
new file mode 100755
index 0000000000000000000000000000000000000000..9a00f96c418bcfd213fd39b7ccdd238df6b0b441
--- /dev/null
+++ b/build/linux/rewrite_dirs.py
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+"""Rewrites paths in -I, -L and other option to be relative to a sysroot."""
+
+import sys
+import os
+
+REWRITE_PREFIX = ['-I',
+ '-idirafter',
+ '-imacros',
+ '-imultilib',
+ '-include',
+ '-iprefix',
+ '-iquote',
+ '-isystem',
+ '-L']
+
+def RewritePath(path, sysroot):
+ """Rewrites a path by prefixing it with the sysroot if it is absolute."""
+ if os.path.isabs(path):
+ path = path.lstrip('/')
+ return os.path.join(sysroot, path)
+ else:
+ return path
+
+def RewriteLine(line, sysroot):
+ """Rewrites all the paths in recognized options."""
+ args = line.split()
+ count = len(args)
+ i = 0
+ while i < count:
+ for prefix in REWRITE_PREFIX:
+ # The option can be either in the form "-I /path/to/dir" or
+ # "-I/path/to/dir" so handle both.
+ if args[i] == prefix:
+ i += 1
+ try:
+ args[i] = RewritePath(args[i], sysroot)
+ except IndexError:
+ sys.stderr.write('Missing argument following %s\n' % prefix)
+ break
+ elif args[i].startswith(prefix):
+ args[i] = prefix + RewritePath(args[i][len(prefix):], sysroot)
+ i += 1
+
+ return ' '.join(args)
+
+def main(argv):
+ try:
+ sysroot = argv[1]
+ except IndexError:
+ sys.stderr.write('usage: %s /path/to/sysroot\n' % argv[0])
+ return 1
+
+ for line in sys.stdin.readlines():
+ line = RewriteLine(line.strip(), sysroot)
+ print line
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
« 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