Commits

ariovistus committed 4f800b6

windows tup config

also, pyd extensions weren't building for 3.2. still don't work

  • Participants
  • Parent commits 0721f95

Comments (0)

Files changed (17)

 include_rules
-: $(PYD_FILES) |> $(DC) $(DFLAGS) $(PY27_VERSION) $(PYD_INCLUDE) -lib %f $(DOUT)%o |> pyd27.a 
-: $(PYD_FILES) |> $(DC) $(DFLAGS) $(PY32_VERSION) $(PYD_INCLUDE) -lib %f $(DOUT)%o |> pyd32.a 
+: $(PYD_FILES) |> $(DC) $(DFLAGS) $(PY27_VERSION) $(PYD_INCLUDE) -lib %f $(DOUT)%o |> pyd27.$(LIB)
+: $(PYD_FILES) |> $(DC) $(DFLAGS) $(PY32_VERSION) $(PYD_INCLUDE) -lib %f $(DOUT)%o |> pyd32.$(LIB)
 #DC=gdc
 
 ifeq ($(DC),dmd)
-DVERSION = -version=
-DFLAGS = -unittest -property
-DOUT = -of
-export DOUT
-DINCLUDE = -I
-DC_LIB = -L-l
+    DVERSION = -version=
+    DFLAGS = -unittest -property
+    DOUT = -of
+    DINCLUDE = -I
+    DC_LIB = -L-l
 else
 ifeq ($(DC),ldc2)
-DVERSION = -d-version=
-DOUT = -of 
-DINCLUDE = -I
-DC_LIB = -L-l
+    DVERSION = -d-version=
+    DOUT = -of 
+    DINCLUDE = -I
+    DC_LIB = -L-l
 else
 ifeq ($(DC),gdc)
-# todo
-DVERSION = -version=
-DOUT = -o 
-DINCLUDE = -I
-DC_LIB = -l
+    # todo
+    DVERSION = -version=
+    DOUT = -o 
+    DINCLUDE = -I
+    DC_LIB = -l
 endif
 endif
 endif
 PY32_VERSION += $(DVERSION)Python_3_1_Or_Later 
 PY32_VERSION += $(DVERSION)Python_3_2_Or_Later 
 
-PY24_LIB = $(DC_LIB)python2.4
-PY25_LIB = $(DC_LIB)python2.5
-PY26_LIB = $(DC_LIB)python2.6
-PY27_LIB = $(DC_LIB)python2.7
-PY32_LIB = $(DC_LIB)python3.2mu
 
 TOPDIR = $(TUP_CWD)
