Commit aea79316 authored by Andreas Dedner's avatar Andreas Dedner

added functions to generator for setting compile flags and for unconditionally making targets

Can be used directly in a scipt by calling for example
  dune.generator.setFlags("-g") or dune.generator.unsetFlags() to get the flag used during configure
and
  dune.generator.setNoDependencyCheck() and dune.generator.setDependencyCheck()
before/after a module is compile, e.g., calling dune.grid.yaspGrid(...)

added some simpler methods to use for recompilation/setting CXXFlags and add some logger output

added an option to add additional flags to the default cxxflags
(function dune.generator.addToFlags)

remoove trailing whitespaces from CXXFlags

minor fix
parent af2ceb15
Pipeline #21159 passed with stage
in 8 minutes and 16 seconds
......@@ -25,14 +25,14 @@ except ImportError:
from .._common import *
from .deprecated import DeprecatedObject
from .._grid import CommunicationDirection, DataType, InterfaceType, Marker, OutputType, PartitionType, reader
CommunicationDirection = DeprecatedObject(CommunicationDirection, "dune.common.CommunicationDirection is deprecated, use dune.grid.CommunicationDirection instead")
DataType = DeprecatedObject(DataType, "dune.common.DataType is deprecated, use dune.grid.DataType instead")
InterfaceType = DeprecatedObject(InterfaceType, "dune.common.Interface is deprecated, use dune.grid.InterfaceType instead")
Marker = DeprecatedObject(Marker, "dune.common.Marker is deprecated, use dune.grid.Marker instead")
OutputType = DeprecatedObject(OutputType, "dune.common.OutputType is deprecated, use dune.grid.OutputType instead")
PartitionType = DeprecatedObject(PartitionType, "dune.common.PartitionType is deprecated, use dune.grid.PartitionType instead")
reader = DeprecatedObject(reader, "dune.common.reader is deprecated, use dune.grid.reader instead")
# from .._grid import CommunicationDirection, DataType, InterfaceType, Marker, OutputType, PartitionType, reader
# CommunicationDirection = DeprecatedObject(CommunicationDirection, "dune.common.CommunicationDirection is deprecated, use dune.grid.CommunicationDirection instead")
# DataType = DeprecatedObject(DataType, "dune.common.DataType is deprecated, use dune.grid.DataType instead")
# InterfaceType = DeprecatedObject(InterfaceType, "dune.common.Interface is deprecated, use dune.grid.InterfaceType instead")
# Marker = DeprecatedObject(Marker, "dune.common.Marker is deprecated, use dune.grid.Marker instead")
# OutputType = DeprecatedObject(OutputType, "dune.common.OutputType is deprecated, use dune.grid.OutputType instead")
# PartitionType = DeprecatedObject(PartitionType, "dune.common.PartitionType is deprecated, use dune.grid.PartitionType instead")
# reader = DeprecatedObject(reader, "dune.common.reader is deprecated, use dune.grid.reader instead")
import numpy
def fvgetitem(self,index):
......
......@@ -585,3 +585,15 @@ def build_dune_py_module(dune_py_dir=None, definitions=None, build_args=None, bu
output = configure_module(dune_py_dir, dune_py_dir, {d: prefix[d] for d in deps}, definitions)
output += build_module(dune_py_dir, build_args)
return output
def getCXXFlags():
'''Return the CXXFLAGS used during configuration of dune-py.
These are extracted from the CMackeCache.txt file.
'''
cache = os.path.join(get_dune_py_dir(), "CMakeCache.txt")
matches = [match for match in [re.match('DEFAULT_CXXFLAGS:STRING=', line) for line in open(cache)] if match is not None]
if not matches:
return ''
if matches.__len__() > 1:
raise ConfigurationError("found multiple entries for CXXFLAGS in CMakeCache.txt")
return matches[0].string.partition('=')[2].rstrip()
import os
import os, logging
from dune.common.module import getCXXFlags
from .exceptions import CompileError, ConfigurationError
from .builder import Builder
import dune.generator.builder as builderModule
logger = logging.getLogger(__name__)
env_force = os.environ.get('DUNE_FORCE_BUILD', 'FALSE').upper()
if env_force in ('1', 'TRUE'):
......@@ -9,6 +13,33 @@ if env_force in ('1', 'TRUE'):
else:
builder = Builder(False)
def setNoDependencyCheck():
logger.info("Switching off dependency check - modules will always be compiled")
builderModule.noDepCheck = True
def setDependencyCheck():
logger.info("Switching on dependency check")
builderModule.noDepCheck = False
def setFlags(flags="-g",noChecks=None):
logger.info("Using compile flags '"+flags+"'")
builderModule.cxxFlags = flags
if noChecks is True:
setNoDependencyCheck()
elif noChecks is False:
setDependencyCheck()
def addToFlags(pre="",post="",noChecks=None):
setFlags(pre+" "+getCXXFlags()+" "+post,noChecks)
def unsetFlags(noChecks=None):
logger.info("Using compile flags from configuration of dune-py")
builderModule.cxxFlags = None
if noChecks is True:
setNoDependencyCheck()
elif noChecks is False:
setDependencyCheck()
def reset():
unsetFlags()
setDependencyCheck()
class Constructor(object):
def __init__(self, args, body=None, extra=None):
self.args = args
......
......@@ -13,6 +13,8 @@ from dune.generator.exceptions import CompileError, ConfigurationError
import dune.common.module
logger = logging.getLogger(__name__)
cxxFlags = None
noDepCheck = False
class Builder:
def __init__(self, force=False):
......@@ -38,8 +40,16 @@ class Builder:
def compile(self, target='all'):
cmake_command = dune.common.module.get_cmake_command()
cmake_args = [cmake_command, "--build", self.dune_py_dir, "--target", target]
make_args = []
if self.build_args is not None:
cmake_args += ['--'] + self.build_args
make_args += self.build_args
if cxxFlags is not None:
make_args += ['CXXFLAGS='+cxxFlags]
if noDepCheck:
make_args += ["-B"]
if cmake_args != []:
cmake_args += ["--"] + make_args
cmake = subprocess.Popen(cmake_args, cwd=self.generated_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = cmake.communicate()
logger.debug(buffer_to_str(stdout))
......
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