Commits

Maciej Fijalkowski committed 8e0678f

remove translator/platform, kill everything

Comments (0)

Files changed (23)

pypy/module/sys/version.py

 """
 import os
 import re
-from pypy.translator.platform import platform
+from platformer import platform
 from pypy.interpreter import gateway
 
 #XXX # the release serial 42 is not in range(16)

pypy/rpython/lltypesystem/ll2ctypes.py

 from pypy.rpython.llinterp import LLInterpreter, LLException
 from pypy.rpython.lltypesystem.rclass import OBJECT, OBJECT_VTABLE
 from pypy.rpython import raddress
-from pypy.translator.platform import platform
+from platformer import platform
 from array import array
 try:
     from thread import _local as tlsobject

pypy/rpython/tool/rfficache.py

 import py
 import os
 import distutils
-from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from platformer import ExternalCompilationInfo
 from pypy.tool.udir import udir
 from pypy.tool.autopath import pypydir
 from pypy.rlib import rarithmetic

pypy/tool/runsubprocess.py

-"""Run a subprocess.  Wrapper around the 'subprocess' module
-with a hack to prevent bogus out-of-memory conditions in os.fork()
-if the current process already grew very large.
-"""
-
-import sys, gc
-import os
-from subprocess import PIPE, Popen
-
-def run_subprocess(executable, args, env=None, cwd=None):
-    return _run(executable, args, env, cwd)
-
-
-def _run(executable, args, env, cwd):   # unless overridden below
-    if isinstance(args, str):
-        args = str(executable) + ' ' + args
-        shell = True
-    else:
-        if args is None:
-            args = [str(executable)]
-        else:
-            args = [str(executable)] + args
-        shell = False
-    # Just before spawning the subprocess, do a gc.collect().  This
-    # should help if we are running on top of PyPy, if the subprocess
-    # is going to need a lot of RAM and we are using a lot too.
-    gc.collect()
-    #
-    pipe = Popen(args, stdout=PIPE, stderr=PIPE, shell=shell, env=env, cwd=cwd)
-    stdout, stderr = pipe.communicate()
-    return pipe.returncode, stdout, stderr
-
-
-if __name__ == '__main__':
-    import gc
-    while True:
-        gc.collect()
-        operation = sys.stdin.readline()
-        if not operation:
-            sys.exit()
-        assert operation.startswith('(')
-        args = eval(operation)
-        try:
-            results = _run(*args)
-        except EnvironmentError, e:
-            results = (None, str(e))
-        sys.stdout.write('%r\n' % (results,))
-        sys.stdout.flush()
-
-
-if sys.platform != 'win32' and hasattr(os, 'fork'):
-    # do this at import-time, when the process is still tiny
-    _source = os.path.dirname(os.path.abspath(__file__))
-    _source = os.path.join(_source, 'runsubprocess.py')   # and not e.g. '.pyc'
-
-    def spawn_subprocess():
-        global _child
-        _child = Popen([sys.executable, _source], bufsize=0,
-                       stdin=PIPE, stdout=PIPE, close_fds=True)
-    spawn_subprocess()
-
-    def cleanup_subprocess():
-        global _child
-        _child = None
-    import atexit; atexit.register(cleanup_subprocess)
-
-    def _run(*args):
-        try:
-            _child.stdin.write('%r\n' % (args,))
-        except (OSError, IOError):
-            # lost the child.  Try again...
-            spawn_subprocess()
-            _child.stdin.write('%r\n' % (args,))
-        results = _child.stdout.readline()
-        assert results.startswith('(')
-        results = eval(results)
-        if results[0] is None:
-            raise OSError('%s: %s\nargs=%r' % (args[0], results[1], args))
-        return results

pypy/translator/platform/__init__.py

-"""Platform-specific support for compiling/executing C sources."""
-
-import py, os, sys
-
-from pypy.tool.ansi_print import ansi_log
-from pypy.tool.runsubprocess import run_subprocess as _run_subprocess
-from pypy.tool.udir import udir
-
-log = py.log.Producer("platform")
-py.log.setconsumer("platform", ansi_log)
-
-class CompilationError(Exception):
-    def __init__(self, out, err):
-        self.out = out.replace('\r\n', '\n')
-        self.err = err.replace('\r\n', '\n')
-
-    def __repr__(self):
-        if self.err:
-            attr = 'err'
-        else:
-            attr = 'out'
-        text = getattr(self, attr).replace('\n', '\n\t')
-        return 'CompilationError(%s="""\n\t%s""")' % (attr, text)
-
-    __str__ = __repr__
-
-class ExecutionResult(object):
-    def __init__(self, returncode, out, err):
-        self.returncode = returncode
-        self.out = out.replace('\r\n', '\n')
-        self.err = err.replace('\r\n', '\n')
-
-    def __repr__(self):
-        return "<ExecutionResult retcode=%d>" % (self.returncode,)
-
-class Platform(object):
-    name = "abstract platform"
-    c_environ = None
-
-    relevant_environ = ()
-    log_errors = True
-
-    so_prefixes = ('',)
-
-    extra_libs = ()
-
-    def __init__(self, cc):
-        if self.__class__ is Platform:
-            raise TypeError("You should not instantiate Platform class directly")
-        self.cc = cc
-
-    def compile(self, cfiles, eci, outputfilename=None, standalone=True):
-        ofiles = self._compile_o_files(cfiles, eci, standalone)
-        return self._finish_linking(ofiles, eci, outputfilename, standalone)
-
-    def _compile_o_files(self, cfiles, eci, standalone=True):
-        cfiles = [py.path.local(f) for f in cfiles]
-        cfiles += [py.path.local(f) for f in eci.separate_module_files]
-        compile_args = self._compile_args_from_eci(eci, standalone)
-        ofiles = []
-        for cfile in cfiles:
-            # Windows hack: use masm for files ending in .asm
-            if str(cfile).lower().endswith('.asm'):
-                ofiles.append(self._compile_c_file(self.masm, cfile, []))
-            else:
-                ofiles.append(self._compile_c_file(self.cc, cfile, compile_args))
-        return ofiles
-
-    def execute(self, executable, args=None, env=None, compilation_info=None):
-        if env is None:
-            env = os.environ.copy()
-        else:
-            env = env.copy()
-
-        # On Windows, %SystemRoot% must be present for most programs to start
-        if (os.name == 'nt' and
-            "SystemRoot" not in env and
-            "SystemRoot" in os.environ):
-            env["SystemRoot"] = os.environ["SystemRoot"]
-
-        # Set LD_LIBRARY_PATH on posix platforms
-        if os.name == 'posix' and compilation_info is not None:
-            env['LD_LIBRARY_PATH'] = ':'.join(
-                [str(i) for i in compilation_info.library_dirs])
-
-        returncode, stdout, stderr = _run_subprocess(str(executable), args,
-                                                     env)
-        return ExecutionResult(returncode, stdout, stderr)
-
-    def gen_makefile(self, cfiles, eci, exe_name=None, path=None,
-                     shared=False):
-        raise NotImplementedError("Pure abstract baseclass")
-
-    def __repr__(self):
-        return '<%s cc=%s>' % (self.__class__.__name__, self.cc)
-
-    def __hash__(self):
-        return hash(self.__class__.__name__)
-
-    def __ne__(self, other):
-        return not self == other
-
-    def __eq__(self, other):
-        return (self.__class__ is other.__class__ and
-                self.__dict__ == other.__dict__)
-
-    def key(self):
-        bits = [self.__class__.__name__, 'cc=%r' % self.cc]
-        for varname in self.relevant_environ:
-            bits.append('%s=%r' % (varname, os.environ.get(varname)))
-        # adding sys.maxint to disambiguate windows
-        bits.append('%s=%r' % ('sys.maxint', sys.maxint))
-        return ' '.join(bits)
-
-    # some helpers which seem to be cross-platform enough
-
-    def _execute_c_compiler(self, cc, args, outname, cwd=None):
-        log.execute(cc + ' ' + ' '.join(args))
-        # 'cc' can also contain some options for the C compiler;
-        # e.g. it can be "gcc -m32".  We handle it by splitting on ' '.
-        cclist = cc.split()
-        cc = cclist[0]
-        args = cclist[1:] + args
-        returncode, stdout, stderr = _run_subprocess(cc, args, self.c_environ,
-                                                     cwd)
-        self._handle_error(returncode, stdout, stderr, outname)
-
-    def _handle_error(self, returncode, stdout, stderr, outname):
-        if returncode != 0:
-            errorfile = outname.new(ext='errors')
-            errorfile.write(stderr, 'wb')
-            if self.log_errors:
-                stderrlines = stderr.splitlines()
-                for line in stderrlines:
-                    log.Error(line)
-                # ^^^ don't use ERROR, because it might actually be fine.
-                # Also, ERROR confuses lib-python/conftest.py.
-            raise CompilationError(stdout, stderr)
-        else:
-            for line in stderr.splitlines():
-                log.WARNING(line)
-
-    def _make_response_file(self, prefix):
-        """Creates a temporary file with the specified prefix,
-        and returns its name"""
-        # Build unique filename
-        num = 0
-        while 1:
-            response_file = udir.join('%s%i' % (prefix, num))
-            num += 1
-            if not response_file.check():
-                break
-        return response_file
-
-    def preprocess_include_dirs(self, include_dirs):
-        if 'PYPY_LOCALBASE' in os.environ:
-            dirs = list(self._preprocess_include_dirs(include_dirs))
-            return [os.environ['PYPY_LOCALBASE'] + '/include'] + dirs
-        return self._preprocess_include_dirs(include_dirs)
-
-    def _preprocess_include_dirs(self, include_dirs):
-        return include_dirs
-
-    def _compile_args_from_eci(self, eci, standalone):
-        include_dirs = self.preprocess_include_dirs(eci.include_dirs)
-        args = self._includedirs(include_dirs)
-        if standalone:
-            extra = self.standalone_only
-        else:
-            extra = self.shared_only
-        cflags = list(self.cflags) + list(extra)
-        return (cflags + list(eci.compile_extra) + args)
-
-    def preprocess_library_dirs(self, library_dirs):
-        if 'PYPY_LOCALBASE' in os.environ:
-            dirs = list(self._preprocess_library_dirs(library_dirs))
-            return [os.environ['PYPY_LOCALBASE'] + '/lib'] + dirs
-        return self._preprocess_library_dirs(library_dirs)
-
-    def _preprocess_library_dirs(self, library_dirs):
-        return library_dirs
-
-    def _link_args_from_eci(self, eci, standalone):
-        library_dirs = self.preprocess_library_dirs(eci.library_dirs)
-        library_dirs = self._libdirs(library_dirs)
-        libraries = self._libs(eci.libraries)
-        link_files = self._linkfiles(eci.link_files)
-        export_flags = self._exportsymbols_link_flags(eci)
-        return (library_dirs + list(self.link_flags) + export_flags +
-                link_files + list(eci.link_extra) + libraries +
-                list(self.extra_libs))
-
-    def _exportsymbols_link_flags(self, eci, relto=None):
-        if eci.export_symbols:
-            raise ValueError("This platform does not support export symbols")
-        return []
-
-    def _finish_linking(self, ofiles, eci, outputfilename, standalone):
-        if outputfilename is None:
-            outputfilename = ofiles[0].purebasename
-        if ofiles:
-            dirname = ofiles[0].dirpath()
-        else:
-            dirname = udir.join('module_cache')
-        exe_name = dirname.join(outputfilename, abs=True)
-        if standalone:
-            if self.exe_ext:
-                exe_name += '.' + self.exe_ext
-        else:
-            exe_name += '.' + self.so_ext
-        if eci.use_cpp_linker:
-            cc_link = 'g++'      # XXX hard-coded so far
-        else:
-            cc_link = self.cc
-        largs = self._link_args_from_eci(eci, standalone)
-        return self._link(cc_link, ofiles, largs, standalone, exe_name)
-
-    # below are some detailed informations for platforms
-
-    def include_dirs_for_libffi(self):
-        dirs = self._include_dirs_for_libffi()
-        if 'PYPY_LOCALBASE' in os.environ:
-            return [os.environ['PYPY_LOCALBASE'] + '/include'] + dirs
-        return dirs
-
-    def library_dirs_for_libffi(self):
-        dirs = self._library_dirs_for_libffi()
-        if 'PYPY_LOCALBASE' in os.environ:
-            return [os.environ['PYPY_LOCALBASE'] + '/lib'] + dirs
-        return dirs
-
-    def _include_dirs_for_libffi(self):
-        raise NotImplementedError("Needs to be overwritten")
-
-    def _library_dirs_for_libffi(self):
-        raise NotImplementedError("Needs to be overwritten")
-
-    def check___thread(self):
-        return True
-
-
-if sys.platform.startswith('linux'):
-    from pypy.translator.platform.linux import Linux, Linux64
-    import platform
-    if platform.architecture()[0] == '32bit':
-        host_factory = Linux
-    else:
-        host_factory = Linux64
-elif sys.platform == 'darwin':
-    from pypy.translator.platform.darwin import Darwin_i386, Darwin_x86_64, Darwin_PowerPC
-    import platform
-    assert platform.machine() in ('Power Macintosh', 'i386', 'x86_64')
-
-    if  platform.machine() == 'Power Macintosh':
-        host_factory = Darwin_PowerPC
-    elif sys.maxint <= 2147483647:
-        host_factory = Darwin_i386
-    else:
-        host_factory = Darwin_x86_64
-elif "freebsd" in sys.platform:
-    from pypy.translator.platform.freebsd import Freebsd, Freebsd_64
-    import platform
-    if platform.architecture()[0] == '32bit':
-        host_factory = Freebsd
-    else:
-        host_factory = Freebsd_64
-elif "openbsd" in sys.platform:
-    from pypy.translator.platform.openbsd import OpenBSD, OpenBSD_64
-    import platform
-    if platform.architecture()[0] == '32bit':
-        host_factory = OpenBSD
-    else:
-        host_factory = OpenBSD_64
-elif os.name == 'nt':
-    from pypy.translator.platform.windows import Windows, Windows_x64
-    import platform
-    if platform.architecture()[0] == '32bit':
-        host_factory = Windows
-    else:
-        host_factory = Windows_x64
-else:
-    # pray
-    from pypy.translator.platform.distutils_platform import DistutilsPlatform
-    host_factory = DistutilsPlatform
-
-platform = host = host_factory()
-
-def pick_platform(new_platform, cc):
-    if new_platform == 'host':
-        return host_factory(cc)
-    elif new_platform == 'maemo':
-        from pypy.translator.platform.maemo import Maemo
-        return Maemo(cc)
-    elif new_platform == 'distutils':
-        from pypy.translator.platform.distutils_platform import DistutilsPlatform
-        return DistutilsPlatform()
-    else:
-        raise ValueError("platform = %s" % (new_platform,))
-
-def set_platform(new_platform, cc):
-    global platform
-    platform = pick_platform(new_platform, cc)
-    if not platform:
-        raise ValueError("pick_platform(%r, %s) failed"%(new_platform, cc))
-    log.msg("Set platform with %r cc=%s, using cc=%r" % (new_platform, cc,
-                    getattr(platform, 'cc','Unknown')))
-
-    if new_platform == 'host':
-        global host
-        host = platform
-

pypy/translator/platform/darwin.py

-"""Support for OS X."""
-
-import os
-
-from pypy.translator.platform import posix
-
-class Darwin(posix.BasePosix):
-    name = "darwin"
-
-    standalone_only = ('-mdynamic-no-pic',)
-    shared_only = ()
-
-    so_ext = 'dylib'
-
-    # NOTE: With asmgcc GCC 4.2 will fail at runtime due to subtle issues,
-    # possibly related to GC roots. Using LLVM-GCC or Clang will break the
-    # build. On Darwin asmgcc is not the default anymore, so it is fine to use
-    # whatever gcc we find on the system
-
-    def _args_for_shared(self, args):
-        return (list(self.shared_only)
-                + ['-dynamiclib', '-undefined', 'dynamic_lookup']
-                + args)
-    
-    def _include_dirs_for_libffi(self):
-        return ['/usr/include/ffi']
-
-    def _library_dirs_for_libffi(self):
-        return ['/usr/lib']
-
-    def check___thread(self):
-        # currently __thread is not supported by Darwin gccs
-        return False
-
-    def _frameworks(self, frameworks):
-        args = []
-        for f in frameworks:
-            args.append('-framework')
-            args.append(f)
-        return args
-
-    def _link_args_from_eci(self, eci, standalone):
-        args = super(Darwin, self)._link_args_from_eci(eci, standalone)
-        frameworks = self._frameworks(eci.frameworks)
-        include_dirs = self._includedirs(eci.include_dirs)
-        return (args + frameworks + include_dirs)
-
-    def _exportsymbols_link_flags(self, eci, relto=None):
-        if not eci.export_symbols:
-            return []
-
-        response_file = self._make_response_file("dynamic-symbols-")
-        f = response_file.open("w")
-        for sym in eci.export_symbols:
-            f.write("_%s\n" % (sym,))
-        f.close()
-
-        if relto:
-            response_file = relto.bestrelpath(response_file)
-        return ["-Wl,-exported_symbols_list,%s" % (response_file,)]
-
-class Darwin_i386(Darwin):
-    name = "darwin_i386"
-    link_flags = ('-arch', 'i386')
-    cflags = ('-arch', 'i386', '-O3', '-fomit-frame-pointer')
-
-class Darwin_PowerPC(Darwin):#xxx fixme, mwp
-    name = "darwin_powerpc"
-    link_flags = ()
-    cflags = ('-O3', '-fomit-frame-pointer')
-
-class Darwin_x86_64(Darwin):
-    name = "darwin_x86_64"
-    link_flags = ('-arch', 'x86_64')
-    cflags = ('-arch', 'x86_64', '-O3', '-fomit-frame-pointer')

pypy/translator/platform/distutils_platform.py

-import py, os, sys
-
-from pypy.translator.platform import Platform, log, CompilationError
-from pypy.translator.tool import stdoutcapture
-
-def log_spawned_cmd(spawn):
-    def spawn_and_log(cmd, *args, **kwds):
-        log.execute(' '.join(cmd))
-        return spawn(cmd, *args, **kwds)
-    return spawn_and_log
-
-CFLAGS = ['-O3']
-
-if os.name != 'nt':
-    so_ext = 'so'
-else:
-    so_ext = 'dll'
-
-class DistutilsPlatform(Platform):
-    """ This is a generic distutils platform. I hope it'll go away at some
-    point soon completely
-    """
-    name = "distutils"
-    so_ext = so_ext
-    
-    def __init__(self, cc=None):
-        self.cc = cc
-        if self.name == "distutils":
-            self.name = sys.platform
-    
-    def _ensure_correct_math(self):
-        if self.name != 'win32':
-            return # so far
-        from distutils import sysconfig
-        gcv = sysconfig.get_config_vars()
-        opt = gcv.get('OPT') # not always existent
-        if opt and '/Op' not in opt:
-            opt += '/Op'
-        gcv['OPT'] = opt
-    
-    def compile(self, cfilenames, eci, outputfilename=None, standalone=True):
-        self._ensure_correct_math()
-        self.cfilenames = cfilenames
-        if standalone:
-            ext = ''
-        else:
-            ext = so_ext
-        self.standalone = standalone
-        self.libraries = list(eci.libraries)
-        self.include_dirs = list(eci.include_dirs)
-        self.library_dirs = list(eci.library_dirs)
-        self.compile_extra = list(eci.compile_extra)
-        self.link_extra = list(eci.link_extra)
-        self.frameworks = list(eci.frameworks)
-        if not self.name in ('win32', 'darwin'): # xxx
-            if 'm' not in self.libraries:
-                self.libraries.append('m')
-            self.compile_extra += CFLAGS + ['-fomit-frame-pointer']
-            if 'pthread' not in self.libraries:
-                self.libraries.append('pthread')
-            if self.name != 'sunos5': 
-                self.compile_extra += ['-pthread']
-                self.link_extra += ['-pthread']
-            else:
-                self.compile_extra += ['-pthreads']
-                self.link_extra += ['-lpthread']
-        if self.name == 'win32':
-            self.link_extra += ['/DEBUG'] # generate .pdb file
-        if self.name == 'darwin':
-            # support Fink & Darwinports
-            for s in ('/sw/', '/opt/local/'):
-                if s + 'include' not in self.include_dirs and \
-                   os.path.exists(s + 'include'):
-                    self.include_dirs.append(s + 'include')
-                if s + 'lib' not in self.library_dirs and \
-                   os.path.exists(s + 'lib'):
-                    self.library_dirs.append(s + 'lib')
-            self.compile_extra += CFLAGS + ['-fomit-frame-pointer']
-            for framework in self.frameworks:
-                self.link_extra += ['-framework', framework]
-
-        if outputfilename is None:
-            self.outputfilename = py.path.local(cfilenames[0]).new(ext=ext)
-        else:
-            self.outputfilename = py.path.local(outputfilename)
-        self.eci = eci
-        import distutils.errors
-        basename = self.outputfilename.new(ext='')
-        data = ''
-        try:
-            saved_environ = os.environ.copy()
-            c = stdoutcapture.Capture(mixed_out_err = True)
-            try:
-                self._build()
-            finally:
-                # workaround for a distutils bugs where some env vars can
-                # become longer and longer every time it is used
-                for key, value in saved_environ.items():
-                    if os.environ.get(key) != value:
-                        os.environ[key] = value
-                foutput, foutput = c.done()
-                data = foutput.read()
-                if data:
-                    fdump = basename.new(ext='errors').open("wb")
-                    fdump.write(data)
-                    fdump.close()
-        except (distutils.errors.CompileError,
-                distutils.errors.LinkError):
-            raise CompilationError('', data)
-        except:
-            print >>sys.stderr, data
-            raise
-        return self.outputfilename
-
-    def _build(self):
-        from distutils.ccompiler import new_compiler
-        from distutils import sysconfig
-        compiler = new_compiler(force=1)
-        if self.cc is not None:
-            for c in '''compiler compiler_so compiler_cxx
-                        linker_exe linker_so'''.split():
-                compiler.executables[c][0] = self.cc
-        if not self.standalone:
-            sysconfig.customize_compiler(compiler) # XXX
-        compiler.spawn = log_spawned_cmd(compiler.spawn)
-        objects = []
-        for cfile in self.cfilenames:
-            cfile = py.path.local(cfile)
-            compile_extra = self.compile_extra[:]
-            # -frandom-seed is only to try to be as reproducable as possible
-            if 0 and self.fix_gcc_random_seed:
-                compile_extra.append('-frandom-seed=%s' % (cfile.basename,))
-                # XXX horrible workaround for a bug of profiling in gcc on
-                # OS X with functions containing a direct call to fork()
-                if '/*--no-profiling-for-this-file!--*/' in cfile.read():
-                    compile_extra = [arg for arg in compile_extra
-                                     if not arg.startswith('-fprofile-')]
-
-            old = cfile.dirpath().chdir()
-            try:
-                res = compiler.compile([cfile.basename],
-                                       include_dirs=self.eci.include_dirs,
-                                       extra_preargs=compile_extra)
-                assert len(res) == 1
-                cobjfile = py.path.local(res[0])
-                assert cobjfile.check()
-                objects.append(str(cobjfile))
-            finally:
-                old.chdir()
-
-        if self.standalone:
-            cmd = compiler.link_executable
-        else:
-            cmd = compiler.link_shared_object
-        cmd(objects, str(self.outputfilename),
-            libraries=self.eci.libraries,
-            extra_preargs=self.link_extra,
-            library_dirs=self.eci.library_dirs)
-
-    def _include_dirs_for_libffi(self):
-        return ['/usr/include/libffi']
-
-    def _library_dirs_for_libffi(self):
-        return ['/usr/lib/libffi']
-

pypy/translator/platform/freebsd.py

-"""Support for FreeBSD."""
-
-import os
-
-from pypy.translator.platform import posix
-
-def get_env(key, default):
-    if key in os.environ:
-        return os.environ[key]
-    else:
-        return default
-
-def get_env_vector(key, default):
-    string = get_env(key, default)
-    # XXX: handle quotes
-    return string.split()
-
-class Freebsd(posix.BasePosix):
-    name = "freebsd"
-
-    link_flags = ['-pthread'] + get_env_vector('LDFLAGS', '')
-    cflags = ['-O3', '-pthread', '-fomit-frame-pointer'
-             ] + get_env_vector('CFLAGS', '')
-    standalone_only = []
-    shared_only = []
-    so_ext = 'so'
-    make_cmd = 'gmake'
-
-    def __init__(self, cc=None):
-        if cc is None:
-            cc = get_env("CC", "gcc")
-        super(Freebsd, self).__init__(cc)
-
-    def _args_for_shared(self, args):
-        return ['-shared'] + args
-
-    def _preprocess_include_dirs(self, include_dirs):
-        res_incl_dirs = list(include_dirs)
-        res_incl_dirs.append(os.path.join(get_env("LOCALBASE", "/usr/local"), "include"))
-        return res_incl_dirs
-
-    def _preprocess_library_dirs(self, library_dirs):
-        res_lib_dirs = list(library_dirs)
-        res_lib_dirs.append(os.path.join(get_env("LOCALBASE", "/usr/local"), "lib"))
-        return res_lib_dirs
-
-    def _include_dirs_for_libffi(self):
-        return [os.path.join(get_env("LOCALBASE", "/usr/local"), "include")]
-
-    def _library_dirs_for_libffi(self):
-        return [os.path.join(get_env("LOCALBASE", "/usr/local"), "lib")]
-
-class Freebsd_64(Freebsd):
-    shared_only = ('-fPIC',)

pypy/translator/platform/linux.py

-"""Support for Linux."""
-
-import os
-import sys
-from pypy.translator.platform.posix import BasePosix
-
-class BaseLinux(BasePosix):
-    name = "linux"
-    
-    link_flags = tuple(
-                 ['-pthread',]
-                 + os.environ.get('LDFLAGS', '').split())
-    extra_libs = ('-lrt',)
-    cflags = tuple(
-             ['-O3', '-pthread', '-fomit-frame-pointer',
-              '-Wall', '-Wno-unused']
-             + os.environ.get('CFLAGS', '').split())
-    standalone_only = ()
-    shared_only = ('-fPIC',)
-    so_ext = 'so'
-    so_prefixes = ('lib', '')
-    
-    def _args_for_shared(self, args):
-        return ['-shared'] + args
-
-    def _include_dirs_for_libffi(self):
-        return self._pkg_config("libffi", "--cflags-only-I",
-                                ['/usr/include/libffi'])
-
-    def _library_dirs_for_libffi(self):
-        return self._pkg_config("libffi", "--libs-only-L",
-                                ['/usr/lib/libffi'])
-
-    def library_dirs_for_libffi_a(self):
-        # places where we need to look for libffi.a
-        # XXX obscuuure!  only look for libffi.a if run with translate.py
-        if 'translate' in sys.modules:
-            return self.library_dirs_for_libffi() + ['/usr/lib']
-        else:
-            return []
-
-
-class Linux(BaseLinux):
-    shared_only = ()    # it seems that on 32-bit linux, compiling with -fPIC
-                        # gives assembler that asmgcc is not happy about.
-
-class Linux64(BaseLinux):
-    pass

pypy/translator/platform/maemo.py

-"""Support for Maemo."""
-
-import py, os
-
-from pypy.tool.udir import udir
-from pypy.translator.platform import ExecutionResult, log
-from pypy.translator.platform.linux import Linux
-from pypy.translator.platform.posix import GnuMakefile, _run_subprocess
-
-def check_scratchbox():
-    # in order to work, that file must exist and be executable by us
-    if not os.access('/scratchbox/login', os.X_OK):
-        py.test.skip("No scratchbox detected")
-
-class Maemo(Linux):
-    name = "maemo"
-    
-    available_includedirs = ('/usr/include', '/tmp')
-    copied_cache = {}
-
-    def _invent_new_name(self, basepath, base):
-        pth = basepath.join(base)
-        num = 0
-        while pth.check():
-            pth = basepath.join('%s_%d' % (base,num))
-            num += 1
-        return pth.ensure(dir=1)
-
-    def _copy_files_to_new_dir(self, dir_from, pattern='*.[ch]'):
-        try:
-            return self.copied_cache[dir_from]
-        except KeyError:
-            new_dirpath = self._invent_new_name(udir, 'copied_includes')
-            files = py.path.local(dir_from).listdir(pattern)
-            for f in files:
-                f.copy(new_dirpath)
-            # XXX <hack for pypy>
-            srcdir = py.path.local(dir_from).join('src')
-            if srcdir.check(dir=1):
-                target = new_dirpath.join('src').ensure(dir=1)
-                for f in srcdir.listdir(pattern):
-                    f.copy(target)
-            # XXX </hack for pypy>
-            self.copied_cache[dir_from] = new_dirpath
-            return new_dirpath
-    
-    def _preprocess_include_dirs(self, include_dirs):
-        """ Tweak includedirs so they'll be available through scratchbox
-        """
-        res_incl_dirs = []
-        for incl_dir in include_dirs:
-            incl_dir = py.path.local(incl_dir)
-            for available in self.available_includedirs:
-                if incl_dir.relto(available):
-                    res_incl_dirs.append(str(incl_dir))
-                    break
-            else:
-                # we need to copy files to a place where it's accessible
-                res_incl_dirs.append(self._copy_files_to_new_dir(incl_dir))
-        return res_incl_dirs
-    
-    def _execute_c_compiler(self, cc, args, outname):
-        log.execute('/scratchbox/login ' + cc + ' ' + ' '.join(args))
-        args = [cc] + args
-        returncode, stdout, stderr = _run_subprocess('/scratchbox/login', args)
-        self._handle_error(returncode, stdout, stderr, outname)
-    
-    def execute(self, executable, args=[], env=None):
-        if isinstance(args, str):
-            args = str(executable) + ' ' + args
-            log.message('executing /scratchbox/login ' + args)
-        else:
-            args = [str(executable)] + args
-            log.message('executing /scratchbox/login ' + ' '.join(args))
-        returncode, stdout, stderr = _run_subprocess('/scratchbox/login', args,
-                                                     env)
-        return ExecutionResult(returncode, stdout, stderr)
-
-    def _include_dirs_for_libffi(self):
-        # insanely obscure dir
-        return ['/usr/include/arm-linux-gnueabi/']
-
-    def _library_dirs_for_libffi(self):
-        # on the other hand, library lands in usual place...
-        return []
-
-    def execute_makefile(self, path_to_makefile, extra_opts=[]):
-        if isinstance(path_to_makefile, GnuMakefile):
-            path = path_to_makefile.makefile_dir
-        else:
-            path = path_to_makefile
-        log.execute('make %s in %s' % (" ".join(extra_opts), path))
-        returncode, stdout, stderr = _run_subprocess(
-            '/scratchbox/login', ['make', '-C', str(path)] + extra_opts)
-        self._handle_error(returncode, stdout, stderr, path.join('make'))

pypy/translator/platform/openbsd.py

-"""Support for OpenBSD."""
-
-import os
-
-from pypy.translator.platform import posix
-
-def get_env(key, default):
-    if key in os.environ:
-        return os.environ[key]
-    else:
-        return default
-
-def get_env_vector(key, default):
-    string = get_env(key, default)
-    # XXX: handle quotes
-    return string.split()
-
-class OpenBSD(posix.BasePosix):
-    name = "openbsd"
-
-    link_flags = get_env_vector("LDFLAGS", '-pthread')
-    cflags = get_env_vector("CFLAGS", "-O3 -pthread -fomit-frame-pointer -D_BSD_SOURCE")
-    standalone_only = []
-    shared_only = []
-    so_ext = 'so'
-    make_cmd = 'gmake'
-
-    def __init__(self, cc=None):
-        if cc is None:
-            cc = get_env("CC", "gcc")
-        super(OpenBSD, self).__init__(cc)
-
-    def _args_for_shared(self, args):
-        return ['-shared'] + args
-
-    def _preprocess_include_dirs(self, include_dirs):
-        res_incl_dirs = list(include_dirs)
-        res_incl_dirs.append(os.path.join(get_env("LOCALBASE", "/usr/local"), "include"))
-        return res_incl_dirs
-
-    def _preprocess_library_dirs(self, library_dirs):
-        res_lib_dirs = list(library_dirs)
-        res_lib_dirs.append(os.path.join(get_env("LOCALBASE", "/usr/local"), "lib"))
-        return res_lib_dirs
-
-    def _include_dirs_for_libffi(self):
-        return [os.path.join(get_env("LOCALBASE", "/usr/local"), "include")]
-
-    def _library_dirs_for_libffi(self):
-        return [os.path.join(get_env("LOCALBASE", "/usr/local"), "lib")]
-
-    def _libs(self, libraries):
-        libraries=set(libraries + ("intl", "iconv", "compat"))
-        return ['-l%s' % lib for lib in libraries if lib not in ["crypt", "dl", "rt"]]
-
-    def check___thread(self):
-        # currently __thread is not supported by Darwin gccs
-        return False
-
-class OpenBSD_64(OpenBSD):
-    shared_only = ('-fPIC',)

pypy/translator/platform/posix.py

-"""Base support for POSIX-like platforms."""
-
-import py, os
-
-from pypy.tool import autopath
-from pypy.translator.platform import Platform, log, _run_subprocess
-
-class BasePosix(Platform):
-    exe_ext = ''
-    make_cmd = 'make'
-
-    relevant_environ = ('CPATH', 'LIBRARY_PATH', 'C_INCLUDE_PATH')
-
-    def __init__(self, cc=None):
-        if cc is None:
-            try:
-                cc = os.environ['CC']
-            except KeyError:
-                cc = 'gcc'
-        self.cc = cc
-
-    def _libs(self, libraries):
-        return ['-l%s' % lib for lib in libraries]
-
-    def _libdirs(self, library_dirs):
-        return ['-L%s' % ldir for ldir in library_dirs]
-
-    def _includedirs(self, include_dirs):
-        return ['-I%s' % idir for idir in include_dirs]
-
-    def _linkfiles(self, link_files):
-        return list(link_files)
-
-    def _compile_c_file(self, cc, cfile, compile_args):
-        oname = cfile.new(ext='o')
-        args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
-        self._execute_c_compiler(cc, args, oname,
-                                 cwd=str(cfile.dirpath()))
-        return oname
-
-    def _link_args_from_eci(self, eci, standalone):
-        return Platform._link_args_from_eci(self, eci, standalone)
-
-    def _exportsymbols_link_flags(self, eci, relto=None):
-        if not eci.export_symbols:
-            return []
-
-        response_file = self._make_response_file("dynamic-symbols-")
-        f = response_file.open("w")
-        f.write("{\n")
-        for sym in eci.export_symbols:
-            f.write("%s;\n" % (sym,))
-        f.write("};")
-        f.close()
-
-        if relto:
-            response_file = relto.bestrelpath(response_file)
-        return ["-Wl,--export-dynamic,--version-script=%s" % (response_file,)]
-
-    def _link(self, cc, ofiles, link_args, standalone, exe_name):
-        args = [str(ofile) for ofile in ofiles] + link_args
-        args += ['-o', str(exe_name)]
-        if not standalone:
-            args = self._args_for_shared(args)
-        self._execute_c_compiler(cc, args, exe_name,
-                                 cwd=str(exe_name.dirpath()))
-        return exe_name
-
-    def _pkg_config(self, lib, opt, default):
-        try:
-            ret, out, err = _run_subprocess("pkg-config", [lib, opt])
-        except OSError:
-            ret = 1
-        if ret:
-            return default
-        # strip compiler flags
-        return [entry[2:] for entry in out.split()]
-
-    def gen_makefile(self, cfiles, eci, exe_name=None, path=None,
-                     shared=False):
-        cfiles = [py.path.local(f) for f in cfiles]
-        cfiles += [py.path.local(f) for f in eci.separate_module_files]
-
-        if path is None:
-            path = cfiles[0].dirpath()
-
-        pypypath = py.path.local(autopath.pypydir)
-
-        if exe_name is None:
-            exe_name = cfiles[0].new(ext=self.exe_ext)
-        else:
-            exe_name = exe_name.new(ext=self.exe_ext)
-
-        linkflags = list(self.link_flags)
-        if shared:
-            linkflags = self._args_for_shared(linkflags)
-
-        linkflags += self._exportsymbols_link_flags(eci, relto=path)
-
-        if shared:
-            libname = exe_name.new(ext='').basename
-            target_name = 'lib' + exe_name.new(ext=self.so_ext).basename
-        else:
-            target_name = exe_name.basename
-
-        if shared:
-            cflags = self.cflags + self.shared_only
-        else:
-            cflags = self.cflags + self.standalone_only
-
-        m = GnuMakefile(path)
-        m.exe_name = exe_name
-        m.eci = eci
-
-        def pypyrel(fpath):
-            lpath = py.path.local(fpath)
-            rel = lpath.relto(pypypath)
-            if rel:
-                return os.path.join('$(PYPYDIR)', rel)
-            m_dir = m.makefile_dir
-            if m_dir == lpath:
-                return '.'
-            if m_dir.dirpath() == lpath:
-                return '..'
-            return fpath
-
-        rel_cfiles = [m.pathrel(cfile) for cfile in cfiles]
-        rel_ofiles = [rel_cfile[:-2]+'.o' for rel_cfile in rel_cfiles]
-        m.cfiles = rel_cfiles
-
-        rel_includedirs = [pypyrel(incldir) for incldir in
-                           self.preprocess_include_dirs(eci.include_dirs)]
-        rel_libdirs = [pypyrel(libdir) for libdir in
-                       self.preprocess_library_dirs(eci.library_dirs)]
-
-        m.comment('automatically generated makefile')
-        definitions = [
-            ('PYPYDIR', autopath.pypydir),
-            ('TARGET', target_name),
-            ('DEFAULT_TARGET', exe_name.basename),
-            ('SOURCES', rel_cfiles),
-            ('OBJECTS', rel_ofiles),
-            ('LIBS', self._libs(eci.libraries) + list(self.extra_libs)),
-            ('LIBDIRS', self._libdirs(rel_libdirs)),
-            ('INCLUDEDIRS', self._includedirs(rel_includedirs)),
-            ('CFLAGS', cflags),
-            ('CFLAGSEXTRA', list(eci.compile_extra)),
-            ('LDFLAGS', linkflags),
-            ('LDFLAGS_LINK', list(self.link_flags)),
-            ('LDFLAGSEXTRA', list(eci.link_extra)),
-            ('CC', self.cc),
-            ('CC_LINK', eci.use_cpp_linker and 'g++' or '$(CC)'),
-            ('LINKFILES', eci.link_files),
-            ]
-        for args in definitions:
-            m.definition(*args)
-
-        rules = [
-            ('all', '$(DEFAULT_TARGET)', []),
-            ('$(TARGET)', '$(OBJECTS)', '$(CC_LINK) $(LDFLAGSEXTRA) -o $@ $(OBJECTS) $(LIBDIRS) $(LIBS) $(LINKFILES) $(LDFLAGS)'),
-            ('%.o', '%.c', '$(CC) $(CFLAGS) $(CFLAGSEXTRA) -o $@ -c $< $(INCLUDEDIRS)'),
-            ]
-
-        for rule in rules:
-            m.rule(*rule)
-
-        if shared:
-            m.definition('SHARED_IMPORT_LIB', libname),
-            m.definition('PYPY_MAIN_FUNCTION', "pypy_main_startup")
-            m.rule('main.c', '',
-                   'echo "'
-                   'int $(PYPY_MAIN_FUNCTION)(int, char*[]); '
-                   'int main(int argc, char* argv[]) '
-                   '{ return $(PYPY_MAIN_FUNCTION)(argc, argv); }" > $@')
-            m.rule('$(DEFAULT_TARGET)', ['$(TARGET)', 'main.o'],
-                   '$(CC_LINK) $(LDFLAGS_LINK) main.o -L. -l$(SHARED_IMPORT_LIB) -o $@')
-
-        return m
-
-    def execute_makefile(self, path_to_makefile, extra_opts=[]):
-        if isinstance(path_to_makefile, GnuMakefile):
-            path = path_to_makefile.makefile_dir
-        else:
-            path = path_to_makefile
-        log.execute('make %s in %s' % (" ".join(extra_opts), path))
-        returncode, stdout, stderr = _run_subprocess(
-            self.make_cmd, ['-C', str(path)] + extra_opts)
-        self._handle_error(returncode, stdout, stderr, path.join('make'))
-
-class Definition(object):
-    def __init__(self, name, value):
-        self.name = name
-        self.value = value
-
-    def write(self, f):
-        def write_list(prefix, lst):
-            lst = lst or ['']
-            for i, fn in enumerate(lst):
-                fn = fn.replace('\\', '\\\\')
-                print >> f, prefix, fn,
-                if i < len(lst)-1:
-                    print >> f, '\\'
-                else:
-                    print >> f
-                prefix = ' ' * len(prefix)
-        name, value = self.name, self.value
-        if isinstance(value, str):
-            f.write('%s = %s\n' % (name, value.replace('\\', '\\\\')))
-        else:
-            write_list('%s =' % (name,), value)
-        f.write('\n')
-
-class Rule(object):
-    def __init__(self, target, deps, body):
-        self.target = target
-        self.deps   = deps
-        self.body   = body
-
-    def write(self, f):
-        target, deps, body = self.target, self.deps, self.body
-        if isinstance(deps, str):
-            dep_s = deps
-        else:
-            dep_s = ' '.join(deps)
-        f.write('%s: %s\n' % (target, dep_s))
-        if isinstance(body, str):
-            f.write('\t%s\n' % body)
-        elif body:
-            f.write('\t%s\n' % '\n\t'.join(body))
-        f.write('\n')
-
-class Comment(object):
-    def __init__(self, body):
-        self.body = body
-
-    def write(self, f):
-        f.write('# %s\n' % (self.body,))
-
-class GnuMakefile(object):
-    def __init__(self, path=None):
-        self.defs = {}
-        self.lines = []
-        self.makefile_dir = py.path.local(path)
-        
-    def pathrel(self, fpath):
-        if fpath.dirpath() == self.makefile_dir:
-            return fpath.basename
-        elif fpath.dirpath().dirpath() == self.makefile_dir.dirpath():
-            path = '../' + fpath.relto(self.makefile_dir.dirpath())
-            return path.replace('\\', '/')
-        else:
-            return str(fpath)
-
-    def definition(self, name, value):
-        defs = self.defs
-        defn = Definition(name, value)
-        if name in defs:
-            self.lines[defs[name]] = defn
-        else:
-            defs[name] = len(self.lines)
-            self.lines.append(defn)
-
-    def rule(self, target, deps, body):
-        self.lines.append(Rule(target, deps, body))
-
-    def comment(self, body):
-        self.lines.append(Comment(body))
-
-    def write(self, out=None):
-        if out is None:
-            f = self.makefile_dir.join('Makefile').open('w')
-        else:
-            f = out
-        for line in self.lines:
-            line.write(f)
-        f.flush()
-        if out is None:
-            f.close()

pypy/translator/platform/test/__init__.py

Empty file removed.

pypy/translator/platform/test/include/test.h

-#define XXX_STUFF 42

pypy/translator/platform/test/test_darwin.py

-
-""" File containing darwin platform tests
-"""
-
-import py, sys, platform
-if sys.platform != 'darwin':
-    py.test.skip("Darwin only")
-
-from pypy.tool.udir import udir
-from pypy.translator.platform.darwin import Darwin_i386, Darwin_x86_64, Darwin_PowerPC
-from pypy.translator.platform.test.test_platform import TestPlatform as BasicTest
-from pypy.translator.tool.cbuild import ExternalCompilationInfo
-
-if platform.machine() == 'i386':
-    if sys.maxint <= 2147483647:
-        host_factory = Darwin_i386
-    else:
-        host_factory = Darwin_x86_64
-else:
-    host_factory = Darwin_PowerPC
-
-class TestDarwin(BasicTest):
-    platform = host_factory()
-
-    def test_frameworks(self):
-        objcfile = udir.join('test_simple.m')
-        objcfile.write(r'''
-        #import <Foundation/Foundation.h>
-        #include "test.h"
-
-        int main (int argc, const char * argv[]) {
-            NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-            NSArray *args = [[NSProcessInfo processInfo] arguments];
-            NSCountedSet *cset = [[NSCountedSet alloc] initWithArray:args];
-
-            printf("%d\n", XXX_STUFF);
-
-            [cset release];
-            [pool release];
-            return 0;
-        }
-        ''')
-        includedir = py.path.local(__file__).dirpath().join('include')
-        eci = ExternalCompilationInfo(frameworks=('Cocoa',),
-                                      include_dirs=(includedir,))
-        executable = self.platform.compile([objcfile], eci)
-        res = self.platform.execute(executable)
-        self.check_res(res)
-
-    def test_64_32_results(self):
-        if platform.machine() != 'i386':
-            py.test.skip("i386 only")
-        plat32 = Darwin_i386()
-        plat64 = Darwin_x86_64()
-        cfile = udir.join('test_int_size.c')
-        cfile.write(r'''
-        #include <stdio.h>
-        #include <limits.h>
-
-        int main() {
-                printf("%d\n", INT_MAX < LONG_MAX);
-                return 0;
-        }
-        ''')
-        eci = ExternalCompilationInfo()
-        executable = plat32.compile([cfile], eci)
-        res = plat32.execute(executable)
-        self.check_res(res, '0\n')
-        if host_factory == Darwin_x86_64:
-            executable = plat64.compile([cfile], eci)
-            res = plat64.execute(executable)
-            self.check_res(res, '1\n')
-
-    def test_longsize(self):
-        if platform.machine() != 'i386':
-            py.test.skip("i386 only")
-        cfile = udir.join('test_int_size.c')
-        cfile.write(r'''
-        #include <stdio.h>
-        #include <limits.h>
-
-        int main() {
-                printf("%ld\n", LONG_MAX);
-                return 0;
-        }
-        ''')
-        eci = ExternalCompilationInfo()
-        executable = self.platform.compile([cfile], eci)
-        res = self.platform.execute(executable)
-        self.check_res(res, str(sys.maxint) + '\n')
-        
-    def test_32bit_makefile(self):
-        if platform.machine() != 'i386':
-            py.test.skip("i386 only")
-        plat32 = Darwin_i386()
-        plat64 = Darwin_x86_64()
-        eci = ExternalCompilationInfo()
-        cfile_content =r'''
-        #include <stdio.h>
-        #include <limits.h>
-
-        int main() {
-                printf("%d\n", INT_MAX < LONG_MAX);
-                return 0;
-        }
-        '''
-
-        tmpdir = udir.join('32_makefile' + self.__class__.__name__).ensure(dir=1)
-        cfile = tmpdir.join('test_int_size.c')
-        cfile.write(cfile_content)
-        mk = plat32.gen_makefile([cfile], ExternalCompilationInfo(),
-                               path=tmpdir)
-        mk.write()
-        plat32.execute_makefile(mk)
-        res = plat32.execute(tmpdir.join('test_int_size'))
-        self.check_res(res, '0\n')
-        if host_factory == Darwin_x86_64:
-            tmpdir = udir.join('64_makefile' + self.__class__.__name__).ensure(dir=1)
-            cfile = tmpdir.join('test_int_size.c')
-            cfile.write(cfile_content)
-            mk = plat64.gen_makefile([cfile], ExternalCompilationInfo(),
-                                   path=tmpdir)
-            mk.write()
-            plat64.execute_makefile(mk)
-            res = plat64.execute(tmpdir.join('test_int_size'))
-            self.check_res(res, '1\n')
-

pypy/translator/platform/test/test_distutils.py

-
-from pypy.translator.platform.test.test_platform import TestPlatform as BasicTest
-from pypy.translator.platform.distutils_platform import DistutilsPlatform
-import py
-
-class TestDistutils(BasicTest):
-    platform = DistutilsPlatform()
-
-    def test_nice_errors(self):
-        py.test.skip("Unsupported")

pypy/translator/platform/test/test_maemo.py

-
-""" File containing maemo platform tests
-"""
-
-import py
-from pypy.tool.udir import udir
-from pypy.translator.platform.maemo import Maemo, check_scratchbox
-from pypy.translator.platform.test.test_platform import TestPlatform as BasicTest
-from pypy.translator.tool.cbuild import ExternalCompilationInfo
-
-class TestMaemo(BasicTest):
-    platform = Maemo()
-    strict_on_stderr = False
-
-    def setup_class(cls):
-        py.test.skip("TestMaemo: tests skipped for now")
-        check_scratchbox()
-
-    def test_includes_outside_scratchbox(self):
-        cfile = udir.join('test_includes_outside_scratchbox.c')
-        cfile.write('''
-        #include <stdio.h>
-        #include "test.h"
-        int main()
-        {
-            printf("%d\\n", XXX_STUFF);
-            return 0;
-        }
-        ''')
-        includedir = py.path.local(__file__).dirpath().join('include')
-        eci = ExternalCompilationInfo(include_dirs=(includedir,))
-        executable = self.platform.compile([cfile], eci)
-        res = self.platform.execute(executable)
-        self.check_res(res)
-
-    def test_environment_inheritance(self):
-        py.test.skip("FIXME")

pypy/translator/platform/test/test_makefile.py

-
-from pypy.translator.platform.posix import GnuMakefile as Makefile
-from StringIO import StringIO
-import re
-
-def test_simple_makefile():
-    m = Makefile()
-    m.definition('CC', 'xxx')
-    m.definition('XX', ['a', 'b', 'c'])
-    m.rule('x', 'y', 'do_stuff')
-    m.rule('y', 'z', ['a', 'b', 'ced'])
-    s = StringIO()
-    m.write(s)
-    val = s.getvalue()
-    expected_lines = [
-        r'CC += +xxx',
-        r'XX += +a \\\n +b \\\n +c',
-        r'^x: y\n\tdo_stuff',
-        r'^y: z\n\ta\n\tb\n\tced\n']
-    for i in expected_lines:
-        assert re.search(i, val, re.M)
-
-def test_redefinition():
-    m = Makefile()
-    m.definition('CC', 'xxx')
-    m.definition('CC', 'yyy')
-    s = StringIO()
-    m.write(s)
-    val = s.getvalue()
-    assert not re.search('CC += +xxx', val, re.M)
-    assert re.search('CC += +yyy', val, re.M)    

pypy/translator/platform/test/test_platform.py

-
-import py, sys, ctypes, os
-from pypy.tool.udir import udir
-from pypy.translator.platform import CompilationError, Platform
-from pypy.translator.platform import host
-from pypy.translator.tool.cbuild import ExternalCompilationInfo
-
-def test_compilationerror_repr():
-    # compilation error output/stdout may be large, but we don't want
-    # repr to create a limited version
-    c = CompilationError('', '*'*1000)
-    assert repr(c) == 'CompilationError(err="""\n\t%s""")' % ('*'*1000,)
-    c = CompilationError('*'*1000, '')
-    assert repr(c) == 'CompilationError(out="""\n\t%s""")' % ('*'*1000,)
-
-class TestPlatform(object):
-    platform = host
-    strict_on_stderr = True
-    
-    def check_res(self, res, expected='42\n'):
-        assert res.out == expected
-        if self.strict_on_stderr:
-            assert res.err == ''
-        assert res.returncode == 0        
-    
-    def test_simple_enough(self):
-        cfile = udir.join('test_simple_enough.c')
-        cfile.write('''
-        #include <stdio.h>
-        int main()
-        {
-            printf("42\\n");
-            return 0;
-        }
-        ''')
-        executable = self.platform.compile([cfile], ExternalCompilationInfo())
-        res = self.platform.execute(executable)
-        self.check_res(res)
-
-    def test_two_files(self):
-        cfile = udir.join('test_two_files.c')
-        cfile.write('''
-        #include <stdio.h>
-        int func();
-        int main()
-        {
-            printf("%d\\n", func());
-            return 0;
-        }
-        ''')
-        cfile2 = udir.join('implement1.c')
-        cfile2.write('''
-        int func()
-        {
-            return 42;
-        }
-        ''')
-        executable = self.platform.compile([cfile, cfile2], ExternalCompilationInfo())
-        res = self.platform.execute(executable)
-        self.check_res(res)
-
-    def test_nice_errors(self):
-        cfile = udir.join('test_nice_errors.c')
-        cfile.write('')
-        try:
-            executable = self.platform.compile([cfile], ExternalCompilationInfo())
-        except CompilationError, e:
-            filename = cfile.dirpath().join(cfile.purebasename + '.errors')
-            assert filename.read('r') == e.err
-        else:
-            py.test.fail("Did not raise")
-
-    def test_use_eci(self):
-        tmpdir = udir.join('use_eci').ensure(dir=1)
-        hfile = tmpdir.join('needed.h')
-        hfile.write('#define SOMEHASHDEFINE 42\n')
-        eci = ExternalCompilationInfo(include_dirs=[tmpdir])
-        cfile = udir.join('use_eci_c.c')
-        cfile.write('''
-        #include <stdio.h>
-        #include "needed.h"
-        int main()
-        {
-            printf("%d\\n", SOMEHASHDEFINE);
-            return 0;
-        }
-        ''')
-        executable = self.platform.compile([cfile], eci)
-        res = self.platform.execute(executable)
-        self.check_res(res)
-
-    def test_standalone_library(self):
-        tmpdir = udir.join('standalone_library').ensure(dir=1)
-        c_file = tmpdir.join('stand1.c')
-        c_file.write('''
-        #include <math.h>
-        #include <stdio.h>
-
-        int main()
-        {
-            printf("%f\\n", pow(2.0, 2.0));
-        }''')
-        if sys.platform != 'win32':
-            eci = ExternalCompilationInfo(
-                libraries = ['m'],
-                )
-        else:
-            eci = ExternalCompilationInfo()
-        executable = self.platform.compile([c_file], eci)
-        res = self.platform.execute(executable)
-        assert res.out.startswith('4.0')
-
-    def test_environment_inheritance(self):
-        # make sure that environment is inherited
-        cmd = 'import os; print os.environ["_SOME_VARIABLE_%d"]'
-        res = self.platform.execute(sys.executable, ['-c', cmd % 1],
-                                    env={'_SOME_VARIABLE_1':'xyz'})
-        assert 'xyz' in res.out
-        os.environ['_SOME_VARIABLE_2'] = 'zyz'
-        try:
-            res = self.platform.execute('python', ['-c', cmd % 2])
-            assert 'zyz' in res.out
-        finally:
-            del os.environ['_SOME_VARIABLE_2']
-
-    def test_key(self):
-        class XPlatform(Platform):
-            relevant_environ = ['CPATH']
-            
-            def __init__(self):
-                self.cc = 'xcc'
-        x = XPlatform()
-        res = x.key()
-        assert res.startswith("XPlatform cc='xcc' CPATH=")
-
-def test_equality():
-    class X(Platform):
-        def __init__(self):
-            pass
-    class Y(Platform):
-        def __init__(self, x):
-            self.x = x
-
-    assert X() == X()
-    assert Y(3) == Y(3)
-    assert Y(2) != Y(3)

pypy/translator/platform/test/test_posix.py

-
-from pypy.translator.platform import host, CompilationError
-from pypy.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.tool.udir import udir
-from StringIO import StringIO
-import sys, os
-
-def test_echo():
-    res = host.execute('echo', '42 24')
-    assert res.out == '42 24\n'
-
-    if sys.platform == 'win32':
-        # echo is a shell builtin on Windows
-        res = host.execute('cmd', ['/c', 'echo', '42', '24'])
-        assert res.out == '42 24\n'
-    else:
-        res = host.execute('echo', ['42', '24'])
-        assert res.out == '42 24\n'
-
-class TestMakefile(object):
-    platform = host
-    strict_on_stderr = True
-    
-    def test_simple_makefile(self):
-        tmpdir = udir.join('simple_makefile' + self.__class__.__name__).ensure(dir=1)
-        cfile = tmpdir.join('test_simple_enough.c')
-        cfile.write('''
-        #include <stdio.h>
-        int main()
-        {
-            printf("42\\n");
-            return 0;
-        }
-        ''')
-        mk = self.platform.gen_makefile([cfile], ExternalCompilationInfo(),
-                               path=tmpdir)
-        mk.write()
-        self.platform.execute_makefile(mk)
-        res = self.platform.execute(tmpdir.join('test_simple_enough'))
-        assert res.out == '42\n'
-        if self.strict_on_stderr:
-            assert res.err == ''
-        assert res.returncode == 0
-        assert '-lrt' in tmpdir.join("Makefile").read()
-
-    def test_link_files(self):
-        tmpdir = udir.join('link_files' + self.__class__.__name__).ensure(dir=1)
-        eci = ExternalCompilationInfo(link_files=['/foo/bar.a'])
-        mk = self.platform.gen_makefile(['blip.c'], eci, path=tmpdir)
-        mk.write()
-        assert 'LINKFILES = /foo/bar.a' in tmpdir.join('Makefile').read()
-
-    def test_preprocess_localbase(self):
-        tmpdir = udir.join('test_preprocess_localbase').ensure(dir=1)
-        eci = ExternalCompilationInfo()
-        os.environ['PYPY_LOCALBASE'] = '/foo/baz'
-        try:
-            mk = self.platform.gen_makefile(['blip.c'], eci, path=tmpdir)
-            mk.write()
-        finally:
-            del os.environ['PYPY_LOCALBASE']
-        Makefile = tmpdir.join('Makefile').read()
-        assert 'INCLUDEDIRS = -I/foo/baz/include' in Makefile
-        assert 'LIBDIRS = -L/foo/baz/lib' in Makefile
-
-class TestMaemo(TestMakefile):
-    strict_on_stderr = False
-    
-    def setup_class(cls):
-        from pypy.translator.platform.maemo import check_scratchbox, Maemo
-        check_scratchbox()
-        cls.platform = Maemo()

pypy/translator/platform/windows.py

-"""Support for Windows."""
-
-import py, os, sys, re
-
-from pypy.tool import autopath
-from pypy.translator.platform import CompilationError
-from pypy.translator.platform import log, _run_subprocess
-from pypy.translator.platform import Platform, posix
-
-def _get_compiler_type(cc, x64_flag):
-    import subprocess
-    if not cc:
-        cc = os.environ.get('CC','')
-    if not cc:
-        return MsvcPlatform(cc=cc, x64=x64_flag)
-    elif cc.startswith('mingw'):
-        return MingwPlatform(cc)
-    try:
-        subprocess.check_output([cc, '--version'])
-    except:
-        raise ValueError,"Could not find compiler specified by cc option" + \
-                " '%s', it must be a valid exe file on your path"%cc
-    return MingwPlatform(cc)
-
-def Windows(cc=None):
-    return _get_compiler_type(cc, False)
-
-def Windows_x64(cc=None):
-    return _get_compiler_type(cc, True)
-    
-def _get_msvc_env(vsver, x64flag):
-    try:
-        toolsdir = os.environ['VS%sCOMNTOOLS' % vsver]
-    except KeyError:
-        return None
-
-    if x64flag:
-        vsinstalldir = os.path.abspath(os.path.join(toolsdir, '..', '..'))
-        vcinstalldir = os.path.join(vsinstalldir, 'VC')
-        vcbindir = os.path.join(vcinstalldir, 'BIN')
-        vcvars = os.path.join(vcbindir, 'amd64', 'vcvarsamd64.bat')
-    else:
-        vcvars = os.path.join(toolsdir, 'vsvars32.bat')
-
-    import subprocess
-    try:
-        popen = subprocess.Popen('"%s" & set' % (vcvars,),
-                             stdout=subprocess.PIPE,
-                             stderr=subprocess.PIPE)
-
-        stdout, stderr = popen.communicate()
-        if popen.wait() != 0:
-            return None
-    except:
-        return None
-    env = {}
-
-    stdout = stdout.replace("\r\n", "\n")
-    for line in stdout.split("\n"):
-        if '=' not in line:
-            continue
-        key, value = line.split('=', 1)
-        if key.upper() in ['PATH', 'INCLUDE', 'LIB']:
-            env[key.upper()] = value
-    ## log.msg("Updated environment with %s" % (vcvars,))
-    return env
-
-def find_msvc_env(x64flag=False):
-    # First, try to get the compiler which served to compile python
-    msc_pos = sys.version.find('MSC v.')
-    if msc_pos != -1:
-        msc_ver = int(sys.version[msc_pos+6:msc_pos+10])
-        # 1300 -> 70, 1310 -> 71, 1400 -> 80, 1500 -> 90
-        vsver = (msc_ver / 10) - 60
-        env = _get_msvc_env(vsver, x64flag)
-
-        if env is not None:
-            return env
-
-    # Then, try any other version
-    for vsver in (100, 90, 80, 71, 70): # All the versions I know
-        env = _get_msvc_env(vsver, x64flag)
-
-        if env is not None:
-            return env
-    log.error("Could not find a Microsoft Compiler")
-    # Assume that the compiler is already part of the environment
-
-class MsvcPlatform(Platform):
-    name = "msvc"
-    so_ext = 'dll'
-    exe_ext = 'exe'
-    
-    relevant_environ = ('PATH', 'INCLUDE', 'LIB')
-
-    cc = 'cl.exe'
-    link = 'link.exe'
-
-    cflags = ('/MD', '/O2')
-    link_flags = ()
-    standalone_only = ()
-    shared_only = ()
-    environ = None
-    
-    def __init__(self, cc=None, x64=False):
-        self.x64 = x64
-        msvc_compiler_environ = find_msvc_env(x64)
-        Platform.__init__(self, 'cl.exe')
-        if msvc_compiler_environ:
-            self.c_environ = os.environ.copy()
-            self.c_environ.update(msvc_compiler_environ)
-            # XXX passing an environment to subprocess is not enough. Why?
-            os.environ.update(msvc_compiler_environ)
-
-        # detect version of current compiler
-        returncode, stdout, stderr = _run_subprocess(self.cc, '',
-                                                     env=self.c_environ)
-        r = re.match(r'Microsoft.+C/C\+\+.+\s([0-9]+)\.([0-9]+).*', stderr)
-        if r is not None:
-            self.version = int(''.join(r.groups())) / 10 - 60
-        else:
-            # Probably not a msvc compiler...
-            self.version = 0
-
-        # Try to find a masm assembler
-        returncode, stdout, stderr = _run_subprocess('ml.exe', '',
-                                                     env=self.c_environ)
-        r = re.search('Macro Assembler', stderr)
-        if r is None and os.path.exists('c:/masm32/bin/ml.exe'):
-            masm32 = 'c:/masm32/bin/ml.exe'
-            masm64 = 'c:/masm64/bin/ml64.exe'
-        else:
-            masm32 = 'ml.exe'
-            masm64 = 'ml64.exe'
-        
-        if x64:
-            self.masm = masm64
-        else:
-            self.masm = masm32
-
-        # Install debug options only when interpreter is in debug mode
-        if sys.executable.lower().endswith('_d.exe'):
-            self.cflags = ['/MDd', '/Z7', '/Od']
-            self.link_flags = ['/debug']
-
-            # Increase stack size, for the linker and the stack check code.
-            stack_size = 8 << 20  # 8 Mb
-            self.link_flags.append('/STACK:%d' % stack_size)
-            # The following symbol is used in c/src/stack.h
-            self.cflags.append('/DMAX_STACK_SIZE=%d' % (stack_size - 1024))
-
-    def _includedirs(self, include_dirs):
-        return ['/I%s' % (idir,) for idir in include_dirs]
-
-    def _libs(self, libraries):
-        libs = []
-        for lib in libraries:
-            lib = str(lib)
-            if lib.endswith('.dll'):
-                lib = lib[:-4]
-            libs.append('%s.lib' % (lib,))
-        return libs
-
-    def _libdirs(self, library_dirs):
-        return ['/LIBPATH:%s' % (ldir,) for ldir in library_dirs]
-
-    def _linkfiles(self, link_files):
-        return list(link_files)
-
-    def _args_for_shared(self, args):
-        return ['/dll'] + args
-
-    def check___thread(self):
-        # __declspec(thread) does not seem to work when using assembler.
-        # Returning False will cause the program to use TlsAlloc functions.
-        # see src/thread_nt.h
-        return False
-
-    def _link_args_from_eci(self, eci, standalone):
-        # Windows needs to resolve all symbols even for DLLs
-        return super(MsvcPlatform, self)._link_args_from_eci(eci, standalone=True)
-
-    def _exportsymbols_link_flags(self, eci, relto=None):
-        if not eci.export_symbols:
-            return []
-
-        response_file = self._make_response_file("exported_symbols_")
-        f = response_file.open("w")
-        for sym in eci.export_symbols:
-            f.write("/EXPORT:%s\n" % (sym,))
-        f.close()
-
-        if relto:
-            response_file = relto.bestrelpath(response_file)
-        return ["@%s" % (response_file,)]
-
-    def _compile_c_file(self, cc, cfile, compile_args):
-        oname = cfile.new(ext='obj')
-        # notabene: (tismer)
-        # This function may be called for .c but also .asm files.
-        # The c compiler accepts any order of arguments, while
-        # the assembler still has the old behavior that all options
-        # must come first, and after the file name all options are ignored.
-        # So please be careful with the order of parameters! ;-)
-        args = ['/nologo', '/c'] + compile_args + ['/Fo%s' % (oname,), str(cfile)]
-        self._execute_c_compiler(cc, args, oname)
-        return oname
-
-    def _link(self, cc, ofiles, link_args, standalone, exe_name):
-        args = ['/nologo'] + [str(ofile) for ofile in ofiles] + link_args
-        args += ['/out:%s' % (exe_name,), '/incremental:no']
-        if not standalone:
-            args = self._args_for_shared(args)
-
-        if self.version >= 80:
-            # Tell the linker to generate a manifest file
-            temp_manifest = exe_name.dirpath().join(
-                exe_name.purebasename + '.manifest')
-            args += ["/MANIFEST", "/MANIFESTFILE:%s" % (temp_manifest,)]
-
-        self._execute_c_compiler(self.link, args, exe_name)
-
-        if self.version >= 80:
-            # Now, embed the manifest into the program
-            if standalone:
-                mfid = 1
-            else:
-                mfid = 2
-            out_arg = '-outputresource:%s;%s' % (exe_name, mfid)
-            args = ['-nologo', '-manifest', str(temp_manifest), out_arg]
-            self._execute_c_compiler('mt.exe', args, exe_name)
-
-        return exe_name
-
-    def _handle_error(self, returncode, stdout, stderr, outname):
-        if returncode != 0:
-            # Microsoft compilers write compilation errors to stdout
-            stderr = stdout + stderr
-            errorfile = outname.new(ext='errors')
-            errorfile.write(stderr, mode='wb')
-            stderrlines = stderr.splitlines()
-            for line in stderrlines:
-                log.ERROR(line)
-            raise CompilationError(stdout, stderr)
-
-
-    def gen_makefile(self, cfiles, eci, exe_name=None, path=None,
-                     shared=False):
-        cfiles = [py.path.local(f) for f in cfiles]
-        cfiles += [py.path.local(f) for f in eci.separate_module_files]
-
-        if path is None:
-            path = cfiles[0].dirpath()
-
-        pypypath = py.path.local(autopath.pypydir)
-
-        if exe_name is None:
-            exe_name = cfiles[0].new(ext=self.exe_ext)
-        else:
-            exe_name = exe_name.new(ext=self.exe_ext)
-
-        m = NMakefile(path)
-        m.exe_name = exe_name
-        m.eci = eci
-
-        linkflags = list(self.link_flags)
-        if shared:
-            linkflags = self._args_for_shared(linkflags) + [
-                '/EXPORT:$(PYPY_MAIN_FUNCTION)']
-        linkflags += self._exportsymbols_link_flags(eci, relto=path)
-        # Make sure different functions end up at different addresses!
-        # This is required for the JIT.
-        linkflags.append('/opt:noicf')
-
-        if shared:
-            so_name = exe_name.new(purebasename='lib' + exe_name.purebasename,
-                                   ext=self.so_ext)
-            target_name = so_name.basename
-        else:
-            target_name = exe_name.basename
-
-        def pypyrel(fpath):
-            rel = py.path.local(fpath).relto(pypypath)
-            if rel:
-                return os.path.join('$(PYPYDIR)', rel)
-            else:
-                return fpath
-
-        rel_cfiles = [m.pathrel(cfile) for cfile in cfiles]
-        rel_ofiles = [rel_cfile[:rel_cfile.rfind('.')]+'.obj' for rel_cfile in rel_cfiles]
-        m.cfiles = rel_cfiles
-
-        rel_includedirs = [pypyrel(incldir) for incldir in eci.include_dirs]
-
-        m.comment('automatically generated makefile')
-        definitions = [
-            ('PYPYDIR', autopath.pypydir),
-            ('TARGET', target_name),
-            ('DEFAULT_TARGET'