-PYD_FILES += $(TOPDIR)/infrastructure/deimos/python/*.d
-PYD_FILES += $(TOPDIR)/infrastructure/pyd/*.d
-PYD_FILES += $(TOPDIR)/infrastructure/meta/*.d
-PYD_FILES += $(TOPDIR)/infrastructure/util/*.d
 
-PYD_INCLUDE = $(DINCLUDE)$(TOPDIR)/infrastructure
+ifeq (@(TUP_PLATFORM),win32)
+    LIB = lib
+    OBJ = obj
+    EXE = exe
+    S = \\
+
+    LIBS_24 += $(TOPDIR)\infrastructure\python\python24_digitalmars.lib
+    LIBS_25 += $(TOPDIR)\infrastructure\python\python25_digitalmars.lib
+    LIBS_26 += $(TOPDIR)\infrastructure\python\python26_digitalmars.lib
+    LIBS_27 += $(TOPDIR)\infrastructure\python\python27_digitalmars.lib
+    LIBS_32 += $(TOPDIR)\infrastructure\python\python32_digitalmars.lib
+
+    PY24_VERSION += $(DVERSION)Python_Unicode_UCS2
+    PY25_VERSION += $(DVERSION)Python_Unicode_UCS2
+    PY26_VERSION += $(DVERSION)Python_Unicode_UCS2
+    PY27_VERSION += $(DVERSION)Python_Unicode_UCS2
+    PY32_VERSION += $(DVERSION)Python_Unicode_UCS2
+
+    RM = del
+else
+    LIB = a
+    OBJ = o
+    EXE = x
+    S = /
+    LIBS_24 += $(DC_LIB)python2.4
+    LIBS_25 += $(DC_LIB)python2.5
+    LIBS_26 += $(DC_LIB)python2.6
+    LIBS_27 += $(DC_LIB)python2.7
+    LIBS_32 += $(DC_LIB)python3.2mu
+
+    RM = rm -f
+endif
+LIBS_24 += $(TOPDIR)$(S)pyd24.$(LIB)
+LIBS_25 += $(TOPDIR)$(S)pyd25.$(LIB)
+LIBS_26 += $(TOPDIR)$(S)pyd26.$(LIB)
+LIBS_27 += $(TOPDIR)$(S)pyd27.$(LIB)
+LIBS_32 += $(TOPDIR)$(S)pyd32.$(LIB)
+PYD_FILES += $(TOPDIR)$(S)infrastructure$(S)deimos$(S)python$(S)*.d
+PYD_FILES += $(TOPDIR)$(S)infrastructure$(S)pyd$(S)*.d
+PYD_FILES += $(TOPDIR)$(S)infrastructure$(S)meta$(S)*.d
+PYD_FILES += $(TOPDIR)$(S)infrastructure$(S)util$(S)*.d
+
+PYD_INCLUDE = $(DINCLUDE)$(TOPDIR)$(S)infrastructure
 
 #dc_py24
 #dc_py25
 #dc_py26
-!dc_py27 = | $(TOPDIR)/pyd27.a |> $(DC) $(DFLAGS) $(PY27_VERSION) $(PY27_LIB) $(PYD_INCLUDE) %f $(TOPDIR)/pyd27.a -of%o && rm -f %B.o |> %B.x
-!dc_py32 = | $(TOPDIR)/pyd32.a |> $(DC) $(DFLAGS) $(PY32_VERSION) $(PY32_LIB) $(PYD_INCLUDE) %f $(TOPDIR)/pyd32.a -of%o && rm -f %B.o |> %B.x
+!dc_py27 = | $(TOPDIR)$(S)pyd27.$(LIB) |> $(DC) $(DFLAGS) $(PY27_VERSION) $(PYD_INCLUDE) %f $(LIBS_27) -of%o && $(RM) %B.$(OBJ) |> %B.$(EXE)
+!dc_py32 = | $(TOPDIR)$(S)pyd32.$(LIB) |> $(DC) $(DFLAGS) $(PY32_VERSION) $(PYD_INCLUDE) %f $(LIBS_32) -of%o && $(RM) %B.$(OBJ) |> %B.$(EXE)
 #dc_py32
 

build_manifest.py

     if pathsubs[0] == 'infrastructure':
         if pathsubs == ['infrastructure','pyd','LICENSE']:
             return True
+        if pathsubs == ['infrastructure','d','python_dll_def.def_template']:
+            return True
         if pathsubs == ['infrastructure','python','python.d']:
             return False
         if ext.lower() == '.d':
 
 _infraDir = os.path.join(os.path.dirname(__file__), 'infrastructure')
 
-from pyd_support import make_pydmain, make_pyddef
+from celerid.pyd_support import make_pydmain, make_pyddef
 
 _pydFiles = [
     'class_wrap.d',
     'ctor_wrap.d',
     'def.d',
+    'embedded.d',
     'exception.d',
     'extra.d',
     'func_wrap.d',
 _pyVerXDotY = '.'.join(str(v) for v in sys.version_info[:2]) # e.g., '2.4'
 _pyVerXY = _pyVerXDotY.replace('.', '') # e.g., '24'
 
+def spawn0(self, cmdElements):
+    import platform
+    if platform.python_version() < "2.6":
+        eval("""
+        try:
+            self.spawn(cmdElements)
+        except DistutilsExecError, msg:
+            raise CompileError(msg)
+        """)
+    else:
+        try:
+            self.spawn(cmdElements)
+        except DistutilsExecError as msg:
+            raise CompileError(msg)
 
 class DCompiler(cc.CCompiler):
 
 
     def _initialize(self):
         # It is intended that this method be implemented by subclasses.
-        raise NotImplementedError, "Cannot initialize DCompiler, use DMDDCompiler or GDCDCompiler instead."
+        raise NotImplementedError( "Cannot initialize DCompiler, use DMDDCompiler or GDCDCompiler instead.")
 
     def _def_file(self, output_dir, output_filename):
         """A list of options used to tell the linker how to make a dll/so. In
         DMD, it is the .def file. In GDC, it is
         ['-shared', '-Wl,-soname,blah.so'] or similar."""
-        raise NotImplementedError, "Cannot initialize DCompiler, use DMDDCompiler or GDCDCompiler instead."
+        raise NotImplementedError( "Cannot initialize DCompiler, use DMDDCompiler or GDCDCompiler instead.")
 
     def _lib_file(self, libraries):
         return ''
         #     // Do it the hard way...
         #   }
         def pvo(opt):
+            optf = 'Python_%d_%d_Or_Later'
+            def pv2(minor):
+                return [opt % 'PydPythonExtension'] + [opt % (optf % (2,m)) for m in range(4,minor+1)]
+            def pv3(minor):
+                return [opt % 'PydPythonExtension'] + [opt % (optf % (3,m)) for m in range(0,minor+1)]
             major = sys.version_info[0]
             minor = sys.version_info[1]
-            optf = 'Python_%d_%d_Or_Later'
-            return [opt % 'PydPythonExtension'] + [opt % (optf % (major,m)) for m in range(4,minor+1)]
-
+            if major == 2: return pv2(minor)
+            if major == 3: return  pv2(7) + pv3(minor)
+            assert False, "what python version is this, anyways?"
             
         pythonVersionOpts = pvo(self._versionOpt) 
 
         else:
             optimizationOpts = self._defaultOptimizeOpts
 
-        print 'sources: ', [os.path.basename(s) for s, t in sources]
+        print ('sources: %s' % ([os.path.basename(s) for s, t in sources],))
 
         objFiles = []
         for source, source_type in sources:
                 [_qp(source)] + extra_postargs
             )
             cmdElements = [el for el in cmdElements if el]
-            try:
-                self.spawn(cmdElements)
-            except DistutilsExecError, msg:
-                raise CompileError(msg)
+            spawn0(self,cmdElements)
         return objFiles
 
     def link (self,
             output_filename = os.path.join(output_dir, output_filename)
         else:
             if not output_filename:
-                raise DistutilsFileError, 'Neither output_dir nor' \
-                    ' output_filename was specified.'
+                raise DistutilsFileError( 'Neither output_dir nor' \
+                    ' output_filename was specified.')
             output_dir = os.path.dirname(output_filename)
             if not output_dir:
-                raise DistutilsFileError, 'Unable to guess output_dir on the'\
-                    ' bases of output_filename "%s" alone.' % output_filename
+                raise DistutilsFileError( 'Unable to guess output_dir on the'\
+                    ' bases of output_filename "%s" alone.' % output_filename)
 
         # Format the output filename option
         # (-offilename in DMD, -o filename in GDC)
             os.makedirs(output_dir)
 
         if not self._need_link(objects, output_filename):
-            print "All binary output files are up to date."
+            print ("All binary output files are up to date.")
             return
 
         # The .def file (on Windows) or -shared and -soname (on Linux)
             )
 
         # Library linkage options
-        print "library_dirs:", library_dirs
-        print "runtime_library_dirs:", runtime_library_dirs
-        print "libraries:", libraries
+        print ("library_dirs: %s" % (library_dirs,))
+        print ("runtime_library_dirs: %s" % (runtime_library_dirs,))
+        print ("libraries: %s"% (libraries,))
         libOpts = gen_lib_options(self, library_dirs, runtime_library_dirs, libraries)
 
         # Optimization opts
         )
         cmdElements = [el for el in cmdElements if el]
 
-        try:
-            self.spawn(cmdElements)
-        except DistutilsExecError, msg:
-            raise CompileError(msg)
+        spawn0(self,cmdElements)
 
 class DMDDCompiler(DCompiler):
     compiler_type = 'dmd'

examples/deimos_unittests/Tupfile

 include_rules
 
-: foreach *.d |> !dc_py27 |>
+: foreach *.d |> !dc_py32 |>

examples/hello/hello.d

File contents unchanged.

examples/hello/test.py

     '.'.join(str(v) for v in sys.version_info[:2])
 ))
 sys.path.append(os.path.abspath(libDir))
-print sys.path
+print (sys.path)
 use = "1" 
 if use == "1":
     import hello
     elif use == 'both':
         hello.hello()
         hello2.hello()
-except Exception, e:
-    print e
-    print e.__dict__
+except Exception as e:
+    print (e)
+    print (e.__dict__)
 

examples/misc/dmd_sharedlibs/Tupfile

 
 include_rules
+ifeq (@(TUP_PLATFORM),win32)
+else
 BITSI = 32
 ifeq ($(BITSI),32)
 DMD_M=-m32
 : test3lib.c |> $(GCC) -fPIC -shared %f -o %o |> libtest3.so
 
 : test3.d libtest3.so |> $(DMD) test3.d -L$(TUP_CWD)/libtest3.so -of%o && rm test3.o |> test3.x
+endif

examples/misc/ldc_sharedlibs/Tupfile

 include_rules
 
+ifeq (@(TUP_PLATFORM),win32)
+# Windows not supported by LDC
+else
+# Linuxen
+
 LDC = ldc2
 LIBS= -Wl,--no-as-needed -lphobos-ldc -ldruntime-ldc -lrt -lpthread -ldl -lm -lpython2.7
 
 : test3lib.c |> gcc -fPIC -shared %f -o %o |> libtest3.so
 
 : test3.o libtest3.so |> $(LDC) test3.o -L$(TUP_CWD)/libtest3.so -of %o |> test3.x
+
+endif

examples/pyind/build.ps1

 
 $DC = @("-unittest", "-property", "-debug")
 
-$PYTHON_2_7 = @(
+$PYTHON_2_7_VERSION = @(
             "-version=Python_2_7_Or_Later",
             "-version=Python_2_6_Or_Later",
             "-version=Python_2_5_Or_Later",
-	        "-version=Python_2_4_Or_Later",
-            "-version=Python_Unicode_UCS2",
-	        "..\..\infrastructure\python/python27_digitalmars.lib")
+            "-version=Python_2_4_Or_Later",
+            "-version=Python_Unicode_UCS2")
+$PYTHON_2_7 = $PYTHON_2_7_VERSION 
+$PYTHON_2_7 += @(
+            "..\..\infrastructure\python\python27_digitalmars.lib")
+
+$PYTHON_3_2 = $PYTHON_2_7_VERSION
+$PYTHON_3_2 += @(
+            "-version=Python_3_0_Or_Later",
+            "-version=Python_3_1_Or_Later",
+            "-version=Python_3_2_Or_Later",
+            "..\..\infrastructure\python\python32_digitalmars.lib")
 $PYD_FILES = ls ../../infrastructure/pyd/ *.d -recurse | foreach-object { $_.FullName } 
 $PYD_FILES += ls ../../infrastructure/meta/ *.d -recurse | foreach-object { $_.FullName } 
 $PYD_FILES += ls ../../infrastructure/util/ *.d -recurse | foreach-object { $_.FullName } 
+$PYD_FILES += ls ../../infrastructure/deimos/ *.d -recurse | foreach-object { $_.FullName } 
 $args = $DC + $PYTHON_2_7 + $PYD_FILES + @("pyind.d","-I..\..\infrastructure\", "-ofpyind.exe")
-. "dmd" $args
+#. "dmd" $args
 
+
+$args3 = $DC + $PYTHON_3_2 + $PYD_FILES + @("pyind3.d","-I..\..\infrastructure\", "-ofpyind3.exe")
+echo "dmd $args3"
+. "dmd" $args3
+

infrastructure/d/pydmain_template.d

 
 extern(C) void PydMain();
 
-extern(C)
-export void init%(modulename)s() {
-    pyd.exception.exception_catcher(delegate void() {
-        pyd.def.pyd_module_name = "%(modulename)s";
-        PydMain();
-    });
-}
+version(Python_3_0_Or_Later) {
+    import deimos.python.Python;
+    pragma(msg, "in here!");
+    extern(C) export PyObject* PyInit_%(modulename)s() {
+        return pyd.exception.exception_catcher(delegate PyObject*() {
+                pyd.def.pyd_module_name = "%(modulename)s";
+                PydMain();
+                return pyd.def.pyd_modules[""];
+                });
+    }
+}else version(Python_2_4_Or_Later) {
+    extern(C) export void init%(modulename)s() {
+        pyd.exception.exception_catcher(delegate void() {
+                pyd.def.pyd_module_name = "%(modulename)s";
+                PydMain();
+                });
+    }
+}else static assert(false);
 
 extern(C) void _Dmain(){
     // make druntime happy

infrastructure/deimos/python/object.d

 import deimos.python.structmember;
 import deimos.python.descrobject;
 
-pragma(msg, "lookie!");
-
 extern(C):
 // Python-header-file: Include/object.h:
 

infrastructure/pyd/def.d

 version(Python_3_0_Or_Later) {
     private PyModuleDef*[string] pyd_moduledefs;
 }
-private PyObject*[string] pyd_modules;
+PyObject*[string] pyd_modules;
 
 private void delegate()[string][string] pyd_module_classes;
 
 
 /// For embedding python
 void py_init() {
+    version(PydPythonExtension) assert(false, "py_init should only be called when embedding python");
     foreach(action; before_py_init_deferred_actions) {
         action();
     }
         modl.m_size = -1;
         modl.m_methods = module_methods[""].ptr;
 
+        Py3_ModuleInit!"".func();
     }else {
         pyd_modules[""] = Py_INCREF(Py_InitModule3((name ~ "\0"), 
                     module_methods[""].ptr, (docstring ~ "\0")));

infrastructure/pyd/make_object.d

File contents unchanged.

infrastructure/python/python32_digitalmars.lib

Binary file added.

patch_distutils.py

     elif compiler == 'gdc':
         return dcompiler.GDCDCompiler(None, dry_run, force)
     else:
-        raise RuntimeError, "Couldn't get a compiler..."
+        raise RuntimeError("Couldn't get a compiler...")
 
 cc.new_compiler = new_compiler
 
 from distutils.errors import DistutilsPlatformError
 import sys
-from dcompiler import _infraDir
+from celerid.dcompiler import _infraDir
 import os.path
 
 def make_pydmain(outputFile, projname):
         raise DistutilsFileError('Required def template file "%s" is'
             ' missing.' % defTemplatePath
         )
-    f = open(defTemplatePath, 'rb')
+    f = open(defTemplatePath)
     try:
         defTemplate = f.read()
     finally:
         f.close()
     defFileContent = defTemplate % projname
-    f = file(outputFile, 'wb')
+    f = open(outputFile, 'w')
     try:
         f.write(defFileContent)
     finally: