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