[cig-commits] commit: Fixing some problems checking for existence of

Mercurial hg at geodynamics.org
Mon Nov 24 11:27:52 PST 2008


changeset:   11:d2229a86cf7d
user:        LukeHodkinson
date:        Thu Jun 26 06:35:40 2008 +0000
files:       SConfig/Configuration.py SConfig/Installation.py SConfig/check_libraries.py SConfig/packages/PETScExt.py
description:
Fixing some problems checking for existence of
shared libraries.


diff -r f1ff7fd04911 -r d2229a86cf7d SConfig/Configuration.py
--- a/SConfig/Configuration.py	Wed Jun 25 03:38:38 2008 +0000
+++ b/SConfig/Configuration.py	Thu Jun 26 06:35:40 2008 +0000
@@ -42,7 +42,8 @@ class Configuration:
         if cfg not in self.deps:
             self.deps += [cfg]
 
-    def enable(self, scons_env, old_state=None, lib_exclude=[]):
+    def enable(self, scons_env, old_state=None,
+               abs_path=False, shared=None, lib_exclude=[]):
         """Inserts this configuration's information into the provided SCons
         environment."""
 
@@ -53,6 +54,7 @@ class Configuration:
         self.inst.enable(scons_env, old_state,
                          libs=self.libs,
                          has_shared=self.has_shared,
+                         abs_path=abs_path,
                          lib_exclude=lib_exclude)
 
         # Throw in any preprocessor stuff.
diff -r f1ff7fd04911 -r d2229a86cf7d SConfig/Installation.py
--- a/SConfig/Installation.py	Wed Jun 25 03:38:38 2008 +0000
+++ b/SConfig/Installation.py	Thu Jun 26 06:35:40 2008 +0000
@@ -75,7 +75,9 @@ class Installation:
         def_list = self.pkg.env.make_list(defs)
         self.cpp_defines += [d for d in def_list if d not in self.cpp_defines + ['']]
 
-    def enable(self, scons_env, old_state=None, libs=[], has_shared=True, lib_exclude=[]):
+    def enable(self, scons_env, old_state=None,
+               libs=[], has_shared=True, abs_path=False,
+               lib_exclude=[]):
         """Inserts this installation's information into the provided SCons
         environment. Any environment values that are modified are backed
         up into 'old_state' providing there is not already a backup there."""
@@ -153,14 +155,16 @@ class Installation:
                     # If the path is relative, make sure SCons knows it needs
                     # to treat it as relative to the project root.
                     if not os.path.isabs(full_dir): full_dir = '#' + full_dir
-                    scons_env.AppendUnique(LIBPATH=[full_dir])
+                    if not abs_path:
+                        scons_env.AppendUnique(LIBPATH=[full_dir])
                     scons_env.AppendUnique(RPATH=[abs_dir])
                 else:
 
                     # If the path is relative, make sure SCons knows it needs
                     # to treat it as relative to the project root.
                     if not os.path.isabs(full_dir): full_dir = '#' + full_dir
-                    scons_env.PrependUnique(LIBPATH=[full_dir])
+                    if not abs_path:
+                        scons_env.PrependUnique(LIBPATH=[full_dir])
                     scons_env.PrependUnique(RPATH=[abs_dir])
 
         # Add libraries if there are any, unless this package is part of our
@@ -174,8 +178,13 @@ class Installation:
                 libs = self.find_library(libs)
                 scons_env.PrependUnique(STATICLIBS=libs)
             else:
-                self.pkg.backup_variable(scons_env, 'LIBS', old_state)
-                scons_env.PrependUnique(LIBS=libs)
+                if abs_path:
+                    self.pkg.backup_variable(scons_env, 'STATICLIBS', old_state)
+                    libs = self.find_library(libs, static=False, shared=True)
+                    scons_env.PrependUnique(STATICLIBS=libs)
+                else:
+                    self.pkg.backup_variable(scons_env, 'LIBS', old_state)
+                    scons_env.PrependUnique(LIBS=libs)
 
         # If we have a framework, add it now.
         if self.fwork:
