]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/scripts/findLibDeps.py
Enlarging window for DCS DPs retrieval for short runs for GRP + Keeping connection...
[u/mrichter/AliRoot.git] / HLT / MUON / scripts / findLibDeps.py
1 #!/usr/bin/env python
2
3 #/**************************************************************************
4 # * This file is property of and copyright by the ALICE HLT Project        *
5 # * All rights reserved.                                                   *
6 # *                                                                        *
7 # * Primary Authors:                                                       *
8 # *   Seforo Mohlalisi <seforomohlalisi@yahoo.co.uk>                       *
9 # *                                                                        *
10 # * Permission to use, copy, modify and distribute this software and its   *
11 # * documentation strictly for non-commercial purposes is hereby granted   *
12 # * without fee, provided that the above copyright notice appears in all   *
13 # * copies and that both the copyright notice and this permission notice   *
14 # * appear in the supporting documentation. The authors make no claims     *
15 # * about the suitability of this software for any purpose. It is          *
16 # * provided "as is" without express or implied warranty.                  *
17 # **************************************************************************/
18
19 # This script tries to find all dependencies of a library on other libraries.
20 #
21 # The first argument to the script should be the directory where your library
22 # of interest resides in. i.e. for
23 #  > find_libs directory1 directory2 ... directoryN libXX.so
24 # The library for which we want to find dependencies, libXX.so, must reside
25 # in directory1. All other directories are optional, but the last argument must
26 # be the library name of the library for which we want to find dependencies.
27
28 import sys
29 import os
30 import commands
31 import time
32 definedSymbols = {}
33 libraries = {}
34 foundLibs = []
35 notFound = []
36 sys.argv = sys.argv[1: ]
37 def NM(libname):
38         undefinedSymbols = []
39         if libname.endswith('.so') == True:
40                 command = """nm -C """ + libname + """ | awk '/ U /{print ;}/ T /{print ; }' """
41                 for line in os.popen(command).readlines():
42                         if '::' in line and not 'for' in line and not 'operator' in line and not 'std::' in line and not 'gnu_cxx::' in line and not 'non-virtual' in line: #To avoid looking for what we cannot find
43                                 line = line.strip()
44                                 if line.startswith('U'):
45                                         line.strip()
46                                         line = (line.lstrip('U')).strip()
47                                         U = line.find('::')
48                                         line = line[:U] #Take only the class name in the symbol 
49                                         if line not in undefinedSymbols:
50                                                 undefinedSymbols.append(line)
51                                 elif 'T ' in line:
52                                         line.strip()
53                                         k = line.find('T')
54                                         line = (line[k+1 : ]).strip()
55                                         T = line.find('::')
56                                         line = line[:T] #Take only the class name in the symbol
57                                         if definedSymbols.has_key(line) == False:
58                                                 definedSymbols[line] = libname
59         libraries[libname] = undefinedSymbols
60
61 def findLibs(libname,directory):
62         Usymbols = libraries[libname]
63         foundLibs.append(libname)
64         i = 0
65         while i < len(Usymbols):
66                 found = 0
67                 symbol = Usymbols[i]    
68                 files=os.listdir(".")
69                 files=[filename for filename in files if filename[0] != '.']
70                 for f in files:
71                         if f.endswith('.so'):
72                                 if libraries.has_key(f) == False:
73                                         NM(f)
74                                 if definedSymbols.has_key(symbol) and definedSymbols[symbol] in foundLibs:
75                                         found = 1
76                                         break
77                                 elif definedSymbols.has_key(symbol) and definedSymbols[symbol] not in foundLibs:
78                                         print definedSymbols[symbol] #Print found library name
79                                         found = 1
80                                         findLibs(definedSymbols[symbol], directory)
81                                         break
82                 else:
83                         if directory < len(sys.argv) - 1:
84                                 os.chdir(sys.argv[directory])
85                                 directory = directory + 1       
86                                 continue # Avoid incrementing the index we are searching
87                         else:
88                                 notFound.append("'"+symbol+"'" + " in " + libname)                                
89                 i = i + 1
90
91 starttime = time.time()
92 os.chdir(sys.argv[0])
93 print "Libraries " + sys.argv[-1] + " depends on; Printed in the order which they are called"
94 NM(sys.argv[-1])
95 findLibs(sys.argv[-1],1)
96 stoptime = time.time()
97 elapsed = stoptime - starttime
98 print "Running findLibDeps.py took %.3f seconds" % (elapsed)
99
100 if len(notFound) > 0:
101         print "Symbols not found"
102         for sim in notFound:
103                 print sim
104