16from pathlib
import Path
18from SCons.Builder
import Builder
22 re.compile(
r'^REG_MODULE\((\S*)\)$', re.M)
25def module_io_emitter(target, source, env):
27 if not env.get(
'HAS_DOT',
False):
28 return (target, source)
29 for source_file
in source:
30 contents = source_file.get_text_contents()
31 for entry
in module_re.findall(contents):
32 target.append(os.path.join(
'build',
'module_io', entry +
'.png'))
33 return (target, source)
36def module_io(target, source, env):
37 for target_file
in target:
39 Path(str(target_file)).touch()
41 dir = os.path.dirname(str(target_file))
42 module = os.path.splitext(os.path.basename(str(target_file)))[0]
43 if module
in [
'EclDisplay',
'Rbuf2Ds',
'FastRbuf2Ds',
'Rbuf2Rbuf',
'Ds2Raw']:
47 subprocess.run([
'basf2',
'--module-io', module],
48 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=dir, timeout=60)
52 subprocess.run([
'dot', module +
'.dot',
'-Tpng',
'-o', module +
'.png'],
53 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=dir, timeout=60)
60def doxygen_groups_emitter(target, source, env):
61 return ([
'Doxygen.h'], [])
64def doxygen_groups(target, source, env):
65 groups_file = open(str(target[0]),
'w')
67/** @defgroup DataObjects Data objects
70/** @defgroup Modules Modules
73/** @defgroup Packages Packages
78 for package
in env[
'AVAILABLE_PACKAGES']:
79 groups_file.write(f
"""
80/** @defgroup {package} {package}
84/**
@defgroup {package}_dataobjects {package} data objects
86 *
@ingroup DataObjects
89/**
@defgroup {package}_modules {package} modules
98def doxyfile(target, source, env):
99 content = source[0].get_text_contents().replace(
'BELLE2_RELEASE', env.GetOption(
'doxygen'))
100 if env.get(
'HAS_DOT',
False):
101 content = content.replace(
'HAVE_DOT = NO',
'HAVE_DOT = YES')
102 content = content.replace(
'IMPORTED',
' '.join([path.rsplit(os.sep, 1)[0]
for path
in glob(
'**/.imported', recursive=
True)]))
103 target_file = open(str(target[0]),
'w')
104 target_file.write(content)
109moduleio = Builder(action=module_io, emitter=module_io_emitter)
110moduleio.action.cmdstr =
'${MODULEIOCOMSTR}'
113doxygen = Builder(action=f
'doxygen $SOURCE 2>&1 > build/doxygen.log | sed "s;^{os.environ.get("BELLE2_LOCAL_DIR", "")}/;;g" 1>&2',
114 emitter=
lambda target, source, env: ([
'build/doxygen/html/index.html'], source))
118 env[
'BUILDERS'][
'ModuleIo'] = moduleio
119 env[
'BUILDERS'][
'DoxygenGroups'] = Builder(action=doxygen_groups, emitter=doxygen_groups_emitter)
120 env[
'BUILDERS'][
'Doxyfile'] = Builder(action=doxyfile)
121 env[
'BUILDERS'][
'Doxygen'] = doxygen
122 for builder
in [
'DoxygenGroups',
'Doxyfile',
'Doxygen']:
123 env[
'BUILDERS'][builder].action.cmdstr =
'${DOXYGENCOMSTR}'