diff -r f1ff7fd04911 -r d2229a86cf7d SConfig/check_libraries.py
--- a/SConfig/check_libraries.py	Wed Jun 25 03:38:38 2008 +0000
+++ b/SConfig/check_libraries.py	Thu Jun 26 06:35:40 2008 +0000
@@ -1,6 +1,28 @@ import os, shutil
 import os, shutil
 import SConfig
 import check_headers
+
+def get_symbols_prototypes(cfg):
+    src = ''
+    for sym, proto in zip(cfg.inst.syms, cfg.inst.pkg.symbol_prototypes):
+        src += (proto % sym) + '\n'
+    return src
+
+def get_symbols_calls(cfg):
+    # Setup any code required for the symbol check.
+    src = ''
+    if cfg.inst.pkg.symbol_setup:
+        src += cfg.inst.pkg.symbol_setup + '\n'
+
+    # Unpack all the symbols.
+    for sym, call in zip(cfg.inst.syms, cfg.inst.pkg.symbol_calls):
+        src += (call % sym) + '\n'
+
+    # Include any teardown code.
+    if cfg.inst.pkg.symbol_teardown:
+        src += cfg.inst.pkg.symbol_teardown + '\n'
+
+    return src
 
 def get_symbols_source(cfg):
     """Build the source code required to check that a set of symbols is
@@ -16,26 +38,13 @@ def get_symbols_source(cfg):
 
     # Begin with header inclusions and symbol prototypes.
     src = check_headers.get_header_source(cfg)
-    for sym, proto in zip(inst.syms, pkg.symbol_prototypes):
-        src += (proto % sym) + '\n'
+    src += get_symbols_prototypes(cfg)
 
     # Setup the main function call.
     src += 'int main(int argc, char* argv[]) {\n'
-
-    # Setup any code required for the symbol check.
-    if pkg.symbol_setup:
-        src += pkg.symbol_setup + '\n'
-
-    # Unpack all the symbols.
-    for sym, call in zip(inst.syms, pkg.symbol_calls):
-        src += (call % sym) + '\n'
-
-    # Include any teardown code.
-    if pkg.symbol_teardown:
-        src += pkg.symbol_teardown + '\n'
-
-    # Finish it off and return.
+    src += get_symbols_calls(cfg)
     src += 'return 0;\n}\n'
+
     return src
 
 def generate_library_paths(cfg, lib):
@@ -46,6 +55,58 @@ def generate_library_paths(cfg, lib):
             yield os.path.abspath(path)
     else:
         yield lib_name
+
+def new_check_shared_exist(cfg):
+    """Check for the existance of shared libraries for the given
+    configuration only. We want to do this by not caring whether
+    dependencies have shared libraries or not. The method we use is
+    to build a shared library and link directly against this packages
+    shared libraries."""
+
+    # Alias the instance and package.
+    inst = cfg.inst
+    pkg = inst.pkg
+
+    pkg.ctx.Log('  Checking for existence of shared libraries:\n')
+
+    # If we're configuring the dynamic linker, just return True.
+    if pkg.name == 'dl':
+        pkg.ctx.Log('    No need for the \'dl\' package.\n')
+        return True
+
+    # If we don't have any libraries to check, return True.
+    if not cfg.libs:
+        pkg.ctx.Log('    No libraries to check!\n')
+        return True
+
+    # If this package is shared, it should have a configuration of the
+    # 'dl' package as one of it's dependencies.
+    dl = None
+    for dep in cfg.deps:
+        if dep.inst.pkg.name == 'dl':
+            dl = dep
+            break
+    if not dl:
+        raise 'Error: No dynamic linker as a dependency!'
+
+    # Begin setting up the shared library source by getting the symbols
+    # function.
+    src = check_headers.get_header_source(cfg) + '\n'
+    src += get_symbols_prototypes(cfg) + '\n'
+    src += 'void lib_main( int argc, char* argv[] ) {\n'
+    src += get_symbols_calls(cfg)
+    src += '}\n'
+
+    # Try building a library, but make sure when we enable the system we
+    # don't use the regular '-l' library options, we need to actually
+    # specify the shared library names directly.
+    if pkg.name == 'PETScExt':
+        import pdb
+        pdb.set_trace()
+    old_state = {}
+    dep_cfg.enable(pkg.env, old_state, abs_path=True, shared=True)
+
+    return True
 
 def check_shared_exist(cfg):
     """Run a sanity check on shared libraries to see if they exist."""
@@ -138,14 +199,15 @@ def run_dependency_check(cfg, dep_cfg, d
     # dependency.
     old_state = {}
     if use_dep:
-        cfg.enable(pkg.env, old_state)
+        cfg.enable(pkg.env, old_state, abs_path=True)
     else:
-        cfg.enable(pkg.env, old_state, lib_exclude=dep_pkg)
+        cfg.enable(pkg.env, old_state, abs_path=True, lib_exclude=dep_pkg)
 
     # Build the initialisation library and grab it's path.
     result = pkg.library_source(lib1_src)
     if not result[0]:
-        raise 'Broken'
+        pkg.ctx.Log('      No shared libraries.\n')
+        return False
     init_lib = pkg.ctx.sconf.lastTarget.abspath
 
     # Disable the main package for building the check library.
@@ -282,9 +344,10 @@ def check_shared_dependencies(cfg):
         # Run the test without the dependent package.
         result = run_dependency_check(cfg, dep_cfg, dl)
 
-        # If the link failed, we have a bug.
+        # If the link failed it means we have no shared libraries for this
+        # package.
         if not result[0]:
-            raise 'Error: This link should not have failed.\n'
+            return False
 
         # Check if we were able to open the initialisation library.
         if result[1].find('lib1 open failed') != -1:
@@ -516,8 +579,8 @@ def check_libraries(cfg):
 
     # Check for the existence of shared libraries if we were able to find shared
     # library-like files.
-    if not inst.fwork and cfg.has_shared:
-        cfg.has_shared = check_shared_exist(cfg)
+#    if not inst.fwork and cfg.has_shared:
+#        cfg.has_shared = new_check_shared_exist(cfg)
 
     # Also check if we know of a dependency for which the package was linked
     # against for each dependency listed.
diff -r f1ff7fd04911 -r d2229a86cf7d SConfig/packages/PETScExt.py
--- a/SConfig/packages/PETScExt.py	Wed Jun 25 03:38:38 2008 +0000
+++ b/SConfig/packages/PETScExt.py	Thu Jun 26 06:35:40 2008 +0000
@@ -4,15 +4,16 @@ class PETScExt(SConfig.Package):
 class PETScExt(SConfig.Package):
     def __init__(self, scons_env, scons_opts, required=False):
         SConfig.Package.__init__(self, scons_env, scons_opts, required)
+        self.mpi = self.dependency(SConfig.packages.MPI)
         self.petsc = self.dependency(SConfig.packages.PETSc)
         self.base_patterns = ['petscext*', 'PETSCEXT*', 'PETScExt*']
         self.header_sub_dir = ['petsc']
         self.headers = [['petscext.h',
                          'petscext_vec.h', 'petscext_mat.h',
                          'petscext_ksp.h', 'petscext_snes.h']]
-        self.libraries = [['petscext_snes', 'petscext_ksp', 'petscext_pc',
-                           'petscext_mat', 'petscext_vec',
-                           'petscext_utils']]
+        self.libraries = [['petscext_utils',
+                           'petscext_snes', 'petscext_ksp', 'petscext_pc',
+                           'petscext_mat', 'petscext_vec']]
 
     def process_installation(self, inst):
         # Have to get the architecture using this garbage...



More information about the CIG-COMMITS mailing list