source: docker/msys/py2exe.patch@ 920:42b14124051b

python3
Last change on this file since 920:42b14124051b was 920:42b14124051b, checked in by István Váradi <ivaradi@…>, 5 years ago

Win 10 Docker image for building the new Python3-based distribution

File size: 31.7 KB
  • py2exe/distutils_buildexe.py

    diff --git a/py2exe/distutils_buildexe.py b/py2exe/distutils_buildexe.py
    index ae8aca3..d809641 100644
    a b class py2exe(Command):  
    154154        self.ascii = 0
    155155        self.custom_boot_script = None
    156156        self.use_assembly = False
     157        self.gi_namespaces = []
    157158
    158159    def finalize_options (self):
    159160        self.optimize = int(self.optimize)
    class py2exe(Command):  
    239240                            excludes = self.excludes,
    240241                            ignores = self.ignores,
    241242                            packages = self.packages,
     243                            gi_namespaces = self.gi_namespaces,
    242244                            dist_dist = self.dist_dir,
    243245                            dll_excludes = self.dll_excludes,
    244246                            typelibs = self.typelibs,
  • py2exe/dllfinder.py

    diff --git a/py2exe/dllfinder.py b/py2exe/dllfinder.py
    index 4e5e76c..bb43f9e 100644
    a b class DllFinder:  
    6868            if dll in self._loaded_dlls:
    6969                continue
    7070            for dep_dll in self.bind_image(dll):
    71                 if dep_dll in self._loaded_dlls:
     71                bname = os.path.basename(dep_dll).lower()
     72                if bname in self._loaded_dlls:
    7273                    continue
    7374                dll_type = self.determine_dll_type(dep_dll)
    7475                if dll_type is None:
    class DllFinder:  
    144145        deps = self.bind_image(imagename)
    145146        if pydll in [d.lower() for d in deps]:
    146147            return "EXT"
    147         if fnm.startswith(windir + os.sep) or fnm.startswith(sysdir + os.sep):
     148        if fnm.startswith(windir + os.sep) or fnm.startswith(sysdir + os.sep) or \
     149           fnm.startswith(windir + '\\') or fnm.startswith(sysdir + '\\'):
    148150            return None
    149151        return "DLL"
    150152
  • py2exe/gihelper.py

    diff --git a/py2exe/gihelper.py b/py2exe/gihelper.py
    index e69de29..f597692 100644
    a b  
     1
     2import cffi
     3
     4class GIHelper(object):
     5    _cdef="""
     6        typedef char gchar;
     7        typedef int gint;
     8        typedef uint32_t guint32;
     9        typedef guint32 GQuark;
     10
     11        typedef struct {
     12          GQuark    domain;
     13          gint      code;
     14          gchar     *message;
     15        } GError;
     16
     17        typedef struct _GITypelib GITypelib;
     18        typedef struct _GIRepository         GIRepository;
     19
     20        typedef enum
     21        {
     22          G_IREPOSITORY_LOAD_FLAG_LAZY = 1
     23        } GIRepositoryLoadFlags;
     24
     25        GIRepository *g_irepository_get_default   (void);
     26
     27        GITypelib *    g_irepository_require       (GIRepository *repository,
     28                               const gchar  *namespace_,
     29                               const gchar  *version,
     30                               GIRepositoryLoadFlags flags,
     31                               GError      **error);
     32
     33        const gchar * g_irepository_get_shared_library (GIRepository *repository,
     34                                const gchar  *namespace_);
     35        """
     36
     37    def __init__(self):
     38        self._ffi = cffi.FFI()
     39        self._ffi.cdef(self._cdef)
     40
     41        self._lib = self._ffi.dlopen("libgirepository-1.0-1.dll")
     42
     43        self._repo=self._lib.g_irepository_get_default()
     44
     45        self._error = self._ffi.new("GError**")
     46
     47    def getSharedLibraries(self, namespace, version):
     48        typelib = self._lib.g_irepository_require(self._repo,
     49                                        bytes(namespace, "utf-8"),
     50                                        bytes(version, "utf-8"),
     51                                        0, self._error)
     52        if typelib == self._ffi.NULL:
     53            return []
     54        else:
     55            return str(
     56                self._ffi.string(
     57                    self._lib.g_irepository_get_shared_library(
     58                        self._repo, bytes(namespace, "utf-8"))), "utf-8").split(",")
  • py2exe/mf3.py

    diff --git a/py2exe/mf3.py b/py2exe/mf3.py
    index f645740..ec1f261 100644
    a b  
    55
    66# XXX XXX XXX Does not yet support PEP 452 namespace packages!
    77
     8from . import gihelper
    89from collections import defaultdict
    910import dis
    1011import importlib
    LOAD_CONST = dis.opname.index('LOAD_CONST')  
    2122IMPORT_NAME = dis.opname.index('IMPORT_NAME')
    2223STORE_NAME = dis.opname.index('STORE_NAME')
    2324STORE_GLOBAL = dis.opname.index('STORE_GLOBAL')
     25LOAD_NAME = dis.opname.index('LOAD_NAME')
     26LOAD_METHOD = dis.opname.index('LOAD_METHOD')
     27CALL_METHOD = dis.opname.index('CALL_METHOD')
    2428STORE_OPS = [STORE_NAME, STORE_GLOBAL]
    2529HAVE_ARGUMENT = dis.HAVE_ARGUMENT
    2630
    class ModuleFinder:  
    6367        self._depgraph = defaultdict(set)
    6468        self._indent = ""
    6569        self._package_paths = defaultdict(list)
    66 
     70        self._gihelper = gihelper.GIHelper()
    6771
    6872    def add_packagepath(self, packagename, path):
    6973        """ModuleFinder can not handle __path__ modifications packages
    class ModuleFinder:  
    416420        We also take note of 'static' global symbols in the module and
    417421        add them to __globalnames__.
    418422        """
    419 
    420423        for what, args in self._scan_opcodes(code):
    421424            if what == "store":
    422425                name, = args
    class ModuleFinder:  
    424427            elif what == "import":
    425428                level, fromlist, name = args
    426429                self.safe_import_hook(name, mod, fromlist, level)
     430            elif what == "gi_request":
     431                for sharedLibrary in \
     432                    self._gihelper.getSharedLibraries(args[0], args[1]):
     433                    from . dllfinder import SearchPath
     434                    self.add_dll(SearchPath(sharedLibrary))
    427435            else:
    428436                # We don't expect anything else from the generator.
    429437                raise RuntimeError(what)
    class ModuleFinder:  
    442450            # dis.get_instructions() is only available in python 3.4
    443451            # and higher
    444452            instructions = []
     453
     454            requireCallLevel = 0
     455            requiredNamespace = None
     456            requiredVersion = None
    445457            for inst in dis.get_instructions(co):
    446458                instructions.append(inst)
    447459                c = inst.opcode
    448460                if c == IMPORT_NAME:
     461                    requireCallLevel = 0
    449462                    assert instructions[-3].opcode == LOAD_CONST
    450463                    level = instructions[-3].argval
    451464                    assert instructions[-2].opcode == LOAD_CONST
    class ModuleFinder:  
    453466                    name = inst.argval
    454467                    yield "import", (level, fromlist, name)
    455468                elif c in STORE_OPS:
     469                    requireCallLevel = 0
    456470                    yield "store", (inst.argval,)
     471                elif c == LOAD_NAME:
     472                    if requireCallLevel==0 and inst.argval=="gi":
     473                        requireCallLevel += 1
     474                    else:
     475                        requireCallLevel = 0
     476                elif c == LOAD_METHOD:
     477                    if requireCallLevel==1 and inst.argval=="require_version":
     478                        requireCallLevel += 1
     479                    else:
     480                        requireCallLevel = 0
     481                elif c==LOAD_CONST:
     482                    if requireCallLevel==2:
     483                        requiredNamespace = inst.argval
     484                        requireCallLevel += 1
     485                    elif requireCallLevel==3:
     486                        requiredVersion = inst.argval
     487                        requireCallLevel += 1
     488                    else:
     489                        requireCallLevel = 0
     490                elif c==CALL_METHOD:
     491                    if requireCallLevel==4:
     492                        yield ("gi_request", (requiredNamespace, requiredVersion))
     493                    requireCallLevel = 0
     494                    requiredNamespace = None
     495                    requiredVersion = None
     496
    457497        else:
    458498            code = co.co_code
    459499            names = co.co_names
  • py2exe/py2exe_distutils.py

    diff --git a/py2exe/py2exe_distutils.py b/py2exe/py2exe_distutils.py
    index 3918849..fe97b90 100644
    a b  
    11# This file is only used when BUILDING py2exe.
    2 import os, sys
     2import os, sys, types, copy
    33
    44from distutils.core import Extension
    55from distutils.dist import Distribution
    from distutils.sysconfig import customize_compiler  
    88from distutils.dep_util import newer_group
    99from distutils.errors import DistutilsError, DistutilsSetupError, DistutilsPlatformError
    1010from distutils.errors import CCompilerError, CompileError
     11from distutils.file_util import write_file
    1112from distutils.util import get_platform
    1213from distutils import log
    1314
    14 # We don't need a manifest in the executable, so monkeypatch the code away:
    15 from distutils.msvc9compiler import MSVCCompiler
    16 MSVCCompiler.manifest_setup_ldargs = lambda *args: None
     15from distutils import ccompiler
     16isMingw32 = ccompiler.get_default_compiler()=='mingw32'
     17
     18if not isMingw32:
     19    # We don't need a manifest in the executable, so monkeypatch the code away:
     20    from distutils.msvc9compiler import MSVCCompiler
     21    MSVCCompiler.manifest_setup_ldargs = lambda *args: None
    1722
    1823class Interpreter(Extension):
    1924    def __init__(self, *args, **kw):
    class Dist(Distribution):  
    3843    def has_extensions(self):
    3944        return False
    4045
     46def mingw32_link(self, target_desc, objects, output_filename, output_dir=None,
     47             libraries=None, library_dirs=None, runtime_library_dirs=None,
     48             export_symbols=None, debug=0, extra_preargs=None,
     49             extra_postargs=None, build_temp=None, target_lang=None):
     50    """Link the objects."""
     51    from distutils.unixccompiler import UnixCCompiler
     52
     53    # use separate copies, so we can modify the lists
     54    extra_preargs = copy.copy(extra_preargs or [])
     55    libraries = copy.copy(libraries or [])
     56    objects = copy.copy(objects or [])
     57
     58    # Additional libraries
     59    libraries.extend(self.dll_libraries)
     60
     61    # handle export symbols by creating a def-file
     62    # with executables this only works with gcc/ld as linker
     63    if ((export_symbols is not None) and
     64        (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
     65        # (The linker doesn't do anything if output is up-to-date.
     66        # So it would probably better to check if we really need this,
     67        # but for this we had to insert some unchanged parts of
     68        # UnixCCompiler, and this is not what we want.)
     69
     70        # we want to put some files in the same directory as the
     71        # object files are, build_temp doesn't help much
     72        # where are the object files
     73        temp_dir = os.path.dirname(objects[0])
     74        # name of dll to give the helper files the same base name
     75        (dll_name, dll_extension) = os.path.splitext(
     76            os.path.basename(output_filename))
     77
     78        # generate the filenames for these files
     79        def_file = os.path.join(temp_dir, dll_name + ".def")
     80        lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")
     81
     82        # Generate .def file
     83        contents = ["EXPORTS"]
     84        for sym in export_symbols:
     85            contents.append(sym)
     86        self.execute(write_file, (def_file, contents),
     87                     "writing %s" % def_file)
     88
     89        # next add options for def-file and to creating import libraries
     90
     91        # dllwrap uses different options than gcc/ld
     92        if self.linker_dll == "dllwrap":
     93            extra_preargs.extend(["--output-lib", lib_file])
     94            # for dllwrap we have to use a special option
     95            extra_preargs.extend(["--def", def_file])
     96            # we use gcc/ld here and can be sure ld is >= 2.9.10
     97        else:
     98            # doesn't work: bfd_close build\...\libfoo.a: Invalid operation
     99            #extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
     100            # for gcc/ld the def-file is specified as any object files
     101            objects.append(def_file)
     102
     103    #end: if ((export_symbols is not None) and
     104    #        (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
     105
     106    # who wants symbols and a many times larger output file
     107    # should explicitly switch the debug mode on
     108    # otherwise we let dllwrap/ld strip the output file
     109    # (On my machine: 10KiB < stripped_file < ??100KiB
     110    #   unstripped_file = stripped_file + XXX KiB
     111    #  ( XXX=254 for a typical python extension))
     112    if not debug and not hasattr(sys, 'gettotalrefcount'):
     113        extra_preargs.append("-s")
     114
     115    UnixCCompiler.link(self, target_desc, objects, output_filename,
     116                       output_dir, libraries, library_dirs,
     117                       runtime_library_dirs,
     118                       None, # export_symbols, we do this in our def-file
     119                       debug, extra_preargs, extra_postargs, build_temp,
     120                       target_lang)
     121
    41122class BuildInterpreters(build_ext.build_ext):
    42123    description = "build special python interpreter stubs"
    43124
    class BuildInterpreters(build_ext.build_ext):  
    67148        if os.name == 'nt' and self.plat_name != get_platform():
    68149            self.compiler.initialize(self.plat_name)
    69150
     151        if isMingw32:
     152            self.compiler.link = types.MethodType(mingw32_link, self.compiler)
     153
    70154        # And make sure that any compile/link-related options (which might
    71155        # come from the command-line or from the setup script) are set in
    72156        # that CCompiler object -- that way, they automatically apply to
    class BuildInterpreters(build_ext.build_ext):  
    190274                           libraries=self.get_libraries(ext),
    191275                           library_dirs=ext.library_dirs,
    192276                           runtime_library_dirs=ext.runtime_library_dirs,
    193                            export_symbols=ext.export_symbols,
     277                           export_symbols=ext.export_symbols if ext.export_symbols else None,
    194278                           extra_postargs=extra_args,
    195279                           debug=self.debug)
    196280
  • py2exe/runtime.py

    diff --git a/py2exe/runtime.py b/py2exe/runtime.py
    index 10b0fa9..d154ff7 100644
    a b from .icons import BuildIcons  
    1919
    2020logger = logging.getLogger("runtime")
    2121
    22 #from importlib.machinery import EXTENSION_SUFFIXES
    23 EXTENSION_SUFFIXES = ['.pyd']
     22from importlib.machinery import EXTENSION_SUFFIXES
     23#EXTENSION_SUFFIXES = ['.pyd']
    2424from importlib.machinery import DEBUG_BYTECODE_SUFFIXES, OPTIMIZED_BYTECODE_SUFFIXES
    2525
    2626RT_MANIFEST = 24
    class Runtime(object):  
    248248            if os.path.isfile(libpath):
    249249                os.remove(libpath)
    250250
    251             if not os.path.exists(os.path.dirname(libpath)):
    252                 os.mkdir(os.path.dirname(libpath))
    253 
    254             dll_bytes = pkgutil.get_data("py2exe", "resources.dll")
    255             with open(libpath, "wb") as ofi:
    256                   ofi.write(dll_bytes)
     251            if self.options.skip_archive:
     252                if not os.path.exists(libpath):
     253                    os.makedirs(libpath)
     254            else:
     255                if not os.path.exists(os.path.dirname(libpath)):
     256                    os.mkdir(os.path.dirname(libpath))
     257                dll_bytes = pkgutil.get_data("py2exe", "resources.dll")
     258                with open(libpath, "wb") as ofi:
     259                    ofi.write(dll_bytes)
    257260            if options.verbose:
    258261                print("Building shared code archive '%s'." % libpath)
    259262            # Archive is appended to resources.dll; remove the icon
    class Runtime(object):  
    263266
    264267        self.copy_files(destdir)
    265268
    266         # data directories from modulefinder
     269        # data directories from modulefinder
    267270        for name, (src, recursive) in self.mf._data_directories.items():
    268271            if recursive:
    269272                dst = os.path.join(destdir, name)
    class Runtime(object):  
    274277            else:
    275278                raise RuntimeError("not yet supported")
    276279
    277         # data files from modulefinder
    278         for name, src in self.mf._data_files.items():
    279             dst = os.path.join(destdir, name)
    280             shutil.copy2(src, dst)
    281 
     280        # data files from modulefinder
     281        for name, src in self.mf._data_files.items():
     282            dst = os.path.join(destdir, name)
     283            shutil.copy2(src, dst)
     284
    282285        # other data files
    283286        if self.options.data_files:
    284287            for subdir, files in self.options.data_files:
    class Runtime(object):  
    410413            compression = zipfile.ZIP_STORED
    411414
    412415        # Create a zipfile and append it to the library file
    413         arc = zipfile.ZipFile(libpath, "a",
    414                               compression=compression)
    415 
    416         # The same modules may be in self.ms.modules under different
    417         # keys; we only need one of them in the archive.
    418         for mod in set(self.mf.modules.values()):
    419             if mod.__code__:
    420                 if hasattr(mod, "__path__"):
    421                     path = mod.__name__.replace(".", "\\") + "\\__init__" + bytecode_suffix
    422                 else:
    423                     path = mod.__name__.replace(".", "\\") + bytecode_suffix
    424                 stream = io.BytesIO()
    425                 stream.write(imp.get_magic())
    426                 if sys.version_info >= (3,7,0):
    427                     stream.write(b"\0\0\0\0") # null flags
    428                 stream.write(b"\0\0\0\0") # null timestamp
    429                 stream.write(b"\0\0\0\0") # null size
    430                 marshal.dump(mod.__code__, stream)
    431                 arc.writestr(path, stream.getvalue())
    432 
    433             elif hasattr(mod, "__file__"):
    434                 #assert mod.__file__.endswith(EXTENSION_SUFFIXES[0])
    435                 if self.options.bundle_files <= 2:
    436                     # put .pyds into the archive
    437                     arcfnm = mod.__name__.replace(".", "\\") + EXTENSION_SUFFIXES[0]
    438                     if self.options.verbose > 1:
    439                         print("Add %s to %s" % (os.path.basename(mod.__file__), libpath))
    440                     arc.write(mod.__file__, arcfnm)
    441                 else:
    442                     # The extension modules will be copied into
    443                     # dlldir.  To be able to import it without dlldir
    444                     # being on sys.path, create a loader module and
    445                     # put that into the archive.
    446                     pydfile = mod.__name__ + EXTENSION_SUFFIXES[0]
    447                     if self.options.verbose > 1:
    448                         print("Add Loader for %s to %s" % (os.path.basename(mod.__file__), libpath))
    449                     loader = LOAD_FROM_DIR.format(pydfile)
    450 
    451                     code = compile(loader, "<loader>", "exec",
    452                                    optimize=self.options.optimize)
     416        if self.options.skip_archive:
     417            for mod in set(self.mf.modules.values()):
     418                if hasattr(mod, "__file__"):
     419                    path = os.path.join(*mod.__name__.split("."))
     420                    if hasattr(mod, "__path__"):
     421                        path = os.path.join(path, "__init__")
     422                    path += bytecode_suffix if mod.__code__ else EXTENSION_SUFFIXES[0]
     423                    path = os.path.join(libpath, path)
     424                    dirpath = os.path.dirname(path)
     425                    if not os.path.isdir(dirpath):
     426                        os.makedirs(dirpath)
     427                    if mod.__code__:
     428                        with open(mod.__file__, "rt") as fin:
     429                            code = compile(fin.read(), mod.__file__, "exec",
     430                                           optimize=self.options.optimize)
     431                        with open(path, "wb") as fout:
     432                            fout.write(imp.get_magic())
     433                            if sys.version_info >= (3,7,0):
     434                                fout.write(b"\0\0\0\0") # null flags
     435                            fout.write(b"\0\0\0\0") # null timestamp
     436                            fout.write(b"\0\0\0\0") # null size
     437                            marshal.dump(code, fout)
     438                    else:
     439                        shutil.copy2(mod.__file__, path)
     440        else:
     441            arc = zipfile.ZipFile(libpath, "a",
     442                                  compression=compression)
     443
     444            # The same modules may be in self.ms.modules under different
     445            # keys; we only need one of them in the archive.
     446            for mod in set(self.mf.modules.values()):
     447                if mod.__code__:
    453448                    if hasattr(mod, "__path__"):
    454449                        path = mod.__name__.replace(".", "\\") + "\\__init__" + bytecode_suffix
    455450                    else:
    class Runtime(object):  
    457452                    stream = io.BytesIO()
    458453                    stream.write(imp.get_magic())
    459454                    if sys.version_info >= (3,7,0):
    460                         stream.write(b"\0\0\0\0") # null flags
     455                        stream.write(b"\0\0\0\0") # null flags
    461456                    stream.write(b"\0\0\0\0") # null timestamp
    462457                    stream.write(b"\0\0\0\0") # null size
    463                     marshal.dump(code, stream)
     458                    marshal.dump(mod.__code__, stream)
    464459                    arc.writestr(path, stream.getvalue())
    465460
    466         if self.options.bundle_files == 0:
    467             # put everything into the arc
    468             files = self.mf.all_dlls()
    469         elif self.options.bundle_files in (1, 2):
    470             # put only extension dlls into the arc
    471             files = self.mf.extension_dlls()
    472         else:
    473             arc.close()
    474             return
     461                elif hasattr(mod, "__file__"):
     462                    #assert mod.__file__.endswith(EXTENSION_SUFFIXES[0])
     463                    if self.options.bundle_files <= 2:
     464                        # put .pyds into the archive
     465                        arcfnm = mod.__name__.replace(".", "\\") + EXTENSION_SUFFIXES[0]
     466                        if self.options.verbose > 1:
     467                            print("Add %s to %s" % (os.path.basename(mod.__file__), libpath))
     468                        arc.write(mod.__file__, arcfnm)
     469                    else:
     470                        # The extension modules will be copied into
     471                        # dlldir.  To be able to import it without dlldir
     472                        # being on sys.path, create a loader module and
     473                        # put that into the archive.
     474                        pydfile = mod.__name__ + EXTENSION_SUFFIXES[0]
     475                        if self.options.verbose > 1:
     476                            print("Add Loader for %s to %s" % (os.path.basename(mod.__file__), libpath))
     477                        loader = LOAD_FROM_DIR.format(pydfile)
     478
     479                        code = compile(loader, "<loader>", "exec",
     480                                       optimize=self.options.optimize)
     481                        if hasattr(mod, "__path__"):
     482                            path = mod.__name__.replace(".", "\\") + "\\__init__" + bytecode_suffix
     483                        else:
     484                            path = mod.__name__.replace(".", "\\") + bytecode_suffix
     485                        stream = io.BytesIO()
     486                        stream.write(imp.get_magic())
     487                        if sys.version_info >= (3,7,0):
     488                            stream.write(b"\0\0\0\0") # null flags
     489                        stream.write(b"\0\0\0\0") # null timestamp
     490                        stream.write(b"\0\0\0\0") # null size
     491                        marshal.dump(code, stream)
     492                        arc.writestr(path, stream.getvalue())
     493
     494            if self.options.bundle_files == 0:
     495                # put everything into the arc
     496                files = self.mf.all_dlls()
     497            elif self.options.bundle_files in (1, 2):
     498                # put only extension dlls into the arc
     499                files = self.mf.extension_dlls()
     500            else:
     501                arc.close()
     502                return
    475503
    476         for src in files:
    477             if self.options.verbose > 1:
    478                 print("Add DLL %s to %s" % (os.path.basename(src), libpath))
    479             arc.write(src, os.path.basename(src))
     504            for src in files:
     505                if self.options.verbose > 1:
     506                    print("Add DLL %s to %s" % (os.path.basename(src), libpath))
     507                arc.write(src, os.path.basename(src))
    480508
    481         arc.close()
     509            arc.close()
    482510
    483511    def copy_files(self, destdir):
    484512        """Copy files (pyds, dlls, depending on the bundle_files value,
    class Runtime(object):  
    498526            with UpdateResources(dst, delete_existing=False) as resource:
    499527                resource.add_string(1000, "py2exe")
    500528
    501         if self.options.bundle_files == 3:
     529        if not self.options.skip_archive and self.options.bundle_files == 3:
    502530            # copy extension modules; they go to libdir
    503531            for mod in self.mf.modules.values():
    504532                if mod.__code__:
    505533                    # nothing to do for python modules.
    506534                    continue
    507535                if hasattr(mod, "__file__"):
    508                     assert mod.__file__.endswith(EXTENSION_SUFFIXES[0])
    509                     pydfile = mod.__name__ + EXTENSION_SUFFIXES[0]
     536                    if mod.__file__.endswith(EXTENSION_SUFFIXES[0]):
     537                        pydfile = mod.__name__ + EXTENSION_SUFFIXES[0]
    510538
    511                     dst = os.path.join(libdir, pydfile)
     539                        dst = os.path.join(libdir, pydfile)
     540                    else:
     541                        dst = os.path.join(libdir, os.path.basename(mod.__file__))
    512542                    if self.options.verbose:
    513543                        print("Copy %s to %s" % (mod.__file__, dst))
    514544                    shutil.copy2(mod.__file__, dst)
    def __load():  
    638668    dllpath = os.path.join(os.path.dirname(__loader__.archive), r'{0}')
    639669    try:
    640670        mod = imp.load_dynamic(__name__, dllpath)
     671        mod.frozen = 1
    641672    except ImportError as details:
    642673        raise ImportError('(%s) %r' % (details, dllpath)) from None
    643     mod.frozen = 1
     674    except AttributeError:
     675        pass
    644676__load()
    645677del __load
    646678"""
  • setup.py

    diff --git a/setup.py b/setup.py
    index 342d194..5fb5a9a 100644
    a b if sys.version_info < (3, 3):  
    1212############################################################################
    1313
    1414from setuptools import setup
     15from distutils import ccompiler
     16isMingw32 = ccompiler.get_default_compiler()=='mingw32'
    1517##from distutils.core import setup
    1618
    1719from py2exe.py2exe_distutils import Dist, Interpreter, BuildInterpreters
    def _is_debug_build():  
    2628    return False
    2729
    2830if _is_debug_build():
    29     macros = [("PYTHONDLL", '\\"python%d%d_d.dll\\"' % sys.version_info[:2]),
     31    macros = [("PYTHONDLL", ('"libpython%d.%dm_d.dll"' if isMingw32 else '"\\python%d%d_d.dll\\"') % sys.version_info[:2]),
    3032##              ("PYTHONCOM", '\\"pythoncom%d%d_d.dll\\"' % sys.version_info[:2]),
    3133              ("_CRT_SECURE_NO_WARNINGS", '1')]
    3234else:
    33     macros = [("PYTHONDLL", '\\"python%d%d.dll\\"' % sys.version_info[:2]),
     35    macros = [("PYTHONDLL", ('"libpython%d.%dm.dll"' if isMingw32 else '"\\python%d%d.dll\\"') % sys.version_info[:2]),
    3436##              ("PYTHONCOM", '\\"pythoncom%d%d.dll\\"' % sys.version_info[:2]),
    3537              ("_CRT_SECURE_NO_WARNINGS", '1'),]
    3638
    macros.append(("Py_BUILD_CORE", '1'))  
    3941extra_compile_args = []
    4042extra_link_args = []
    4143
    42 extra_compile_args.append("-IC:\\Program Files\\Microsoft SDKs\\Windows\\v7.0\\Include")
    43 extra_compile_args.append("-IC:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include")
    44 extra_compile_args.append("-IC:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.10586.0\\ucrt")
     44if not isMingw32:
     45    extra_compile_args.append("-IC:\\Program Files\\Microsoft SDKs\\Windows\\v7.0\\Include")
     46    extra_compile_args.append("-IC:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include")
     47    extra_compile_args.append("-IC:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.10586.0\\ucrt")
    4548
    4649if 0:
    4750    # enable this to debug a release build
    run_ctypes_dll = Interpreter("py2exe.run_ctypes_dll",  
    6366                              "source/python-dynload.c",
    6467                              ],
    6568                             libraries=["user32", "shell32"],
    66                              export_symbols=["DllCanUnloadNow,PRIVATE",
     69                             export_symbols=["DllCanUnloadNow",
     70                                             "DllGetClassObject",
     71                                             "DllRegisterServer",
     72                                             "DllUnregisterServer",
     73                                             ] if isMingw32 else ["DllCanUnloadNow,PRIVATE",
    6774                                             "DllGetClassObject,PRIVATE",
    6875                                             "DllRegisterServer,PRIVATE",
    6976                                             "DllUnregisterServer,PRIVATE",
    run_ctypes_dll = Interpreter("py2exe.run_ctypes_dll",  
    7178                             target_desc = "shared_library",
    7279                             define_macros=macros,
    7380                             extra_compile_args=extra_compile_args,
    74                              extra_link_args=extra_link_args + ["/DLL"],
     81                             extra_link_args=extra_link_args + ([] if isMingw32 else ["/DLL"]),
    7582                             )
    7683
    7784run = Interpreter("py2exe.run",
    resource_dll = Interpreter("py2exe.resources",  
    123130                           ["source/dll.c",
    124131                            "source/icon.rc"],
    125132                           target_desc = "shared_library",
    126                            extra_link_args=["/DLL"],
     133                           extra_link_args=[] if isMingw32 else ["/DLL"],
    127134                           )
    128135
    129136interpreters = [run, run_w, resource_dll,
  • source/python-dynload.c

    diff --git a/source/python-dynload.c b/source/python-dynload.c
    index 2a60b86..373bb62 100644
    a b static HMODULE hmod_pydll;  
    3131
    3232#define FUNC(res, name, args) \
    3333  static res(*proc)args; \
    34   if (!proc) (FARPROC)proc = MyGetProcAddress(hmod_pydll, #name)
     34  if (!proc) proc = (res (*)args)MyGetProcAddress(hmod_pydll, #name)
    3535
    3636#define DATA(type, name)                                \
    3737  static type pflag; \
    void PyErr_Print(void)  
    158158  proc();
    159159}
    160160
    161 void Py_SetProgramName(wchar_t *name)
     161void Py_SetProgramName(const wchar_t *name)
    162162{
    163163  FUNC(void, Py_SetProgramName, (wchar_t *));
    164164  proc(name);
  • source/run.c

    diff --git a/source/run.c b/source/run.c
    index e1f630e..933ae77 100644
    a b extern int start(int argc, wchar_t **argv);  
    5454/*
    5555  The main function for our exe.
    5656*/
     57#if defined(__MINGW32__)
     58int main (int argc, wchar_t **argv)
     59#else
    5760int wmain (int argc, wchar_t **argv)
     61#endif
    5862{
    5963        int result;
    6064        result = init("console_exe");
  • source/start.c

    diff --git a/source/start.c b/source/start.c
    index e894ae6..6b61624 100644
    a b BOOL locate_script(HMODULE hmod)  
    128128                SystemError(GetLastError(), "Could not load script resource:");
    129129                return FALSE;
    130130        }
    131         p_script_info = (struct scriptinfo *)pScript = LockResource(hgbl);
     131        p_script_info = (struct scriptinfo *)(pScript = LockResource(hgbl));
    132132        if (!pScript)  {
    133133                SystemError(GetLastError(), "Could not lock script resource:");
    134134                return FALSE;
Note: See TracBrowser for help on using the repository browser.