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

numpy-svn@scip... numpy-svn@scip...
Mon Sep 24 02:17:03 CDT 2007


Author: cdavid
Date: 2007-09-24 02:16:44 -0500 (Mon, 24 Sep 2007)
New Revision: 4111

Added:
   branches/numpy.scons/.bzrignore
Modified:
   branches/numpy.scons/
   branches/numpy.scons/numpy/distutils/ccompiler.py
   branches/numpy.scons/numpy/distutils/command/build_ext.py
   branches/numpy.scons/numpy/distutils/command/scons.py
   branches/numpy.scons/numpy/distutils/scons/__init__.py
Log:
* Add an option for scons env for tools in non standard path
* Clean and comment more the small scons support library



Property changes on: branches/numpy.scons
___________________________________________________________________
Name: bzr:revision-info
   - timestamp: 2007-09-24 10:59:25.736999989 +0900
committer: david <david@david-laptop>
properties: 
	branch-nick: numpy.scons

   + timestamp: 2007-09-24 16:06:57.940999985 +0900
committer: David Cournapeau <david@ar.media.kyoto-u.ac.jp>
properties: 
	branch-nick: numpy.scons

Name: bzr:file-ids
   - 
   + .bzrignore	bzrignore-20070924070626-ok1qp1327ewhdlvq-1

Name: bzr:revision-id:v3-trunk0
   - 3737 david@david-laptop-20070920080908-n8pj8vmszdir3zoa
3738 david@david-laptop-20070920081509-58kkojgmml3t7jxs
3739 david@david-laptop-20070920081910-phlk1ujthksgpm0z
3740 david@david-laptop-20070920082641-bdhrt6eafeoli50i
3741 david@ar.media.kyoto-u.ac.jp-20070920130730-satdeppbh1k0bq2p
3743 david@ar.media.kyoto-u.ac.jp-20070921073742-vpv8pwv0j8fbd93m
3744 david@david-laptop-20070922101656-61kfi2faucemr2rl
3745 david@david-laptop-20070922113708-ror18thshang1cpu
3747 david@david-laptop-20070922140534-n9xsl096tjrzmct1
3749 david@david-laptop-20070922154007-usit009fr6vp377j
3750 david@david-laptop-20070923070011-leu2ozc2fy1q5cht
3751 david@david-laptop-20070924015925-dhsiao40jp7zsfp9

   + 3737 david@david-laptop-20070920080908-n8pj8vmszdir3zoa
3738 david@david-laptop-20070920081509-58kkojgmml3t7jxs
3739 david@david-laptop-20070920081910-phlk1ujthksgpm0z
3740 david@david-laptop-20070920082641-bdhrt6eafeoli50i
3741 david@ar.media.kyoto-u.ac.jp-20070920130730-satdeppbh1k0bq2p
3743 david@ar.media.kyoto-u.ac.jp-20070921073742-vpv8pwv0j8fbd93m
3744 david@david-laptop-20070922101656-61kfi2faucemr2rl
3745 david@david-laptop-20070922113708-ror18thshang1cpu
3747 david@david-laptop-20070922140534-n9xsl096tjrzmct1
3749 david@david-laptop-20070922154007-usit009fr6vp377j
3750 david@david-laptop-20070923070011-leu2ozc2fy1q5cht
3751 david@david-laptop-20070924015925-dhsiao40jp7zsfp9
3752 david@ar.media.kyoto-u.ac.jp-20070924070657-nbw23j0ayan30cli


Added: branches/numpy.scons/.bzrignore
===================================================================
--- branches/numpy.scons/.bzrignore	2007-09-24 05:56:00 UTC (rev 4110)
+++ branches/numpy.scons/.bzrignore	2007-09-24 07:16:44 UTC (rev 4111)
@@ -0,0 +1,4 @@
+.sconf_temp
+.sconsign.dblite
+build
+config.log

