Commit 687b1f10 authored by Tarek Ziadé's avatar Tarek Ziadé

reverting partially distutils to its 2.6.x state so 2.7a4 looks more like the...

reverting partially distutils to its 2.6.x state so 2.7a4 looks more like the 2.7b1 in this. the whole revert will occur after a4 is tagged
parent aac05903
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -21,13 +21,12 @@ handles the EMX port of the GNU C compiler to OS/2.
__revision__ = "$Id$"
import os, sys, copy
from warnings import warn
import os,sys,copy
from distutils.ccompiler import gen_preprocess_options, gen_lib_options
from distutils.unixccompiler import UnixCCompiler
from distutils.file_util import write_file
from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
from distutils.util import get_compiler_versions
from distutils import log
class EMXCCompiler (UnixCCompiler):
......@@ -56,8 +55,8 @@ class EMXCCompiler (UnixCCompiler):
("Reason: %s." % details) +
"Compiling may fail because of undefined preprocessor macros.")
gcc_version, ld_version, dllwrap_version = get_compiler_versions()
self.gcc_version, self.ld_version = gcc_version, ld_version
(self.gcc_version, self.ld_version) = \
get_versions()
self.debug_print(self.compiler_type + ": gcc %s, ld %s\n" %
(self.gcc_version,
self.ld_version) )
......@@ -294,11 +293,23 @@ def get_versions():
""" Try to find out the versions of gcc and ld.
If not possible it returns None for it.
"""
warn("'distutils.emxccompiler.get_versions' is deprecated "
"use 'distutils.util.get_compiler_versions' instead",
DeprecationWarning)
from distutils.version import StrictVersion
from distutils.spawn import find_executable
import re
gcc_exe = find_executable('gcc')
if gcc_exe:
out = os.popen(gcc_exe + ' -dumpversion','r')
out_string = out.read()
out.close()
result = re.search('(\d+\.\d+\.\d+)',out_string)
if result:
gcc_version = StrictVersion(result.group(1))
else:
gcc_version = None
else:
gcc_version = None
# EMX ld has no way of reporting version number, and we use GCC
# anyway - so we can link OMF DLLs
gcc_version, ld_version, dllwrap_version = get_compiler_versions()
return gcc_version, None
ld_version = None
return (gcc_version, ld_version)
......@@ -5,8 +5,13 @@ modules in setup scripts."""
__revision__ = "$Id$"
import os
import warnings
import os, string, sys
from types import *
try:
import warnings
except ImportError:
warnings = None
# This class is really only used by the "build_ext" command, so it might
# make sense to put it in distutils.command.build_ext. However, that
......@@ -78,9 +83,6 @@ class Extension:
language : string
extension language (i.e. "c", "c++", "objc"). Will be detected
from the source extensions if not provided.
optional : boolean
specifies that a build failure in the extension should not abort the
build process, but simply not install the failing extension.
"""
# When adding arguments to this constructor, be sure to update
......@@ -99,14 +101,12 @@ class Extension:
swig_opts = None,
depends=None,
language=None,
optional=None,
**kw # To catch unknown keywords
):
if not isinstance(name, str):
raise AssertionError("'name' must be a string")
if not (isinstance(sources, list) and
all(isinstance(v, str) for v in sources)):
raise AssertionError("'sources' must be a list of strings")
assert type(name) is StringType, "'name' must be a string"
assert (type(sources) is ListType and
map(type, sources) == [StringType]*len(sources)), \
"'sources' must be a list of strings"
self.name = name
self.sources = sources
......@@ -123,28 +123,27 @@ class Extension:
self.swig_opts = swig_opts or []
self.depends = depends or []
self.language = language
self.optional = optional
# If there are unknown keyword options, warn about them
if len(kw) > 0:
options = [repr(option) for option in kw]
options = ', '.join(sorted(options))
msg = "Unknown Extension options: %s" % options
warnings.warn(msg)
def read_setup_file(filename):
"""Reads a Setup file and returns Extension instances."""
warnings.warn('distutils.extensions.read_setup_file is deprecated. '
'It will be removed in the next Python release.')
_sysconfig = __import__('sysconfig')
from distutils.sysconfig import (expand_makefile_vars,
_variable_rx)
if len(kw):
L = kw.keys() ; L.sort()
L = map(repr, L)
msg = "Unknown Extension options: " + string.join(L, ', ')
if warnings is not None:
warnings.warn(msg)
else:
sys.stderr.write(msg + '\n')
# class Extension
def read_setup_file (filename):
from distutils.sysconfig import \
parse_makefile, expand_makefile_vars, _variable_rx
from distutils.text_file import TextFile
from distutils.util import split_quoted
# First pass over the file to gather "VAR = VALUE" assignments.
vars = _sysconfig._parse_makefile(filename)
vars = parse_makefile(filename)
# Second pass to gobble up the real content: lines of the form
# <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
......@@ -164,11 +163,10 @@ def read_setup_file(filename):
file.warn("'%s' lines not handled yet" % line)
continue
with warnings.catch_warnings():
warnings.simplefilter("ignore")
line = expand_makefile_vars(line, vars)
#print "original line: " + line
line = expand_makefile_vars(line, vars)
words = split_quoted(line)
#print "expanded line: " + line
# NB. this parses a slightly different syntax than the old
# makesetup script: here, there must be exactly one extension per
......@@ -197,7 +195,7 @@ def read_setup_file(filename):
elif switch == "-I":
ext.include_dirs.append(value)
elif switch == "-D":
equals = value.find("=")
equals = string.find(value, "=")
if equals == -1: # bare "-DFOO" -- no value
ext.define_macros.append((value, None))
else: # "-DFOO=blah"
......@@ -234,4 +232,15 @@ def read_setup_file(filename):
extensions.append(ext)
#print "module:", module
#print "source files:", source_files
#print "cpp args:", cpp_args
#print "lib args:", library_args
#extensions[module] = { 'sources': source_files,
# 'cpp_args': cpp_args,
# 'lib_args': library_args }
return extensions
# read_setup_file ()
This diff is collapsed.
"""Tests for distutils.cygwinccompiler."""
import unittest
import sys
import os
import warnings
import sysconfig
from test.test_support import check_warnings, run_unittest
from test.test_support import captured_stdout
from distutils import cygwinccompiler
from distutils.cygwinccompiler import (CygwinCCompiler, check_config_h,
CONFIG_H_OK, CONFIG_H_NOTOK,
CONFIG_H_UNCERTAIN, get_versions,
get_msvcr, RE_VERSION)
from distutils.util import get_compiler_versions
from distutils.tests import support
class CygwinCCompilerTestCase(support.TempdirManager,
unittest.TestCase):
def setUp(self):
super(CygwinCCompilerTestCase, self).setUp()
self.version = sys.version
self.python_h = os.path.join(self.mkdtemp(), 'python.h')
self.old_get_config_h_filename = sysconfig.get_config_h_filename
sysconfig.get_config_h_filename = self._get_config_h_filename
def tearDown(self):
sys.version = self.version
sysconfig.get_config_h_filename = self.old_get_config_h_filename
super(CygwinCCompilerTestCase, self).tearDown()
def _get_config_h_filename(self):
return self.python_h
def test_check_config_h(self):
# check_config_h looks for "GCC" in sys.version first
# returns CONFIG_H_OK if found
sys.version = ('2.6.1 (r261:67515, Dec 6 2008, 16:42:21) \n[GCC '
'4.0.1 (Apple Computer, Inc. build 5370)]')
self.assertEquals(check_config_h()[0], CONFIG_H_OK)
# then it tries to see if it can find "__GNUC__" in pyconfig.h
sys.version = 'something without the *CC word'
# if the file doesn't exist it returns CONFIG_H_UNCERTAIN
self.assertEquals(check_config_h()[0], CONFIG_H_UNCERTAIN)
# if it exists but does not contain __GNUC__, it returns CONFIG_H_NOTOK
self.write_file(self.python_h, 'xxx')
self.assertEquals(check_config_h()[0], CONFIG_H_NOTOK)
# and CONFIG_H_OK if __GNUC__ is found
self.write_file(self.python_h, 'xxx __GNUC__ xxx')
self.assertEquals(check_config_h()[0], CONFIG_H_OK)
def test_get_msvcr(self):
# none
sys.version = ('2.6.1 (r261:67515, Dec 6 2008, 16:42:21) '
'\n[GCC 4.0.1 (Apple Computer, Inc. build 5370)]')
self.assertEquals(get_msvcr(), None)
# MSVC 7.0
sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
'[MSC v.1300 32 bits (Intel)]')
self.assertEquals(get_msvcr(), ['msvcr70'])
# MSVC 7.1
sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
'[MSC v.1310 32 bits (Intel)]')
self.assertEquals(get_msvcr(), ['msvcr71'])
# VS2005 / MSVC 8.0
sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
'[MSC v.1400 32 bits (Intel)]')
self.assertEquals(get_msvcr(), ['msvcr80'])
# VS2008 / MSVC 9.0
sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
'[MSC v.1500 32 bits (Intel)]')
self.assertEquals(get_msvcr(), ['msvcr90'])
# unknown
sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
'[MSC v.1999 32 bits (Intel)]')
self.assertRaises(ValueError, get_msvcr)
def test_get_version_deprecated(self):
with check_warnings() as w:
warnings.simplefilter("always")
# make sure get_compiler_versions and get_versions
# returns the same thing
self.assertEquals(get_compiler_versions(), get_versions())
# make sure using get_version() generated a warning
self.assertEquals(len(w.warnings), 1)
# make sure any usage of RE_VERSION will also
# generate a warning, but till works
version = RE_VERSION.search('1.2').group(1)
self.assertEquals(version, '1.2')
self.assertEquals(len(w.warnings), 2)
def test_suite():
return unittest.makeSuite(CygwinCCompilerTestCase)
if __name__ == '__main__':
run_unittest(test_suite())
"""Tests for distutils.emxccompiler."""
import unittest
import sys
import os
import warnings
from test.test_support import check_warnings, run_unittest
from test.test_support import captured_stdout
from distutils.emxccompiler import get_versions
from distutils.util import get_compiler_versions
from distutils.tests import support
class EmxCCompilerTestCase(support.TempdirManager,
unittest.TestCase):
def test_get_version_deprecated(self):
with check_warnings() as w:
warnings.simplefilter("always")
# make sure get_compiler_versions and get_versions
# returns the same gcc
gcc, ld, dllwrap = get_compiler_versions()
emx_gcc, emx_ld = get_versions()
self.assertEquals(gcc, emx_gcc)
# make sure using get_version() generated a warning
self.assertEquals(len(w.warnings), 1)
def test_suite():
return unittest.makeSuite(EmxCCompilerTestCase)
if __name__ == '__main__':
run_unittest(test_suite())
"""Tests for distutils.extension."""
import os
import sys
import unittest
import warnings
from test.test_support import check_warnings
from distutils.extension import read_setup_file, Extension
from distutils.tests.support import capture_warnings
class ExtensionTestCase(unittest.TestCase):
@capture_warnings
def test_read_setup_file(self):
# trying to read a Setup file
# (sample extracted from the PyGame project)
setup = os.path.join(os.path.dirname(__file__), 'Setup.sample')
exts = read_setup_file(setup)
names = [ext.name for ext in exts]
names.sort()
# here are the extensions read_setup_file should have created
# out of the file
wanted = ['_arraysurfarray', '_camera', '_numericsndarray',
'_numericsurfarray', 'base', 'bufferproxy', 'cdrom',
'color', 'constants', 'display', 'draw', 'event',
'fastevent', 'font', 'gfxdraw', 'image', 'imageext',
'joystick', 'key', 'mask', 'mixer', 'mixer_music',
'mouse', 'movie', 'overlay', 'pixelarray', 'pypm',
'rect', 'rwobject', 'scrap', 'surface', 'surflock',
'time', 'transform']
self.assertEquals(names, wanted)
@unittest.skipIf(sys.flags.optimize >= 2,
"Assertions are omitted with -O2 and above")
def test_extension_init_assertions(self):
# The first argument, which is the name, must be a string.
self.assertRaises(AssertionError, Extension, 1, [])
# the second argument, which is the list of files, must
# be a list of strings
self.assertRaises(AssertionError, Extension, 'name', 'file')
self.assertRaises(AssertionError, Extension, 'name', ['file', 1])
def test_extension_init(self):
ext = Extension('name', [])
self.assertEquals(ext.name, 'name')
ext = Extension('name', ['file1', 'file2'])
self.assertEquals(ext.sources, ['file1', 'file2'])
# others arguments have defaults
for attr in ('include_dirs', 'define_macros', 'undef_macros',
'library_dirs', 'libraries', 'runtime_library_dirs',
'extra_objects', 'extra_compile_args', 'extra_link_args',
'export_symbols', 'swig_opts', 'depends'):
self.assertEquals(getattr(ext, attr), [])
self.assertEquals(ext.language, None)
self.assertEquals(ext.optional, None)
# if there are unknown keyword options, warn about them
with check_warnings() as w:
warnings.simplefilter('always')
ext = Extension('name', ['file1', 'file2'], chic=True)
self.assertEquals(len(w.warnings), 1)
self.assertEquals(str(w.warnings[0].message),
"Unknown Extension options: 'chic'")
def test_suite():
return unittest.makeSuite(ExtensionTestCase)
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")
"""Tests for distutils.command.install."""
import os
import os.path
import sys
import unittest
import site
import sysconfig
from sysconfig import (get_scheme_names, _CONFIG_VARS, _INSTALL_SCHEMES,
get_config_var, get_path)
from test.test_support import captured_stdout
from distutils.command.install import install
from distutils.command import install as install_module
from distutils.core import Distribution
from distutils.errors import DistutilsOptionError
from distutils.tests import support
class InstallTestCase(support.TempdirManager,
support.EnvironGuard,
support.LoggingSilencer,
unittest.TestCase):
class InstallTestCase(support.TempdirManager, unittest.TestCase):
def test_home_installation_scheme(self):
# This ensure two things:
......@@ -38,23 +26,9 @@ class InstallTestCase(support.TempdirManager,
build_lib=os.path.join(builddir, "lib"),
)
posix_prefix = _INSTALL_SCHEMES['posix_prefix']
old_posix_prefix = posix_prefix['platinclude']
posix_prefix['platinclude'] = \
'{platbase}/include/python{py_version_short}'
posix_home = _INSTALL_SCHEMES['posix_home']
old_posix_home = posix_home['platinclude']
posix_home['platinclude'] = '{base}/include/python'
try:
cmd = install(dist)
cmd.home = destination
cmd.ensure_finalized()
finally:
posix_home['platinclude'] = old_posix_home
posix_prefix['platinclude'] = old_posix_prefix
cmd = install(dist)
cmd.home = destination
cmd.ensure_finalized()
self.assertEqual(cmd.install_base, destination)
self.assertEqual(cmd.install_platbase, destination)
......@@ -73,143 +47,6 @@ class InstallTestCase(support.TempdirManager,
check_path(cmd.install_scripts, os.path.join(destination, "bin"))
check_path(cmd.install_data, destination)
def test_user_site(self):
# site.USER_SITE was introduced in 2.6
if sys.version < '2.6':
return
# preparing the environement for the test
self.old_user_base = get_config_var('userbase')
self.old_user_site = get_path('purelib', '%s_user' % os.name)
self.tmpdir = self.mkdtemp()
self.user_base = os.path.join(self.tmpdir, 'B')
self.user_site = os.path.join(self.tmpdir, 'S')
_CONFIG_VARS['userbase'] = self.user_base
scheme = _INSTALL_SCHEMES['%s_user' % os.name]
scheme['purelib'] = self.user_site
def _expanduser(path):
if path[0] == '~':
path = os.path.normpath(self.tmpdir) + path[1:]
return path
self.old_expand = os.path.expanduser
os.path.expanduser = _expanduser
try:
# this is the actual test
self._test_user_site()
finally:
_CONFIG_VARS['userbase'] = self.old_user_base
scheme['purelib'] = self.old_user_site
os.path.expanduser = self.old_expand
def _test_user_site(self):
schemes = get_scheme_names()
for key in ('nt_user', 'posix_user', 'os2_home'):
self.assertTrue(key in schemes)
dist = Distribution({'name': 'xx'})
cmd = install(dist)
# making sure the user option is there
options = [name for name, short, lable in
cmd.user_options]
self.assertTrue('user' in options)
# setting a value
cmd.user = 1
# user base and site shouldn't be created yet
self.assertTrue(not os.path.exists(self.user_base))
self.assertTrue(not os.path.exists(self.user_site))
# let's run finalize
cmd.ensure_finalized()
# now they should
self.assertTrue(os.path.exists(self.user_base))
self.assertTrue(os.path.exists(self.user_site))
self.assertTrue('userbase' in cmd.config_vars)
self.assertTrue('usersite' in cmd.config_vars)
def test_handle_extra_path(self):
dist = Distribution({'name': 'xx', 'extra_path': 'path,dirs'})
cmd = install(dist)
# two elements
cmd.handle_extra_path()
self.assertEquals(cmd.extra_path, ['path', 'dirs'])
self.assertEquals(cmd.extra_dirs, 'dirs')
self.assertEquals(cmd.path_file, 'path')
# one element
cmd.extra_path = ['path']
cmd.handle_extra_path()
self.assertEquals(cmd.extra_path, ['path'])
self.assertEquals(cmd.extra_dirs, 'path')
self.assertEquals(cmd.path_file, 'path')
# none
dist.extra_path = cmd.extra_path = None
cmd.handle_extra_path()
self.assertEquals(cmd.extra_path, None)
self.assertEquals(cmd.extra_dirs, '')
self.assertEquals(cmd.path_file, None)
# three elements (no way !)
cmd.extra_path = 'path,dirs,again'
self.assertRaises(DistutilsOptionError, cmd.handle_extra_path)
def test_finalize_options(self):
dist = Distribution({'name': 'xx'})
cmd = install(dist)
# must supply either prefix/exec-prefix/home or
# install-base/install-platbase -- not both
cmd.prefix = 'prefix'
cmd.install_base = 'base'
self.assertRaises(DistutilsOptionError, cmd.finalize_options)
# must supply either home or prefix/exec-prefix -- not both
cmd.install_base = None
cmd.home = 'home'
self.assertRaises(DistutilsOptionError, cmd.finalize_options)
# can't combine user with with prefix/exec_prefix/home or
# install_(plat)base
cmd.prefix = None
cmd.user = 'user'
self.assertRaises(DistutilsOptionError, cmd.finalize_options)
def test_record(self):
install_dir = self.mkdtemp()
pkgdir, dist = self.create_dist()
dist = Distribution()
cmd = install(dist)
dist.command_obj['install'] = cmd
cmd.root = install_dir
cmd.record = os.path.join(pkgdir, 'RECORD')
cmd.ensure_finalized()
cmd.run()
# let's check the RECORD file was created with one
# line (the egg info file)
with open(cmd.record) as f:
self.assertEquals(len(f.readlines()), 1)
def _test_debug_mode(self):
# this covers the code called when DEBUG is set
old_logs_len = len(self.logs)
install_module.DEBUG = True
try:
with captured_stdout() as stdout:
self.test_record()
finally:
install_module.DEBUG = False
self.assertTrue(len(self.logs) > old_logs_len)
def test_suite():
return unittest.makeSuite(InstallTestCase)
......
"""Tests for distutils.unixccompiler."""
import sys
import unittest
import sysconfig
from distutils import sysconfig
from distutils.unixccompiler import UnixCCompiler
class UnixCCompilerTestCase(unittest.TestCase):
......@@ -70,7 +70,7 @@ class UnixCCompilerTestCase(unittest.TestCase):
elif v == 'GNULD':
return 'yes'
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo')
# GCC non-GNULD
sys.platform = 'bar'
......@@ -91,7 +91,7 @@ class UnixCCompilerTestCase(unittest.TestCase):
elif v == 'GNULD':
return 'yes'
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo')
# non-GCC GNULD
......@@ -119,7 +119,7 @@ class UnixCCompilerTestCase(unittest.TestCase):
def gcv(v):
return 'xxx'
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), '-blibpath:/foo')
self.assertEqual(self.cc.rpath_foo(), '-R/foo')
def test_suite():
......
"""Tests for distutils.util."""
import os
import sys
import unittest
from copy import copy
from StringIO import StringIO
import subprocess
from sysconfig import get_config_vars, get_platform
from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError
from distutils.util import (convert_path, change_root,
check_environ, split_quoted, strtobool,
rfc822_escape, get_compiler_versions,
_find_exe_version, _MAC_OS_X_LD_VERSION,
byte_compile)
from distutils import util
from distutils.tests import support
from distutils.version import LooseVersion
from distutils.util import byte_compile
class FakePopen(object):
test_class = None
def __init__(self, cmd, shell, stdout, stderr):
self.cmd = cmd.split()[0]
exes = self.test_class._exes
if self.cmd not in exes:
# we don't want to call the system, returning an empty
# output so it doesn't match
self.stdout = StringIO()
self.stderr = StringIO()
else:
self.stdout = StringIO(exes[self.cmd])
self.stderr = StringIO()
class UtilTestCase(support.EnvironGuard, unittest.TestCase):
def setUp(self):
super(UtilTestCase, self).setUp()
# saving the environment
self.name = os.name
self.platform = sys.platform
self.version = sys.version
self.sep = os.sep
self.join = os.path.join
self.isabs = os.path.isabs
self.splitdrive = os.path.splitdrive
#self._config_vars = copy(sysconfig._config_vars)
# patching os.uname
if hasattr(os, 'uname'):
self.uname = os.uname
self._uname = os.uname()
else:
self.uname = None
self._uname = None
os.uname = self._get_uname
# patching POpen
self.old_find_executable = util.find_executable
util.find_executable = self._find_executable
self._exes = {}
self.old_popen = subprocess.Popen
self.old_stdout = sys.stdout
self.old_stderr = sys.stderr
FakePopen.test_class = self
subprocess.Popen = FakePopen
def tearDown(self):
# getting back the environment
os.name = self.name
sys.platform = self.platform
sys.version = self.version
os.sep = self.sep
os.path.join = self.join
os.path.isabs = self.isabs
os.path.splitdrive = self.splitdrive
if self.uname is not None:
os.uname = self.uname
else:
del os.uname
#sysconfig._config_vars = copy(self._config_vars)
util.find_executable = self.old_find_executable
subprocess.Popen = self.old_popen
sys.old_stdout = self.old_stdout
sys.old_stderr = self.old_stderr
super(UtilTestCase, self).tearDown()
def _set_uname(self, uname):
self._uname = uname
def _get_uname(self):
return self._uname
def test_get_platform(self):
platform = util.get_platform()
self.assertEquals(platform, get_platform())
util.set_platform('MyOwnPlatform')
self.assertEquals('MyOwnPlatform', util.get_platform())
util.set_platform(platform)
def test_convert_path(self):
# linux/mac
os.sep = '/'
def _join(path):
return '/'.join(path)
os.path.join = _join
self.assertEquals(convert_path('/home/to/my/stuff'),
'/home/to/my/stuff')
# win
os.sep = '\\'
def _join(*path):
return '\\'.join(path)
os.path.join = _join
self.assertRaises(ValueError, convert_path, '/home/to/my/stuff')
self.assertRaises(ValueError, convert_path, 'home/to/my/stuff/')
self.assertEquals(convert_path('home/to/my/stuff'),
'home\\to\\my\\stuff')
self.assertEquals(convert_path('.'),
os.curdir)
def test_change_root(self):
# linux/mac
os.name = 'posix'
def _isabs(path):
return path[0] == '/'
os.path.isabs = _isabs
def _join(*path):
return '/'.join(path)
os.path.join = _join
self.assertEquals(change_root('/root', '/old/its/here'),
'/root/old/its/here')
self.assertEquals(change_root('/root', 'its/here'),
'/root/its/here')
# windows
os.name = 'nt'
def _isabs(path):
return path.startswith('c:\\')
os.path.isabs = _isabs
def _splitdrive(path):
if path.startswith('c:'):
return ('', path.replace('c:', ''))
return ('', path)
os.path.splitdrive = _splitdrive
def _join(*path):
return '\\'.join(path)
os.path.join = _join
self.assertEquals(change_root('c:\\root', 'c:\\old\\its\\here'),
'c:\\root\\old\\its\\here')
self.assertEquals(change_root('c:\\root', 'its\\here'),
'c:\\root\\its\\here')
# BugsBunny os (it's a great os)
os.name = 'BugsBunny'
self.assertRaises(DistutilsPlatformError,
change_root, 'c:\\root', 'its\\here')
# XXX platforms to be covered: os2, mac
def test_check_environ(self):
util._environ_checked = 0
if 'HOME' in os.environ:
del os.environ['HOME']
# posix without HOME
if os.name == 'posix': # this test won't run on windows
check_environ()
import pwd
self.assertEquals(os.environ['HOME'], pwd.getpwuid(os.getuid())[5])
else:
check_environ()
self.assertEquals(os.environ['PLAT'], get_platform())
self.assertEquals(util._environ_checked, 1)
def test_split_quoted(self):
self.assertEquals(split_quoted('""one"" "two" \'three\' \\four'),
['one', 'two', 'three', 'four'])
def test_strtobool(self):
yes = ('y', 'Y', 'yes', 'True', 't', 'true', 'True', 'On', 'on', '1')
no = ('n', 'no', 'f', 'false', 'off', '0', 'Off', 'No', 'N')
for y in yes:
self.assertTrue(strtobool(y))
for n in no:
self.assertTrue(not strtobool(n))
def test_rfc822_escape(self):
header = 'I am a\npoor\nlonesome\nheader\n'
res = rfc822_escape(header)
wanted = ('I am a%(8s)spoor%(8s)slonesome%(8s)s'
'header%(8s)s') % {'8s': '\n'+8*' '}
self.assertEquals(res, wanted)
def test_find_exe_version(self):
# the ld version scheme under MAC OS is:
# ^@(#)PROGRAM:ld PROJECT:ld64-VERSION
#
# where VERSION is a 2-digit number for major
# revisions. For instance under Leopard, it's
# currently 77
#
# Dots are used when branching is done.
#
# The SnowLeopard ld64 is currently 95.2.12
for output, version in (('@(#)PROGRAM:ld PROJECT:ld64-77', '77'),
('@(#)PROGRAM:ld PROJECT:ld64-95.2.12',
'95.2.12')):
result = _MAC_OS_X_LD_VERSION.search(output)
self.assertEquals(result.group(1), version)
def _find_executable(self, name):
if name in self._exes:
return name
return None
def test_get_compiler_versions(self):
# get_versions calls distutils.spawn.find_executable on
# 'gcc', 'ld' and 'dllwrap'
self.assertEquals(get_compiler_versions(), (None, None, None))
# Let's fake we have 'gcc' and it returns '3.4.5'
self._exes['gcc'] = 'gcc (GCC) 3.4.5 (mingw special)\nFSF'
res = get_compiler_versions()
self.assertEquals(str(res[0]), '3.4.5')
# and let's see what happens when the version
# doesn't match the regular expression
# (\d+\.\d+(\.\d+)*)
self._exes['gcc'] = 'very strange output'
res = get_compiler_versions()
self.assertEquals(res[0], None)
# same thing for ld
if sys.platform != 'darwin':
self._exes['ld'] = 'GNU ld version 2.17.50 20060824'
res = get_compiler_versions()
self.assertEquals(str(res[1]), '2.17.50')
self._exes['ld'] = '@(#)PROGRAM:ld PROJECT:ld64-77'
res = get_compiler_versions()
self.assertEquals(res[1], None)
else:
self._exes['ld'] = 'GNU ld version 2.17.50 20060824'
res = get_compiler_versions()
self.assertEquals(res[1], None)
self._exes['ld'] = '@(#)PROGRAM:ld PROJECT:ld64-77'
res = get_compiler_versions()
self.assertEquals(str(res[1]), '77')
# and dllwrap
self._exes['dllwrap'] = 'GNU dllwrap 2.17.50 20060824\nFSF'
res = get_compiler_versions()
self.assertEquals(str(res[2]), '2.17.50')
self._exes['dllwrap'] = 'Cheese Wrap'
res = get_compiler_versions()
self.assertEquals(res[2], None)
class UtilTestCase(unittest.TestCase):
def test_dont_write_bytecode(self):
# makes sure byte_compile raise a DistutilsError
......
......@@ -18,6 +18,7 @@ __revision__ = "$Id$"
import os, sys
from types import StringType, NoneType
from distutils import sysconfig
from distutils.dep_util import newer
from distutils.ccompiler import \
CCompiler, gen_preprocess_options, gen_lib_options
......@@ -25,7 +26,6 @@ from distutils.errors import \
DistutilsExecError, CompileError, LibError, LinkError
from distutils import log
# XXX Things not currently handled:
# * optimization/debug/warning flags; we just use whatever's in Python's
# Makefile and live with it. Is this adequate? If not, we might
......@@ -75,7 +75,7 @@ def _darwin_compiler_fixup(compiler_so, cc_args):
if 'ARCHFLAGS' in os.environ and not stripArch:
# User specified different -arch flags in the environ,
# see also the sysconfig
# see also distutils.sysconfig
compiler_so = compiler_so + os.environ['ARCHFLAGS'].split()
if stripSysroot:
......@@ -276,16 +276,13 @@ class UnixCCompiler(CCompiler):
# Linkers on different platforms need different options to
# specify that directories need to be added to the list of
# directories searched for dependencies when a dynamic library
# is sought. GCC on GNU systems (Linux, FreeBSD, ...) has to
# be told to pass the -R option through to the linker, whereas
# other compilers and gcc on other systems just know this.
# is sought. GCC has to be told to pass the -R option through
# to the linker, whereas other compilers just know this.
# Other compilers may need something slightly different. At
# this time, there's no way to determine this information from
# the configuration data stored in the Python installation, so
# we use this hack.
_sysconfig = __import__('sysconfig')
compiler = os.path.basename(_sysconfig.get_config_var("CC"))
compiler = os.path.basename(sysconfig.get_config_var("CC"))
if sys.platform[:6] == "darwin":
# MacOSX's linker doesn't understand the -R flag at all
return "-L" + dir
......@@ -296,22 +293,8 @@ class UnixCCompiler(CCompiler):
elif sys.platform[:7] == "irix646" or sys.platform[:6] == "osf1V5":
return ["-rpath", dir]
elif self._is_gcc(compiler):
# gcc on non-GNU systems does not need -Wl, but can
# use it anyway. Since distutils has always passed in
# -Wl whenever gcc was used in the past it is probably
# safest to keep doing so.
if _sysconfig.get_config_var("GNULD") == "yes":
# GNU ld needs an extra option to get a RUNPATH
# instead of just an RPATH.
return "-Wl,--enable-new-dtags,-R" + dir
else:
return "-Wl,-R" + dir
elif sys.platform[:3] == "aix":
return "-blibpath:" + dir
return "-Wl,-R" + dir
else:
# No idea how --enable-new-dtags would be passed on to
# ld if this system was using GNU ld. Don't know if a
# system like this even exists.
return "-R" + dir
def library_option(self, lib):
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment