OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import os.path |
| 6 import shutil |
| 7 import subprocess |
| 8 import sys |
| 9 |
| 10 |
| 11 """Populate the compiler-provided portions of the fusl sysroot. |
| 12 |
| 13 In particular, crtbegin, ocrtend.o,libgcc.a, and so on must be copied |
| 14 from the host sysroot to our sysroot. |
| 15 """ |
| 16 |
| 17 def parse_clang_dirs(clang): |
| 18 """Parse the output of |clang -print-search-dirs|. |
| 19 |
| 20 This is used to find library search paths. One line of the output |
| 21 is formatted something like: |
| 22 |
| 23 libraries: =/usr/lib/gcc/4.8:/lib:/usr/lib |
| 24 |
| 25 This functions strips the 'libraries: =' prefix and splits on the |
| 26 colon, returning the list: |
| 27 |
| 28 [ '/usr/lib/gcc/4.8', '/lib', '/usr/lib' ] |
| 29 """ |
| 30 |
| 31 clang_search_dirs = subprocess.check_output([clang, '-print-search-dirs']) |
| 32 |
| 33 library_line = None |
| 34 library_line_prefix = 'libraries: =' |
| 35 for line in clang_search_dirs.split('\n'): |
| 36 if line.startswith(library_line_prefix): |
| 37 prefix_length = len(library_line_prefix) |
| 38 library_line = line[prefix_length:] |
| 39 break |
| 40 assert(library_line) |
| 41 return library_line.split(':') |
| 42 |
| 43 |
| 44 def try_populate(artifact, library_paths, target): |
| 45 """Returns whether we found the artifact and copied it.""" |
| 46 |
| 47 for library_path in library_paths: |
| 48 source = os.path.join(library_path, artifact) |
| 49 if not os.path.isfile(source): |
| 50 continue |
| 51 shutil.copy(source, target) |
| 52 return True |
| 53 |
| 54 return False |
| 55 |
| 56 |
| 57 def main(): |
| 58 clang = sys.argv[1] |
| 59 target = sys.argv[2] |
| 60 artifacts = sys.argv[3:] |
| 61 assert(len(artifacts)) |
| 62 |
| 63 library_paths = parse_clang_dirs(clang) |
| 64 |
| 65 for artifact in artifacts: |
| 66 if not try_populate(artifact, library_paths, target): |
| 67 print('Unable to locate %s in any of the following paths: %s' % |
| 68 (artifact, library_paths)) |
| 69 exit(1) |
| 70 |
| 71 |
| 72 if __name__ == '__main__': |
| 73 main() |
OLD | NEW |