boost_names.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #!/usr/bin/env python3
  2. # Copyright 2017 Niklas Claesson
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. """This is two implementations for how to get module names from the boost
  13. sources. One relies on json metadata files in the sources, the other relies on
  14. the folder names.
  15. Run the tool in the boost directory and append the stdout to the misc.py:
  16. boost/$ path/to/meson/tools/boost_names.py >> path/to/meson/dependencies/misc.py
  17. """
  18. import sys
  19. import os
  20. import collections
  21. import pprint
  22. import json
  23. import re
  24. Module = collections.namedtuple('Module', ['dirname', 'name', 'libnames'])
  25. Module.__repr__ = lambda self: str((self.dirname, self.name, self.libnames))
  26. LIBS = 'libs'
  27. manual_map = {
  28. 'callable_traits': 'Call Traits',
  29. 'crc': 'CRC',
  30. 'dll': 'DLL',
  31. 'gil': 'GIL',
  32. 'graph_parallel': 'GraphParallel',
  33. 'icl': 'ICL',
  34. 'io': 'IO State Savers',
  35. 'msm': 'Meta State Machine',
  36. 'mpi': 'MPI',
  37. 'mpl': 'MPL',
  38. 'multi_array': 'Multi-Array',
  39. 'multi_index': 'Multi-Index',
  40. 'numeric': 'Numeric Conversion',
  41. 'ptr_container': 'Pointer Container',
  42. 'poly_collection': 'PolyCollection',
  43. 'qvm': 'QVM',
  44. 'throw_exception': 'ThrowException',
  45. 'tti': 'TTI',
  46. 'vmd': 'VMD',
  47. }
  48. extra = [
  49. Module('utility', 'Compressed Pair', []),
  50. Module('core', 'Enable If', []),
  51. Module('functional', 'Functional/Factory', []),
  52. Module('functional', 'Functional/Forward', []),
  53. Module('functional', 'Functional/Hash', []),
  54. Module('functional', 'Functional/Overloaded Function', []),
  55. Module('utility', 'Identity Type', []),
  56. Module('utility', 'In Place Factory, Typed In Place Factory', []),
  57. Module('numeric', 'Interval', []),
  58. Module('math', 'Math Common Factor', []),
  59. Module('math', 'Math Octonion', []),
  60. Module('math', 'Math Quaternion', []),
  61. Module('math', 'Math/Special Functions', []),
  62. Module('math', 'Math/Statistical Distributions', []),
  63. Module('bind', 'Member Function', []),
  64. Module('algorithm', 'Min-Max', []),
  65. Module('numeric', 'Odeint', []),
  66. Module('utility', 'Operators', []),
  67. Module('core', 'Ref', []),
  68. Module('utility', 'Result Of', []),
  69. Module('algorithm', 'String Algo', []),
  70. Module('core', 'Swap', []),
  71. Module('', 'Tribool', []),
  72. Module('numeric', 'uBLAS', []),
  73. Module('utility', 'Value Initialized', []),
  74. ]
  75. # Cannot find the following modules in the documentation of boost
  76. not_modules = ['beast', 'logic', 'mp11', 'winapi']
  77. def eprint(message):
  78. print(message, file=sys.stderr)
  79. def get_library_names(jamfile):
  80. libs = []
  81. with open(jamfile) as jamfh:
  82. jam = jamfh.read()
  83. res = re.finditer(r'^lib[\s]+([A-Za-z0-9_]+)([^;]*);', jam, re.MULTILINE | re.DOTALL)
  84. for matches in res:
  85. if ':' in matches.group(2):
  86. libs.append(matches.group(1))
  87. res = re.finditer(r'^boost-lib[\s]+([A-Za-z0-9_]+)([^;]*);', jam, re.MULTILINE | re.DOTALL)
  88. for matches in res:
  89. if ':' in matches.group(2):
  90. libs.append('boost_{}'.format(matches.group(1)))
  91. return libs
  92. def exists(modules, module):
  93. return len([x for x in modules if x.dirname == module.dirname]) != 0
  94. def get_modules(init=extra):
  95. modules = init
  96. for directory in os.listdir(LIBS):
  97. if not os.path.isdir(os.path.join(LIBS, directory)):
  98. continue
  99. if directory in not_modules:
  100. continue
  101. jamfile = os.path.join(LIBS, directory, 'build', 'Jamfile.v2')
  102. if os.path.isfile(jamfile):
  103. libs = get_library_names(jamfile)
  104. else:
  105. libs = []
  106. if directory in manual_map.keys():
  107. modname = manual_map[directory]
  108. else:
  109. modname = directory.replace('_', ' ').title()
  110. modules.append(Module(directory, modname, libs))
  111. return modules
  112. def get_modules_2():
  113. modules = []
  114. # The python module uses an older build system format and is not easily parseable.
  115. # We add the python module libraries manually.
  116. modules.append(Module('python', 'Python', ['boost_python', 'boost_python3', 'boost_numpy', 'boost_numpy3']))
  117. for (root, dirs, files) in os.walk(LIBS):
  118. for f in files:
  119. if f == "libraries.json":
  120. projectdir = os.path.dirname(root)
  121. jamfile = os.path.join(projectdir, 'build', 'Jamfile.v2')
  122. if os.path.isfile(jamfile):
  123. libs = get_library_names(jamfile)
  124. else:
  125. libs = []
  126. # Get metadata for module
  127. jsonfile = os.path.join(root, f)
  128. with open(jsonfile) as jsonfh:
  129. boost_modules = json.loads(jsonfh.read())
  130. if(isinstance(boost_modules, dict)):
  131. boost_modules = [boost_modules]
  132. for boost_module in boost_modules:
  133. modules.append(Module(boost_module['key'], boost_module['name'], libs))
  134. # Some subprojects do not have meta directory with json file. Find those
  135. jsonless_modules = [x for x in get_modules([]) if not exists(modules, x)]
  136. for module in jsonless_modules:
  137. eprint("WARNING: {} does not have meta/libraries.json. Will guess pretty name '{}'".format(module.dirname, module.name))
  138. modules.extend(jsonless_modules)
  139. return modules
  140. def main(args):
  141. if not os.path.isdir(LIBS):
  142. eprint("ERROR: script must be run in boost source directory")
  143. # It will pick jsonless algorithm if 1 is given as argument
  144. impl = 0
  145. if len(args) > 1:
  146. if args[1] == '1':
  147. impl = 1
  148. if impl == 1:
  149. modules = get_modules()
  150. else:
  151. modules = get_modules_2()
  152. sorted_modules = sorted(modules, key=lambda module: module.name.lower())
  153. sorted_modules = [x[2] for x in sorted_modules if x[2]]
  154. sorted_modules = sum(sorted_modules, [])
  155. sorted_modules = [x for x in sorted_modules if x.startswith('boost')]
  156. pp = pprint.PrettyPrinter()
  157. pp.pprint(sorted_modules)
  158. if __name__ == '__main__':
  159. main(sys.argv)