Belle II Software  release-08-01-10
reg_map.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import re
13 from SCons.Builder import Builder
14 
15 # regular expression to find module names in source files
16 # corresponding code to get module name in ModuleManager::fillModuleNameLibMap()
17 reg_re = re.compile(r'^\s*(REG_[A-Z0-9_]+\s*\‍([\S ]+\‍))', re.M)
18 
19 
20 def build_map(target, source, env):
21  # extract the module names from all source files
22 
23  # create target output file
24  map_file = open(str(target[0]), 'w')
25 
26  # loop over source files and extract registered modules
27  nModules = 0
28  for source_file in source:
29  # ignore libs
30  if str(source_file).endswith(env.subst('$SHLIBSUFFIX')):
31  continue
32 
33  contents = source_file.get_text_contents()
34  for entry in reg_re.findall(contents):
35  map_file.write(entry + '\n')
36  nModules += 1
37 
38  map_file.close()
39 
40  if nModules == 0:
41  return "Module map file empty. Did you forget REG_MODULE(...) in your module source file?"
42 
43  return None
44 
45 
46 # define builder for module map files
47 map_builder = Builder(action=build_map)
48 map_builder.action.cmdstr = '${MAPCOMSTR}'
49 
50 
51 def generate(env):
52  env['BUILDERS']['RegMap'] = map_builder
53 
54 
55 def exists(env):
56  return True