Commit caace360 authored by Andreas Dedner's avatar Andreas Dedner

add a 'preamble' parameter to the Builder that is simply a string which is added before

the 'DuneTyoe' is declared
Also a minor bug fix concerning the order in which the cc source and
CMakeLists entry to writen - avoids a problem when the str(...) method fails
parent 06fd1478
Pipeline #11228 passed with stage
in 14 minutes and 3 seconds
......@@ -53,16 +53,18 @@ class Builder:
sourceFileName = os.path.join(self.generated_dir, moduleName + ".cc")
if not os.path.isfile(sourceFileName):
logger.info("Loading " + pythonName + " (new)")
code = str(source)
with open(os.path.join(sourceFileName), 'w') as out:
out.write(code)
with open(os.path.join(self.generated_dir, "CMakeLists.txt"), 'a') as out:
out.write("dune_add_pybind11_module(NAME " + moduleName + " EXCLUDE_FROM_ALL)\n")
with open(os.path.join(sourceFileName), 'w') as out:
out.write(str(source))
# update build system
self.compile()
elif isString(source) and not source == open(os.path.join(sourceFileName), 'r').read():
logger.info("Loading " + pythonName + " (updated)")
code = str(source)
with open(os.path.join(sourceFileName), 'w') as out:
out.write(str(source))
out.write(code)
else:
logger.info("Loading " + pythonName)
......
......@@ -29,6 +29,7 @@ class SimpleGenerator(object):
def load(self, includes, typeName, moduleName, *args, **kwargs):
defines = kwargs.get("defines",[])
preamble = kwargs.get("preamble",None)
source = '#include <config.h>\n\n'
source += '#define USING_DUNE_PYTHON 1\n\n'
source += ''.join(["#define " + d + "\n" for d in defines])
......@@ -43,6 +44,9 @@ class SimpleGenerator(object):
with open(self.fileName, "r") as include:
source += include.read()
source += "\n"
if preamble is not None:
source += preamble
source += "\n"
source += "typedef " + typeName + " DuneType;\n"
source += "\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment