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

Side by Side Diff: fusl/tools/populate_crt.py

Issue 1649133002: Start to fusl toolchain (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: remove unneeded dummy action Created 4 years, 10 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
« fusl/test/empty_main.c ('K') | « fusl/test/empty_main.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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.o, crtend.o, and libgcc.a must be copied from
14 the host sysroot to our sysroot.
15 """
16
17 SYSROOT_ARTEFACTS = [
18 'crtbegin.o',
viettrungluu 2016/02/01 21:15:55 I think we mostly format Python code with a 2-spac
19 'crtend.o',
20 'libgcc.a',
21 ]
22
23
24 def parse_clang_dirs(clang):
25 """Parse the output of |clang -print-search-dirs|.
26
27 This is used to find library search paths. One line of the output
28 is formatted something like:
29
30 libraries: =/usr/lib/gcc/4.8:/lib:/usr/lib
31
32 This functions strips the 'libraries: =' prefix and splits on the
33 colon, returning the list:
34
35 [ '/usr/lib/gcc/4.8', '/lib', '/usr/lib' ]
36
37 """
38
39 clang_search_dirs = subprocess.check_output([clang, '-print-search-dirs'])
40
41 library_line = None
42 library_line_prefix = 'libraries: ='
43 for line in clang_search_dirs.split('\n'):
44 if line.startswith(library_line_prefix):
45 prefix_length = len(library_line_prefix)
46 library_line = line[prefix_length:]
47 break
48 assert(library_line)
49 return library_line.split(':')
50
51
52 def try_populate(library_path, target):
53 """Returns whether this path contained all the libs and we were able
54 to copy them."""
55
56 # Check that everything is here.
viettrungluu 2016/02/01 21:15:55 Is it possible to find some things, but not all? (
kulakowski 2016/02/01 21:29:29 Ah, yeah. Didn't think too much about it, since in
57 for artefact in SYSROOT_ARTEFACTS:
viettrungluu 2016/02/01 21:15:55 In 'merika, "we" spell artifact with an "i".
kulakowski 2016/02/01 21:29:29 Done.
58 path = os.path.join(library_path, artefact)
59 if not os.path.isfile(path):
60 return False
61
62 # All here, so copy!
63 for artefact in SYSROOT_ARTEFACTS:
64 source = os.path.join(library_path, artefact)
65 shutil.copy(source, target)
66
67 return True
68
69
70 def main():
71 clang = sys.argv[1]
72 target = sys.argv[2]
73
74 library_paths = parse_clang_dirs(clang)
75 for library_path in library_paths:
76 if try_populate(library_path, target):
77 # If we successfully populated with one path, we are done.
78 exit(0)
79
80 # No path had what we needed, so fail.
81 exit(1)
82
83
84 if __name__ == '__main__':
85 main()
OLDNEW
« fusl/test/empty_main.c ('K') | « fusl/test/empty_main.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698