Commits

Johan Hake committed ef84ddf

Remove runtime dependency for checking swig version

  • Participants
  • Parent commits 0ed8315

Comments (0)

Files changed (5)

File CMakeLists.txt

     PATTERN "*.in" EXCLUDE
     )
 
-  get_filename_component(SWIG_BINARY ${SWIG_EXECUTABLE} NAME)
-
   configure_file(${CMAKE_SOURCE_DIR}/site-packages/dolfin/common/globalparameters.py.in
     ${CMAKE_BINARY_DIR}/globalparameters.py @ONLY)
 
+ - Fix runtime dependency on checking swig version
  - Deprecate DofMap member methods vertex_to_dof_map and dof_to_vertex_map
  - Add free functions: vertex_to_dof_map and dof_to_vertex_map, and correct the ordering of the map.
  - Introduce CompiledSubDomain a more robust version of compiled_subdomains, which is now deprecated

File site-packages/dolfin/common/globalparameters.py.in

     form_compiler_parameters.add("quadrature_degree", -1)
     form_compiler_parameters.add("no-evaluate_basis_derivatives", True)
 
-# Set default swig path and binary parameters
-if not parameters.has_parameter("swig_binary"):
-    parameters.add("swig_binary", "@SWIG_BINARY@")
-if not parameters.has_parameter("swig_path"):
-    parameters.add("swig_path", "")
-
 # Increase log level for form compiler to hide output
 form_compiler_parameters["log_level"] = ufl.INFO + 5
 

File site-packages/dolfin/compilemodules/compilemodule.py

 # Bump the interface version if anything changes that invalidates cached
 # modules (not required for change in generated code, swig version or dolfin
 # version)
-_interface_version = 0
+_interface_version = 1
 
 # A list of supported math builtins
 _cpp_math_builtins = [
 %(dolfin_import_statement)s
 
 %%feature("autodoc", "1");
+
+%%inline %%{
+int get_swigversion() { return  SWIGVERSION; }
+%%}
+
+%%pythoncode %%{
+tmp = hex(get_swigversion())
+swigversion = "%%d.%%d.%%d"%%(tuple(map(int, [tmp[-5], tmp[-3], tmp[-2:]])))
+del tmp, get_swigversion
+%%}
+
 """
 
 def expression_to_code_fragments(expr, arguments, generic_function_members=None):
                      "Provide a '%s', for the '%s' argument" % \
                      (argtype.__name__, argname))
     
+def check_swig_version(compiled_module):
+    
+    # Check swig version of compiled module
+    if compiled_module and compiled_module.swigversion != cpp.__swigversion__:
+        cpp.dolfin_error("compilemodule.py",
+                         "compiling extension module",
+                         "Incompatible swig versions detected. DOLFIN swig "\
+                         "version is not the same as extension module swig "\
+                         "version: '%s' != '%s' " % \
+                         (cpp.__swigversion__, compiled_module.swigversion))
+
 @mpi_jit_decorator
 def compile_extension_module(code, module_name="",
                              additional_declarations="",
         codelines += ["}"]
         code = "\n".join(codelines)
 
-    # Check and set swig binary
-    if not instant.check_and_set_swig_binary(dolfin.parameters["swig_binary"], \
-                                             dolfin.parameters["swig_path"]):
-        cpp.dolfin_error("compilemodule.py",
-                         "ensure correct swig version",
-                         "Could not find swig installation. Pass an existing "\
-                         "swig binary or install SWIG version 2.0 or higher")
-
     # Create unique module name for this application run
     if module_name is "":
         module_name = "dolfin_compile_code_%s" % \
-                      hashlib.md5(repr(code) + instant.get_swig_version() +\
-                                  dolfin.__version__ + str(_interface_version)+\
+                      hashlib.md5(repr(code) + dolfin.__version__ + \
+                                  str(_interface_version)+\
                                   additional_declarations +\
                                   str(additional_system_headers)).hexdigest()
 
     compiled_module = instant.import_module(module_name)
 
     if compiled_module:
+        # Check that the swig version of the compiled module is the same as
+        # dolfin was compiled with
+        check_swig_version(compiled_module)
         return compiled_module
 
     sys.stdout.flush()
     # Compile extension module with instant
     compiled_module = instant.build_module(\
         code              = code,
-        additional_declarations = _additional_declarations%declaration_strs,
+        additional_declarations = _additional_declarations % declaration_strs,
         **instant_kwargs)
 
     sys.stdout.flush()
+
+    # Check that the swig version of the compiled module is the same as
+    # dolfin was compiled with
+    check_swig_version(compiled_module)
+    
     return compiled_module
 
 def extract_shared_ptr_declaration(declared_types, used_dolfin_types, shared_ptr_classes):

File site-packages/dolfin/compilemodules/jit.py

 import ufl
 ufl.set_level(ufl.INFO)
 
-# Import check for correct swig version from instant
-from instant import check_swig_version, get_swig_version, check_and_set_swig_binary
-
-# Cached swig check
-_swig_version_ok = False
-
 def mpi_jit_decorator(local_jit, *args, **kwargs):
     """A decorator for jit compilation
 
         if form.integrals() == ():
             raise RuntimeError, "Form is empty. Cannot pass to JIT compiler."
 
-    global _swig_version_ok
-
-    # Check and set swig binary
-    if not _swig_version_ok and not check_and_set_swig_binary(\
-        parameters["swig_binary"], parameters["swig_path"]):
-        raise OSError, "Could not find swig installation. Pass an existing "\
-              "swig binary or install SWIG version 2.0 or higher.\n"
-
-    # Check that the form compiler will use the same swig version
-    # that PyDOLFIN was compiled with
-    _swig_version_ok = _swig_version_ok or \
-                       check_swig_version(cpp.__swigversion__, same=True)
-
-    if not _swig_version_ok:
-        raise OSError, """\
-PyDOLFIN was not compiled with the present version of swig.
-Install swig version %s or recompiled PyDOLFIN with present swig
-"""%cpp.__swigversion__
-
-    # Cache swig version test
-    _swig_version_ok = True
-
     # Import form compiler
     form_compiler_name = cpp.parameters["form_compiler"]["name"]
     try:
     if form_compiler_parameters:
         p.update(form_compiler_parameters)
 
-    # Set the swig binary and path
-    p["swig_binary"] = parameters["swig_binary"]
-    p["swig_path"] = parameters["swig_path"]
-
     # Get jit function
     try:
         jit_compile = form_compiler.jit