Commits

Armin Rigo committed 1d66408

Fixes. It's a bit hacking-until-it-works, but well, it seems to work :-/

  • Participants
  • Parent commits 3d6567a

Comments (0)

Files changed (3)

File cffi/ffiplatform.py

 def compile(tmpdir, ext):
     """Compile a C extension module using distutils."""
 
+    # Turn the 'ext.sources' into absolute paths, because we're going to
+    # do chdir().  In the common case where the path is precisely where
+    # we're going to chdir(), then replace it with a pathless copy.
+    for i, src in enumerate(ext.sources):
+        src = os.path.abspath(src)
+        if os.path.samefile(os.path.dirname(src), tmpdir):
+            src = os.path.basename(src)
+        ext.sources[i] = src
+
     saved_environ = os.environ.copy()
     saved_path = os.getcwd()
     try:

File cffi/verifier.py

 from . import __version__
 
 
-_TMPDIR = '__pycache__'
-
-def set_tmpdir(dirname):
-    """Set the temporary directory to use instead of __pycache__."""
-    global _TMPDIR
-    _TMPDIR = dirname
-
-def cleanup_tmpdir(keep_so=False):
-    """Clean up the temporary directory by removing all files in it
-    called `_cffi_*.{c,so}` as well as the `build` subdirectory."""
-    try:
-        filelist = os.listdir(_TMPDIR)
-    except OSError:
-        return
-    if keep_so:
-        suffix = '.c'   # only remove .c files
-    else:
-        suffix = _get_so_suffix().lower()
-    for fn in filelist:
-        if fn.lower().startswith('_cffi_') and (
-                fn.lower().endswith(suffix) or fn.lower().endswith('.c')):
-            try:
-                os.unlink(os.path.join(_TMPDIR, fn))
-            except OSError:
-                pass
-    shutil.rmtree(os.path.join(_TMPDIR, 'build'), ignore_errors=True)
-
-def _get_so_suffix():
-    for suffix, mode, type in imp.get_suffixes():
-        if type == imp.C_EXTENSION:
-            return suffix
-    raise ffiplatform.VerificationError("no C_EXTENSION available")
-
-def _ensure_dir(filename):
-    try:
-        os.makedirs(os.path.dirname(filename))
-    except OSError:
-        pass
-
-# ____________________________________________________________
-
 class Verifier(object):
     _status = '?'
 
     def get_extension(self):
         if self._status == 'init':
             self._write_source()
-        sourcename = os.path.abspath(self.sourcefilename)
+        sourcename = self.sourcefilename
         modname = self.get_module_name()
         return ffiplatform.get_extension(sourcename, modname, **self.kwds)
 
 
 /**********/
 '''
+
+# ____________________________________________________________
+
+_TMPDIR = '__pycache__'
+
+def set_tmpdir(dirname):
+    """Set the temporary directory to use instead of __pycache__."""
+    global _TMPDIR
+    _TMPDIR = dirname
+
+def cleanup_tmpdir(keep_so=False):
+    """Clean up the temporary directory by removing all files in it
+    called `_cffi_*.{c,so}` as well as the `build` subdirectory."""
+    try:
+        filelist = os.listdir(_TMPDIR)
+    except OSError:
+        return
+    if keep_so:
+        suffix = '.c'   # only remove .c files
+    else:
+        suffix = _get_so_suffix().lower()
+    for fn in filelist:
+        if fn.lower().startswith('_cffi_') and (
+                fn.lower().endswith(suffix) or fn.lower().endswith('.c')):
+            try:
+                os.unlink(os.path.join(_TMPDIR, fn))
+            except OSError:
+                pass
+    clean_dir = [os.path.join(_TMPDIR, 'build')]
+    for dir in clean_dir:
+        try:
+            for fn in os.listdir(dir):
+                fn = os.path.join(dir, fn)
+                if os.path.isdir(fn):
+                    clean_dir.append(fn)
+                else:
+                    os.unlink(fn)
+        except OSError:
+            pass
+
+def _get_so_suffix():
+    for suffix, mode, type in imp.get_suffixes():
+        if type == imp.C_EXTENSION:
+            return suffix
+    raise ffiplatform.VerificationError("no C_EXTENSION available")
+
+def _ensure_dir(filename):
+    try:
+        os.makedirs(os.path.dirname(filename))
+    except OSError:
+        pass

File testing/test_zdistutils.py

     v = ffi.verifier
     ext = v.get_extension()
     assert str(ext.__class__) == 'distutils.extension.Extension'
-    assert ext.sources == [os.path.abspath(v.sourcefilename)]
+    assert ext.sources == [v.sourcefilename]
     assert ext.name == v.get_module_name()
     assert ext.define_macros == [('TEST_EXTENSION_OBJECT', '1')]