Commits

ariovistus committed e101797 Merge

the 'whatever, just work' merge commit

Comments (0)

Files changed (6)

 import os, os.path, sys
 
 from distutils import ccompiler as cc
+from distutils.sysconfig import get_config_var 
 from distutils.ccompiler import gen_lib_options
 from distutils.errors import (
     DistutilsExecError, DistutilsFileError, DistutilsPlatformError,
         return stdout.strip()
     else:
         return path_
+
+def is_posix_static_python():
+    if (sys.platform == "win32" or 
+       sys.platform[:6] == "cygwin"):
+        return False
+    else:
+        return not get_config_var('Py_ENABLE_SHARED')
+def posix_static_python_opts():
+    ls = [l for l in get_config_var('LIBS').split(' ') if l]
+    ls.extend([l for l in get_config_var('MODLIBS').split(' ') if l])
+    return ls
+
+def posix_static_python_lib():
+    return os.path.join(get_config_var('LIBPL'),get_config_var('LIBRARY'))
+
 _isPlatWin = sys.platform.lower().startswith('win') or _isPlatCygwin
 
 _infraDir = os.path.join(os.path.dirname(__file__), 'infrastructure')
         # _outputOpts
         self._outputOpts = ['-of%s']
         # _linkOpts
-        self._exeLinkOpts = []
+        if is_posix_static_python():
+            self._exeLinkOpts = ['-L'+l for l in posix_static_python_opts()]
+            self._exeLinkOpts.append(posix_static_python_lib())
+        else:
+            self._exeLinkOpts = []
         self._linkOpts = []
         # _includeOpts
         self._includeOpts = ['-I%s']
         self._compileOpts = ['-fPIC', '-c']
         # _outputOpts
         self._outputOpts = ['-o', '%s']
-        self._exeLinkOpts = []
+        if is_posix_static_python():
+            self._exeLinkOpts = posix_static_python_opts()
+            self._exeLinkOpts.append(posix_static_python_lib())
+        else:
+            self._exeLinkOpts = []
         # _linkOpts
         self._linkOpts = ['-fPIC', '-nostartfiles', '-shared']
         # _includeOpts
         # _outputOpts
         self._outputOpts = ['-of', '%s']
         self._linkOutputOpts = ['-o', '%s']
-        self._exeLinkOpts = []
+        # bloody ubuntu has to make things difficult
+        if is_posix_static_python():
+            self._exeLinkOpts = ['-L'+l for l in posix_static_python_opts()]
+            self._exeLinkOpts.append(posix_static_python_lib())
+        else:
+            self._exeLinkOpts = []
         # _linkOpts
         self._SharedLinkOpts = ['-nostartfiles', '-shared','-Wl,--no-as-needed','-lphobos-ldc','-ldruntime-ldc', '-lrt','-lpthread','-ldl','-lm']
-        self._ExeLinkOpts = []
         # _includeOpts
         self._includeOpts = ['-I', '%s']
         # _versionOpt
             self._linkOpts = self._SharedLinkOpts
         elif target_desc == cc.CCompiler.EXECUTABLE:
             self._binpath = self.executables['linker_exe'][0]
-            self._linkOpts = self._ExeLinkOpts
+            self._linkOpts = self._exeLinkOpts
             self._linkOutputOpts = self._outputOpts
         else:
             raise LinkError('This CCompiler implementation does not know'

examples/deimos_unittests/link.d

 // So test that the dratted thing is working!
 
 unittest {
-    PyObject* p = cast(PyObject*) &PyString_Type;
+    PyObject* p = cast(PyObject*) &PyType_Type;
     assert(p !is null);
     assert(p.ob_type !is null);
     assert(p.ob_type.tp_name !is null);

examples/pyd_unittests/make_object.d

     auto t = Foo1(z);
     auto ix = t[0];
     z = t[1];
-    assert(ix == [0, 1]);
+    import std.conv;
+    assert(ix == [0, 1], to!string(ix));
     assert(equal(z, [2,3,4,5,6,7,8,9]));
 
 }

examples/pyd_unittests/setup.py

     ext_modules=[
         Extension(ext(e), [ext(e)+".d"],
             d_unittest=True,
+            build_deimos=True,
             string_imports = string_imports.get(e, [])
             )
             for e in exts 
 use_parts = set()
 exe_ext = get_config_var("EXE")
 verz_maj = platform.python_version_tuple()[0]
-print "%r" % (verz_maj,), verz_maj == 2
-if verz_maj == "3":
-    pass
-elif verz_maj == "2":
+print ("%r" % (verz_maj,), verz_maj == 2)
+if verz_maj == "3" or verz_maj == "2":
     import optparse
     oparser = optparse.OptionParser()
     oparser.add_option("-b", action="store_true", dest="use_build")
     old_path = os.getenv("PYTHONPATH")
     if not os.path.exists(build):
         subprocess.check_call([sys.executable, "setup.py", "build"]);
-    print "using build: %r" % build
+    print ("using build: %r" % build)
     os.putenv("PYTHONPATH", build)
 
 def check_exe(cmd):
     if os.path.exists(cmd + exe_ext):
         os.remove(cmd+exe_ext)
 def pydexe():
-    cmds = [sys.executable, "setup.py", "pydexe"]
-    if opts.compiler:
-        cmds.append("--compiler="+opts.compiler)
-    subprocess.check_call(cmds)
+    try:
+        cmds = [sys.executable, "setup.py", "pydexe"]
+        if opts.compiler:
+            cmds.append("--compiler="+opts.compiler)
+        subprocess.check_call(cmds)
+    except:
+        import os
+        print (os.getcwd())
+        raise
 def check_py(scrpt):
     subprocess.check_call([sys.executable, scrpt])
 def pybuild():
         else:
             from distutils import sysconfig
             if sysconfig.get_config_var('Py_ENABLE_SHARED'):
-                template = "python%d.%d"
-                pythonlib = (template %
-                             (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
-                if sys.pydebug:
+                pythonlib = "python{}.{}{}".format(
+                        sys.hexversion >> 24, 
+                        (sys.hexversion >> 16) & 0xff,
+                        '' if not hasattr(sys, 'abiflags') else sys.abiflags)
+                if hasattr(sys,'pydebug') and sys.pydebug:
                     pythonlib += '_d'
                 return ext.libraries + [pythonlib]
             else: