]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/workspace_tools/dev/syms.py
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / workspace_tools / dev / syms.py
1 """
2 mbed SDK
3 Copyright (c) 2011-2013 ARM Limited
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17
18 Utility to find which libraries could define a given symbol
19 """
20 from argparse import ArgumentParser
21 from os.path import join, splitext
22 from os import walk
23 from subprocess import Popen, PIPE
24
25
26 OBJ_EXT = ['.o', '.a', '.ar']
27
28
29 def find_sym_in_lib(sym, obj_path):
30 contain_symbol = False
31
32 out = Popen(["nm", "-C", obj_path], stdout=PIPE, stderr=PIPE).communicate()[0]
33 for line in out.splitlines():
34 tokens = line.split()
35 n = len(tokens)
36 if n == 2:
37 sym_type = tokens[0]
38 sym_name = tokens[1]
39 elif n == 3:
40 sym_type = tokens[1]
41 sym_name = tokens[2]
42 else:
43 continue
44
45 if sym_type == "U":
46 # This object is using this symbol, not defining it
47 continue
48
49 if sym_name == sym:
50 contain_symbol = True
51
52 return contain_symbol
53
54
55 def find_sym_in_path(sym, dir_path):
56 for root, _, files in walk(dir_path):
57 for file in files:
58
59 _, ext = splitext(file)
60 if ext not in OBJ_EXT: continue
61
62 path = join(root, file)
63 if find_sym_in_lib(sym, path):
64 print path
65
66
67 if __name__ == '__main__':
68 parser = ArgumentParser(description='Find Symbol')
69 parser.add_argument('-s', '--sym', required=True,
70 help='The symbol to be searched')
71 parser.add_argument('-p', '--path', required=True,
72 help='The path where to search')
73 args = parser.parse_args()
74
75 find_sym_in_path(args.sym, args.path)
Imprint / Impressum