[Numpy-svn] r4307 - in branches/numpy.scons/numpy/distutils: command scons

numpy-svn@scip... numpy-svn@scip...
Fri Oct 26 03:53:37 CDT 2007


Author: cdavid
Date: 2007-10-26 03:53:25 -0500 (Fri, 26 Oct 2007)
New Revision: 4307

Modified:
   branches/numpy.scons/numpy/distutils/command/scons.py
   branches/numpy.scons/numpy/distutils/scons/numpyenv.py
Log:
F77 support for scons command.

Modified: branches/numpy.scons/numpy/distutils/command/scons.py
===================================================================
--- branches/numpy.scons/numpy/distutils/command/scons.py	2007-10-26 08:14:02 UTC (rev 4306)
+++ branches/numpy.scons/numpy/distutils/command/scons.py	2007-10-26 08:53:25 UTC (rev 4307)
@@ -6,6 +6,7 @@
 from distutils.errors import DistutilsExecError, DistutilsSetupError
 from numpy.distutils.command.build_ext import build_ext as old_build_ext
 from numpy.distutils.ccompiler import CCompiler
+from numpy.distutils.fcompiler import FCompiler
 from numpy.distutils.exec_command import find_executable
 from numpy.distutils import log
 
@@ -53,9 +54,27 @@
     else:
         return compiler.compiler[0]
 
+def dist2sconsfc(compiler):
+    """This converts the name passed to distutils to scons name convention
+    (Fortran compiler). The argument should be a FCompiler instance.
+
+    Example:
+        --fcompiler=intel -> ifort on linux, ifl on windows"""
+    if compiler.compiler_type == 'intel':
+        return 'intelc'
+    elif compiler.compiler_type == 'gnu':
+        return 'g77'
+    elif compiler.compiler_type == 'gnu95':
+        # XXX ?
+        return 'f95'
+    else:
+        return compiler.compiler_type
+
 def get_compiler_executable(compiler):
     """For any give CCompiler instance, this gives us the name of C compiler
-    (the actual executable)."""
+    (the actual executable).
+    
+    NOTE: does NOT work with FCompiler instances."""
     # Geez, why does distutils has no common way to get the compiler name...
     if compiler.compiler_type == 'msvc':
         # this is harcoded in distutils... A bit cleaner way would be to
@@ -69,6 +88,11 @@
     else:
         return compiler.compiler[0]
 
+def get_f77_compiler_executable(compiler):
+    """For any give FCompiler instance, this gives us the name of F77 compiler
+    (the actual executable)."""
+    return compiler.compiler_f77[0]
+
 def get_tool_path(compiler):
     """Given a distutils.ccompiler.CCompiler class, returns the path of the
     toolset related to C compilation."""
@@ -79,6 +103,17 @@
         raise DistutilsSetupError("Could not find compiler executable info for scons")
     return fullpath
 
+def get_f77_tool_path(compiler):
+    """Given a distutils.ccompiler.FCompiler class, returns the path of the
+    toolset related to F77 compilation."""
+    fullpath_exec = find_executable(get_f77_compiler_executable(compiler))
+    if fullpath_exec:
+        fullpath = pdirname(fullpath_exec)
+    else:
+        raise DistutilsSetupError("Could not find F77 compiler executable "\
+                "info for scons")
+    return fullpath
+
 def protect_path(path):
     """Convert path (given as a string) to something the shell will have no
     problem to understand (space, etc... problems)."""
@@ -116,7 +151,7 @@
         # full path, and add the path to the env['PATH'] variable in env
         # instance (this is done in numpy.distutils.scons module).
         compiler_type = self.compiler
-        from distutils.ccompiler import new_compiler
+        from numpy.distutils.ccompiler import new_compiler
         self.compiler = new_compiler(compiler=compiler_type,
                                      verbose=self.verbose,
                                      dry_run=self.dry_run,
@@ -127,6 +162,15 @@
         if hasattr(self.compiler, 'initialize'):
             self.compiler.initialize()
 		
+        # We do the same for the fortran compiler
+        fcompiler_type = self.fcompiler
+        from numpy.distutils.fcompiler import new_fcompiler
+        self.fcompiler = new_fcompiler(compiler = fcompiler_type,
+                                       verbose = self.verbose,
+                                       dry_run = self.dry_run,
+                                       force = self.force)
+        self.fcompiler.customize(self.distribution)
+
     def run(self):
         # XXX: when a scons script is missing, scons only prints warnings, and
         # does not return a failure (status is 0). We have to detect this from
@@ -149,6 +193,10 @@
                                                                 pdirname(sconscript)))
             cmd += ' cc_opt=%s ' % dist2sconscc(self.compiler)
             cmd += ' cc_opt_path=%s ' % protect_path(get_tool_path(self.compiler))
+
+            cmd += ' f77_opt=%s ' % dist2sconsfc(self.fcompiler)
+            cmd += ' f77_opt_path=%s ' % protect_path(get_f77_tool_path(self.fcompiler))
+
             cmd += ' include_bootstrap=%s ' % dirl_to_str(get_numpy_include_dirs())
             log.info("Executing scons command: %s ", cmd)
             st = os.system(cmd)

Modified: branches/numpy.scons/numpy/distutils/scons/numpyenv.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/numpyenv.py	2007-10-26 08:14:02 UTC (rev 4306)
+++ branches/numpy.scons/numpy/distutils/scons/numpyenv.py	2007-10-26 08:53:25 UTC (rev 4307)
@@ -65,6 +65,10 @@
     # Add compiler related info
     opts.Add('cc_opt', 'name of C compiler', '')
     opts.Add('cc_opt_path', 'path of the C compiler set in cc_opt', '')
+
+    opts.Add('f77_opt', 'name of F77 compiler', '')
+    opts.Add('f77_opt_path', 'path of the F77 compiler set in cc_opt', '')
+
     return opts
 
 def GetNumpyEnvironment(args):
@@ -130,6 +134,29 @@
         t = Tool(FindTool(DEF_C_COMPILERS))
         t(env)
 
+    # F77 compiler
+    if len(env['f77_opt']) > 0:
+        try:
+            if len(env['f77_opt_path']) > 0:
+                # XXX: what is the right way to add one directory in the
+                # PATH ? (may not work on windows).
+                t = Tool(env['f77_opt'])
+                t(env) 
+                if sys.platform == 'win32':
+                    env['ENV']['PATH'] += ';%s' % env['f77_opt_path']
+                else:
+                    env['ENV']['PATH'] += ':%s' % env['f77_opt_path']
+        except EnvironmentError, e:
+            # scons could not understand cc_opt (bad name ?)
+            raise AssertionError("SCONS: Could not initialize tool ? Error is %s" % \
+                                 str(e))
+    else:
+        t = Tool(FindTool(DEF_FORTRAN_COMPILERS))
+        t(env)
+
+    # XXX: really have to understand how fortran compilers work in scons...
+    env['F77'] = env['_FORTRAND']
+
     # XXX: Really, we should use our own subclass of Environment, instead of
     # adding Numpy* functions !
 
@@ -157,8 +184,7 @@
     # according to scons, don't ask me why, but this does not work as expected
     # for this tool.
     if not env['cc_opt'] == 'mingw':
-        for i in [DEF_LINKERS, DEF_CXX_COMPILERS, DEF_ASSEMBLERS, 
-                  DEF_FORTRAN_COMPILERS]:
+        for i in [DEF_LINKERS, DEF_CXX_COMPILERS, DEF_ASSEMBLERS]:
             t = FindTool(i, env) or i[0]
             Tool(t)(env)
 			



More information about the Numpy-svn mailing list