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

Side by Side Diff: sky/tools/mojo_cache_linker.py

Issue 866383004: Fix skydb --gdb to always have symbols (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Remove <fstream> and use base/files/file.h instead Created 5 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 import logging 7 import logging
8 import os 8 import os
9 import re
10 import sys 9 import sys
10 import subprocess
11 11
12 # TODO(eseidel): This should be shared with tools/android_stack_parser/stack 12 # TODO(eseidel): Share logic with tools/android_stack_parser/stack
13 # TODO(eseidel): This could be replaced by using build-ids on Android
14 # TODO(eseidel): mojo_shell should write out a cache mapping file.
15 def main(): 13 def main():
16 logging.basicConfig(level=logging.INFO) 14 logging.basicConfig(level=logging.INFO)
17 parser = argparse.ArgumentParser( 15 parser = argparse.ArgumentParser(
18 description='Watches mojo_shell logcat output and builds a directory ' 16 description='Watches mojo_shell logcat output and builds a directory '
19 'of symlinks to symboled binaries for seen cache names.') 17 'of symlinks to symboled binaries for seen cache names.')
20 parser.add_argument('links_dir', type=str) 18 parser.add_argument('links_dir', type=str)
21 parser.add_argument('symbols_dir', type=str) 19 parser.add_argument('build_dir', type=str)
22 parser.add_argument('base_url', type=str)
23 args = parser.parse_args() 20 args = parser.parse_args()
24 21
25 regex = re.compile('Caching mojo app (?P<url>\S+) at (?P<path>\S+)')
26
27 if not os.path.isdir(args.links_dir): 22 if not os.path.isdir(args.links_dir):
28 logging.fatal('links_dir: %s is not a directory' % args.links_dir) 23 logging.fatal('links_dir: %s is not a directory' % args.links_dir)
29 sys.exit(1) 24 sys.exit(1)
30 25
31 for line in sys.stdin: 26 for name in os.listdir(args.build_dir):
32 result = regex.search(line) 27 path = os.path.join(args.build_dir, name)
33 if not result: 28 if not os.path.isfile(path):
34 continue 29 continue
35 30
36 url = result.group('url') 31 # md5sum is slow, so only bother for suffixes we care about:
37 if not url.startswith(args.base_url): 32 basename, ext = os.path.splitext(name)
38 logging.debug('%s does not match base %s' % (url, args.base_url)) 33 if ext not in ('', '.mojo', '.so'):
39 continue
40 full_name = os.path.basename(url)
41 name, ext = os.path.splitext(full_name)
42 if ext != '.mojo':
43 logging.debug('%s is not a .mojo library' % url)
44 continue 34 continue
45 35
46 symboled_name = 'lib%s_library.so' % name 36 # Ignore ninja's dot-files.
47 cache_link_path = os.path.join(args.links_dir, 37 if basename.startswith('.'):
48 os.path.basename(result.group('path')))
49 symboled_path = os.path.realpath(
50 os.path.join(args.symbols_dir, symboled_name))
51 if not os.path.isfile(symboled_path):
52 logging.warn('symboled path %s does not exist' % symboled_path)
53 continue 38 continue
54 39
55 print "%s -> %s" % (cache_link_path, symboled_path) 40 # Example output:
41 # f82a3551478a9a0e010adccd675053b9 png_viewer.mojo
42 md5 = subprocess.check_output(['md5sum', path]).strip().split()[0]
43 link_path = os.path.join(args.links_dir, '%s.mojo' % md5)
56 44
57 if os.path.lexists(cache_link_path): 45 lib_path = os.path.realpath(os.path.join(args.build_dir, name))
58 logging.debug('link already exists %s, replacing' % symboled_path)
59 os.unlink(cache_link_path)
60 46
61 os.symlink(symboled_path, cache_link_path) 47 # On android foo.mojo is stripped, but libfoo_library.so is not.
48 if ext == '.mojo':
49 symboled_name = 'lib%s_library.so' % basename
50 symboled_path = os.path.realpath(
51 os.path.join(args.build_dir, symboled_name))
52 if os.path.exists(symboled_path):
53 lib_path = symboled_path
54
55 print "%s -> %s" % (link_path, lib_path)
56
57 if os.path.lexists(link_path):
58 logging.debug('link already exists %s, replacing' % lib_path)
59 os.unlink(link_path)
60
61 os.symlink(lib_path, link_path)
62 62
63 if __name__ == '__main__': 63 if __name__ == '__main__':
64 main() 64 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698