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

Unified Diff: fusl/tools/populate_crt.py

Issue 1649133002: Start to fusl toolchain (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 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 | « fusl/test/empty_main.c ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/tools/populate_crt.py
diff --git a/fusl/tools/populate_crt.py b/fusl/tools/populate_crt.py
new file mode 100644
index 0000000000000000000000000000000000000000..733e5c88203c38aebaea1246633351396d0b3f6b
--- /dev/null
+++ b/fusl/tools/populate_crt.py
@@ -0,0 +1,73 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os.path
+import shutil
+import subprocess
+import sys
+
+
+"""Populate the compiler-provided portions of the fusl sysroot.
+
+In particular, crtbegin, ocrtend.o,libgcc.a, and so on must be copied
+from the host sysroot to our sysroot.
+"""
+
+def parse_clang_dirs(clang):
+ """Parse the output of |clang -print-search-dirs|.
+
+ This is used to find library search paths. One line of the output
+ is formatted something like:
+
+ libraries: =/usr/lib/gcc/4.8:/lib:/usr/lib
+
+ This functions strips the 'libraries: =' prefix and splits on the
+ colon, returning the list:
+
+ [ '/usr/lib/gcc/4.8', '/lib', '/usr/lib' ]
+ """
+
+ clang_search_dirs = subprocess.check_output([clang, '-print-search-dirs'])
+
+ library_line = None
+ library_line_prefix = 'libraries: ='
+ for line in clang_search_dirs.split('\n'):
+ if line.startswith(library_line_prefix):
+ prefix_length = len(library_line_prefix)
+ library_line = line[prefix_length:]
+ break
+ assert(library_line)
+ return library_line.split(':')
+
+
+def try_populate(artifact, library_paths, target):
+ """Returns whether we found the artifact and copied it."""
+
+ for library_path in library_paths:
+ source = os.path.join(library_path, artifact)
+ if not os.path.isfile(source):
+ continue
+ shutil.copy(source, target)
+ return True
+
+ return False
+
+
+def main():
+ clang = sys.argv[1]
+ target = sys.argv[2]
+ artifacts = sys.argv[3:]
+ assert(len(artifacts))
+
+ library_paths = parse_clang_dirs(clang)
+
+ for artifact in artifacts:
+ if not try_populate(artifact, library_paths, target):
+ print('Unable to locate %s in any of the following paths: %s' %
+ (artifact, library_paths))
+ exit(1)
+
+
+if __name__ == '__main__':
+ main()
« no previous file with comments | « fusl/test/empty_main.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698