| 1 |
import copy |
|---|
| 2 |
|
|---|
| 3 |
class LibraryInfo(object): |
|---|
| 4 |
""" Helper class for capturing all the files that we are finding in source tree. |
|---|
| 5 |
This class is used internally by the build and by the osg-config script. |
|---|
| 6 |
""" |
|---|
| 7 |
def __init__(self, name=""): |
|---|
| 8 |
self.name = name |
|---|
| 9 |
self.source_files = [] |
|---|
| 10 |
self.header_files = [] |
|---|
| 11 |
self.test_files = [] |
|---|
| 12 |
self.osg_dep_libs = [] |
|---|
| 13 |
self.libs = [] |
|---|
| 14 |
self.libpath = [] |
|---|
| 15 |
self.frameworks = [] |
|---|
| 16 |
self.frameworkpath = [] |
|---|
| 17 |
self.cpppath = [] |
|---|
| 18 |
self.osg_test_libs = [] |
|---|
| 19 |
self.other_test_libs = [] |
|---|
| 20 |
self.test_cpppath = [] |
|---|
| 21 |
self.test_libpath = [] |
|---|
| 22 |
self.unittest_files = [] |
|---|
| 23 |
|
|---|
| 24 |
def dump(self): |
|---|
| 25 |
""" Dump contained data to a dictionary that could be pprinted. """ |
|---|
| 26 |
ret_dict = {} |
|---|
| 27 |
for i in self.__dict__.keys(): |
|---|
| 28 |
if i not in ["source_files","header_files","test_files"]: |
|---|
| 29 |
ret_dict[i] = self.__dict__[i] |
|---|
| 30 |
return ret_dict |
|---|
| 31 |
|
|---|
| 32 |
def load(self, dumpDict): |
|---|
| 33 |
""" Load status from a dumped dictionary.""" |
|---|
| 34 |
for i in self.__dict__.keys(): |
|---|
| 35 |
if dumpDict.has_key(i): |
|---|
| 36 |
self.__dict__[i] = dumpDict[i] |
|---|
| 37 |
|
|---|
| 38 |
def merge(self, other): |
|---|
| 39 |
""" Merge our library information with another library info object. """ |
|---|
| 40 |
|
|---|
| 41 |
for a in ["source_files","header_files","test_files","osg_dep_libs", |
|---|
| 42 |
"libs","libpath","frameworks","frameworkpath","cpppath", |
|---|
| 43 |
"osg_test_libs","other_test_libs","test_cpppath","test_libpath","unittest_files"]: |
|---|
| 44 |
getattr(self,a).extend([i for i in getattr(other,a) if not i in getattr(self,a)]) |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
def getLibDepList(self, knownList, libMap): |
|---|
| 48 |
""" Return list of all OSG libraries that we depend upon (and that they depend upon). |
|---|
| 49 |
Get full list of dependent libraries based on libMap and existing known list. |
|---|
| 50 |
""" |
|---|
| 51 |
dep_list = [] |
|---|
| 52 |
dep_list.extend([l for l in self.osg_dep_libs if not (l in knownList)]) |
|---|
| 53 |
for l in dep_list[:]: |
|---|
| 54 |
if libMap.has_key(l): |
|---|
| 55 |
sub_deps = libMap[l].getLibDepList(knownList + dep_list, libMap) |
|---|
| 56 |
dep_list.extend(sub_deps) |
|---|
| 57 |
return dep_list |
|---|
| 58 |
|
|---|
| 59 |
def createMergedDepLibrary(self, libMap): |
|---|
| 60 |
""" Return a new library object with all of the options |
|---|
| 61 |
merged for the dependencies of this library. |
|---|
| 62 |
This is used to combine all the options for a library and |
|---|
| 63 |
it's dependencies into a single object |
|---|
| 64 |
osg_dep_libs will be filled with all OSG libs (not just dep libs) |
|---|
| 65 |
""" |
|---|
| 66 |
dep_list = self.getLibDepList([], libMap) |
|---|
| 67 |
if not self.name in dep_list: |
|---|
| 68 |
dep_list.insert(0,self.name) |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
dep_lib_list = [libMap[l] for l in dep_list] |
|---|
| 73 |
merged_lib = LibraryInfo() |
|---|
| 74 |
merged_lib.osg_dep_libs = dep_list[:] |
|---|
| 75 |
|
|---|
| 76 |
for lib in dep_lib_list: |
|---|
| 77 |
merged_lib.merge(lib) |
|---|
| 78 |
|
|---|
| 79 |
return merged_lib |
|---|
| 80 |
|
|---|
| 81 |
class ConfigInfoAdapter(object): |
|---|
| 82 |
""" Class to adapt a LibraryInfo object into something that returns config info |
|---|
| 83 |
type data. (flags, paths, etc) |
|---|
| 84 |
|
|---|
| 85 |
libs: List or single library. (string name of class) |
|---|
| 86 |
libMap: Map from string library name to library object. |
|---|
| 87 |
osg_lib_suffix: Suffix to use for names of OSG libraries. |
|---|
| 88 |
""" |
|---|
| 89 |
def __init__(self, libs, libMap, defaultMergedLib=None, |
|---|
| 90 |
incprefix="-I", libprefix="-l", libpathprefix="-L", |
|---|
| 91 |
osg_lib_suffix="", osg_lib_ext=""): |
|---|
| 92 |
|
|---|
| 93 |
libraries = copy.copy(libs) |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
if not type(libraries) == list: |
|---|
| 97 |
libraries = [libraries] |
|---|
| 98 |
for i in range(len(libraries)): |
|---|
| 99 |
if type(libraries[i]) == str: |
|---|
| 100 |
libraries[i] = libMap[libraries[i]] |
|---|
| 101 |
|
|---|
| 102 |
self.merged_lib = LibraryInfo() |
|---|
| 103 |
if defaultMergedLib: |
|---|
| 104 |
self.merged_lib = copy.copy(defaultMergedLib) |
|---|
| 105 |
|
|---|
| 106 |
for lib in libraries: |
|---|
| 107 |
if not self.merged_lib: |
|---|
| 108 |
self.merged_lib = lib.createMergedDepLibrary(libMap) |
|---|
| 109 |
else: |
|---|
| 110 |
self.merged_lib.merge(lib.createMergedDepLibrary(libMap)) |
|---|
| 111 |
|
|---|
| 112 |
self.incprefix = incprefix |
|---|
| 113 |
self.libprefix = libprefix |
|---|
| 114 |
self.libpathprefix = libpathprefix |
|---|
| 115 |
self.osg_lib_suffix = osg_lib_suffix |
|---|
| 116 |
self.osg_lib_ext = osg_lib_ext |
|---|
| 117 |
|
|---|
| 118 |
def getIncPath(self): |
|---|
| 119 |
return self.merged_lib.cpppath |
|---|
| 120 |
def getIncPathStr(self): |
|---|
| 121 |
return " ".join(["%s%s"%(self.incprefix,p) for p in self.merged_lib.cpppath]) |
|---|
| 122 |
def getLibs(self): |
|---|
| 123 |
osg_lib_list = ["%s%s%s"%(l,self.osg_lib_suffix, self.osg_lib_ext) for l in self.merged_lib.osg_dep_libs] |
|---|
| 124 |
deps_lib_list = ["%s%s"%(l,self.osg_lib_ext) for l in self.merged_lib.libs] |
|---|
| 125 |
return osg_lib_list + deps_lib_list |
|---|
| 126 |
def getLibsStr(self): |
|---|
| 127 |
return " ".join(["%s%s"%(self.libprefix,l) for l in self.getLibs()]) |
|---|
| 128 |
def getLibPath(self): |
|---|
| 129 |
return self.merged_lib.libpath |
|---|
| 130 |
def getLibPathStr(self): |
|---|
| 131 |
return " ".join(["%s%s"%(self.libpathprefix,p) for p in self.merged_lib.libpath]) |
|---|
| 132 |
def getFrameworks(self): |
|---|
| 133 |
return self.merged_lib.frameworks |
|---|
| 134 |
def getFrameworkPath(self): |
|---|
| 135 |
return self.merged_lib.frameworkpath |
|---|
| 136 |
|
|---|
| 137 |
|
|---|