Modified: branches/numpy.scons/numpy/distutils/ccompiler.py
===================================================================
--- branches/numpy.scons/numpy/distutils/ccompiler.py	2007-09-24 05:56:00 UTC (rev 4110)
+++ branches/numpy.scons/numpy/distutils/ccompiler.py	2007-09-24 07:16:44 UTC (rev 4111)
@@ -364,8 +364,6 @@
               ("can't compile C/C++ code: unable to find class '%s' " +
                "in module '%s'") % (class_name, module_name)
     compiler = klass(None, dry_run, force)
-    #print "!!!!!!!!!!!!!!!!!!!!!"
-    #print "compiler class is %s, module_name is %s, compiler %s" % (klass, module_name, compiler.cc_exe)
     log.debug('new_compiler returns %s' % (klass))
     return compiler
 

Modified: branches/numpy.scons/numpy/distutils/command/build_ext.py
===================================================================
--- branches/numpy.scons/numpy/distutils/command/build_ext.py	2007-09-24 05:56:00 UTC (rev 4110)
+++ branches/numpy.scons/numpy/distutils/command/build_ext.py	2007-09-24 07:16:44 UTC (rev 4111)
@@ -77,12 +77,14 @@
                                      dry_run=self.dry_run,
                                      force=self.force)
         print "self.compiler is %s, this gives us %s" % (compiler_type, self.compiler)
+        print self.compiler.compiler
         self.compiler.customize(self.distribution)
+        print self.compiler.compiler
         self.compiler.customize_cmd(self)
+        print self.compiler.compiler
         self.compiler.show_customization()
+        print self.compiler.compiler
 
-        print "======================"
-        print self.compiler.compiler
         # Create mapping of libraries built by build_clib:
         clibs = {}
         if build_clib is not None:

Modified: branches/numpy.scons/numpy/distutils/command/scons.py
===================================================================
--- branches/numpy.scons/numpy/distutils/command/scons.py	2007-09-24 05:56:00 UTC (rev 4110)
+++ branches/numpy.scons/numpy/distutils/command/scons.py	2007-09-24 07:16:44 UTC (rev 4111)
@@ -5,6 +5,7 @@
 #from distutils.core import build_py as old_build_py
 from numpy.distutils.command.build_ext import build_ext as old_build_ext
 from numpy.distutils.ccompiler import CCompiler
+from numpy.distutils.exec_command import find_executable
 
 def dist2sconscc(compiler):
     """This converts the name passed to distutils to scons name convention (C
@@ -14,13 +15,26 @@
         --compiler=intel -> icc."""
     # Geez, why does distutils has no common way to get the compiler name...
     if compiler.compiler_type == 'msvc':
-        #print dir(compiler)
         return 'msvc'
     else:
-        #print dir(compiler)
-        #print compiler.compiler[0]
         return compiler.compiler[0]
 
+def get_compiler_executable(compiler):
+    """For any give CCompiler instance, this gives us the name of C compiler
+    (the actual executable."""
+    # Geez, why does distutils has no common way to get the compiler name...
+    if compiler.compiler_type == 'msvc':
+        return compiler.cc
+    else:
+        return compiler.compiler[0]
+
+def get_tool_path(compiler):
+    """Given a distutils.ccompiler.CCompiler class, returns the path of the
+    toolset related to C compilation."""
+    fullpath_exec = find_executable(get_compiler_executable(compiler))
+    fullpath = pdirname(fullpath_exec)
+    return fullpath
+
 class scons(old_build_ext):
     description = "Scons builder"
     #user_options = []
@@ -36,44 +50,43 @@
         if self.distribution.has_scons_scripts():
             print "Got it: scons scripts are %s" % self.distribution.scons_scripts
             self.scons_scripts = self.distribution.scons_scripts
-        #        build_py = self.get_finalized_command('build_py')
-        print "!!!!!!!!!!!!!!!!!!"
-        #from distutils.ccompiler import get_default_compiler
-        #import sys
-        #import os
-        #print get_default_compiler(sys.platform)
-        #print get_default_compiler(os.name)
-        #from numpy.distutils.ccompiler import compiler_class
-        #print compiler_class
 
