diff options
author | Pearu Peterson <pearu.peterson@gmail.com> | 2004-02-13 23:25:43 +0000 |
---|---|---|
committer | Pearu Peterson <pearu.peterson@gmail.com> | 2004-02-13 23:25:43 +0000 |
commit | 68569c20c5a8775e4ce0a01260d11e8d28753822 (patch) | |
tree | 6646ca7c132c68311df4a7a8373fb5bf62cbcef2 /scipy_distutils/unixccompiler.py | |
parent | 3317087bc3f28aaebc5e796346e306cbb1828b43 (diff) | |
download | numpy-68569c20c5a8775e4ce0a01260d11e8d28753822.tar.gz |
Using new.instancemethod to override distutils internal methods - this is very robust that avoids using nasty import hacks.
Diffstat (limited to 'scipy_distutils/unixccompiler.py')
-rw-r--r-- | scipy_distutils/unixccompiler.py | 136 |
1 files changed, 50 insertions, 86 deletions
diff --git a/scipy_distutils/unixccompiler.py b/scipy_distutils/unixccompiler.py index fa6a2931a..214763cef 100644 --- a/scipy_distutils/unixccompiler.py +++ b/scipy_distutils/unixccompiler.py @@ -3,99 +3,63 @@ unixccompiler - can handle very long argument lists for ar. """ import os -from distutils import unixccompiler -from distutils.errors import DistutilsExecError, LinkError -from types import StringType, NoneType +import sys +import new -from ccompiler import gen_lib_options, CCompiler -import log -from exec_command import exec_command +from distutils.errors import DistutilsExecError, LinkError, CompileError +from distutils.unixccompiler import * -class UnixCCompiler(unixccompiler.UnixCCompiler): - def _compile(self, obj, src, *args): - log.info('%s: %s' % (os.path.basename(self.compiler_so[0]),src)) - return unixccompiler.UnixCCompiler._compile(self, obj, src, *args) +import log - def spawn(self, cmd): - s,o = exec_command(cmd) - if s: - if type(cmd) is type([]): - cmd = ' '.join(cmd) - raise DistutilsExecError,\ - 'Command "%s" failed with exit status %d' % (cmd, s) +# Note that UnixCCompiler._compile appeared in Python 2.3 +def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): + display = '%s: %s' % (os.path.basename(self.compiler_so[0]),src) + try: + self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + + extra_postargs, display = display) + except DistutilsExecError, msg: + raise CompileError, msg +UnixCCompiler._compile = new.instancemethod(UnixCCompiler__compile, + None, + UnixCCompiler) - def create_static_lib(self, objects, output_libname, - output_dir=None, debug=0, target_lang=None): - objects, output_dir = self._fix_object_args(objects, output_dir) - - output_filename = \ - self.library_filename(output_libname, output_dir=output_dir) - - if self._need_link(objects, output_filename): - self.mkpath(os.path.dirname(output_filename)) - tmp_objects = objects + self.objects - log.info('%s:> %s' % (os.path.basename(self.archiver[0]), - output_filename)) - while tmp_objects: - objects = tmp_objects[:50] - tmp_objects = tmp_objects[50:] - self.spawn(self.archiver + - [output_filename] + - objects) - - # Not many Unices required ranlib anymore -- SunOS 4.x is, I - # think the only major Unix that does. Maybe we need some - # platform intelligence here to skip ranlib if it's not - # needed -- or maybe Python's configure script took care of - # it for us, hence the check for leading colon. - if self.ranlib: - log.info('%s:@ %s' % (os.path.basename(self.ranlib[0]), - output_filename)) - try: - self.spawn(self.ranlib + [output_filename]) - except DistutilsExecError, msg: - raise LibError, msg - else: - log.debug("skipping %s (up-to-date)", output_filename) - def link(self, target_desc, objects, - output_filename, output_dir=None, libraries=None, - library_dirs=None, runtime_library_dirs=None, - export_symbols=None, debug=0, extra_preargs=None, - extra_postargs=None, build_temp=None, target_lang=None): - objects, output_dir = self._fix_object_args(objects, output_dir) - libraries, library_dirs, runtime_library_dirs = \ - self._fix_lib_args(libraries, library_dirs, runtime_library_dirs) +def UnixCCompile_create_static_lib(self, objects, output_libname, + output_dir=None, debug=0, target_lang=None): + objects, output_dir = self._fix_object_args(objects, output_dir) - lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, - libraries) - if type(output_dir) not in (StringType, NoneType): - raise TypeError, "'output_dir' must be a string or None" - if output_dir is not None: - output_filename = os.path.join(output_dir, output_filename) + output_filename = \ + self.library_filename(output_libname, output_dir=output_dir) + + if self._need_link(objects, output_filename): + self.mkpath(os.path.dirname(output_filename)) + tmp_objects = objects + self.objects + while tmp_objects: + objects = tmp_objects[:50] + tmp_objects = tmp_objects[50:] + display = '%s: adding %d object files to %s' % (os.path.basename(self.archiver[0]), + len(objects),output_filename) + self.spawn(self.archiver + [output_filename] + objects, + display = display) - if self._need_link(objects, output_filename): - ld_args = (objects + self.objects + - lib_opts + ['-o', output_filename]) - if debug: - ld_args[:0] = ['-g'] - if extra_preargs: - ld_args[:0] = extra_preargs - if extra_postargs: - ld_args.extend(extra_postargs) - self.mkpath(os.path.dirname(output_filename)) + # Not many Unices required ranlib anymore -- SunOS 4.x is, I + # think the only major Unix that does. Maybe we need some + # platform intelligence here to skip ranlib if it's not + # needed -- or maybe Python's configure script took care of + # it for us, hence the check for leading colon. + if self.ranlib: + display = '%s:@ %s' % (os.path.basename(self.ranlib[0]), + output_filename) try: - if target_desc == CCompiler.EXECUTABLE: - linker = self.linker_exe[:] - else: - linker = self.linker_so[:] - if target_lang == "c++" and self.compiler_cxx: - linker[0] = self.compiler_cxx[0] - log.info('%s:> %s' % (os.path.basename(linker[0]), - output_filename)) - self.spawn(linker + ld_args) + self.spawn(self.ranlib + [output_filename], + display = display) except DistutilsExecError, msg: - raise LinkError, msg - else: - log.debug("skipping %s (up-to-date)", output_filename) + raise LibError, msg + else: + log.debug("skipping %s (up-to-date)", output_filename) + return + +UnixCCompiler.create_static_lib = \ + new.instancemethod(UnixCCompile_create_static_lib, + None,UnixCCompiler) |