-        # Try to get the same compiler than the ones used
+        # Try to get the same compiler than the ones used by distutils: this is
+        # non trivial because distutils and scons have totally different
+        # conventions on this one (distutils uses PATH from user's environment,
+        # whereas scons uses standard locations). The way we do it is once we
+        # got the c compiler used, we use numpy.distutils function to get the
+        # 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
-        # Initialize C compiler:
         from distutils.ccompiler import new_compiler
-        #self.compiler = new_compiler(compiler=compiler_type,
-        #                             verbose=self.verbose,
-        #                             dry_run=self.dry_run,
-        #                             force=self.force)
-        self.compiler = new_compiler(compiler=compiler_type)
+        self.compiler = new_compiler(compiler=compiler_type,
+                                     verbose=self.verbose,
+                                     dry_run=self.dry_run,
+                                     force=self.force)
+        self.compiler.customize(self.distribution)
 
-        print "self.compiler is %s, this gives us %s" % (compiler_type, 
-                                                         dist2sconscc(self.compiler))
-        #print dir(new_compiler(self.compiler))
-        #print new_compiler(self.compiler).compiler
-        #print self.build_temp
-        #print self.build_lib
-        #print self.package
+        #print "++++++++++++++++++++++++++++++++++++++++"
+        #print "self.compiler is %s, this gives us scons tool %s" % (compiler_type, 
+        #                                                 dist2sconscc(self.compiler))
+        #print get_tool_path(self.compiler)
+        #print "++++++++++++++++++++++++++++++++++++++++"
 
     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
         # distutils (this cannot work for recursive scons builds...)
+
+        # XXX: passing everything at command line may cause some trouble where
+        # there is a size limitation ? What is the standard solution in thise
+        # case ?
         for i in self.scons_scripts:
             cmd = "scons -f " + i + ' -I. '
             cmd += ' src_dir=%s ' % pdirname(i)
             cmd += ' distutils_libdir=%s ' % pjoin(self.build_lib, pdirname(i))
             cmd += ' cc_opt=%s ' % dist2sconscc(self.compiler)
-            #print cmd
+            cmd += ' cc_opt_path=%s ' % get_tool_path(self.compiler)
+            print cmd
             st = os.system(cmd)
             if st:
                 print "status is %d" % st

Modified: branches/numpy.scons/numpy/distutils/scons/__init__.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/__init__.py	2007-09-24 05:56:00 UTC (rev 4110)
+++ branches/numpy.scons/numpy/distutils/scons/__init__.py	2007-09-24 07:16:44 UTC (rev 4111)
@@ -6,7 +6,8 @@
 from SCons.Environment import Environment
 from SCons.Script import BuildDir, Help
 
-from SCons.Errors import EnvironmentError
+# XXX: all this should be put in another files eventually once it is getting in
+# shape
 
 def NumpySharedLibrary(env, target, source, *args, **kw):
     """This builder is the same than SharedLibrary, except for the fact that it
@@ -51,6 +52,7 @@
 
     # 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', '')
     return opts
 
 def GetNumpyEnvironment(args):
@@ -68,9 +70,13 @@
         try:
             t = Tool(env['cc_opt'])
             t(env) 
+            if len(env['cc_opt_path']) > 0:
+                # XXX: what is the right way to add one directory in the PATH ?
+                env['ENV']['PATH'] += ':%s' % env['cc_opt_path']
         except EnvironmentError, e:
             # scons could not understand cc_opt (bad name ?)
-            raise AssertionError(e)
+            raise AssertionError("SCONS: Could not initialize tool ? Error is %s" % \
+                                 str(e))
 
     # Adding custom builder
     env['BUILDERS']['NumpySharedLibrary'] = NumpySharedLibrary
@@ -85,8 +91,9 @@
     # Generate help (if calling scons directly during debugging, this could be useful)
     Help(opts.GenerateHelpText(env))
 
-    print "setup.cfg abspath is %s" % pjoin(env['src_dir'], 'setup.cfg')
+    #print "setup.cfg abspath is %s" % pjoin(env['src_dir'], 'setup.cfg')
     return env
 
 def find_config_file(name = 'site.cfg'):
     # According to system_info in 
+    pass



More information about the Numpy-svn mailing list