Skip to content

Commit

Permalink
Ensure the copy of default python libraries - windows (#640)
Browse files Browse the repository at this point in the history
* Ensure the copy of default python libraries - windows

* don't break mingw

* refactor
  • Loading branch information
marcelotduarte authored May 30, 2020
1 parent 59e7773 commit 21b1cfd
Showing 1 changed file with 37 additions and 16 deletions.
53 changes: 37 additions & 16 deletions cx_Freeze/freezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import stat
import struct
import sys
import sysconfig
import time
import zipfile

Expand Down Expand Up @@ -177,20 +178,36 @@ def _FreezeExecutable(self, exe):
".py")
finder.IncludeFile(startupModule)

# Always copy the python dynamic libraries into lib folder
# Copy the python dynamic libraries
copyDependentFiles = True
if sys.platform == "linux":
self._CopyFile(exe.base, exe.targetName,
copyDependentFiles=False, includeMode=True)
# Always copy the python dynamic libraries into lib folder
targetDir = os.path.join(os.path.dirname(exe.targetName), 'lib')
dependentFiles = self._GetDependentFiles(exe.base) or \
self._GetDependentFiles(sys.executable)
for source in dependentFiles:
target = os.path.join(targetDir, os.path.basename(source))
self._CopyFile(source, target,
copyDependentFiles=True, includeMode=True)
else:
self._CopyFile(exe.base, exe.targetName,
copyDependentFiles=True, includeMode=True)
copyDependentFiles = False
elif sys.platform == "win32":
# Copy the python dynamic libraries into build folder
targetDir = os.path.dirname(exe.targetName)
dependentFiles = self._GetDependentFiles(exe.base) or \
self._GetDependentFiles(sys.executable)
# Ensure the copy of default python libraries
sourceDir = os.path.dirname(dependentFiles[0])
for name in self._GetDefaultBinIncludes():
source = os.path.join(sourceDir, os.path.normcase(name))
if source not in dependentFiles:
dependentFiles.append(source)
for source in dependentFiles:
target = os.path.join(targetDir, os.path.basename(source))
self._CopyFile(source, target,
copyDependentFiles=True, includeMode=True)
copyDependentFiles = False
self._CopyFile(exe.base, exe.targetName,
copyDependentFiles=copyDependentFiles, includeMode=True)
if not os.access(exe.targetName, os.W_OK):
mode = os.stat(exe.targetName).st_mode
os.chmod(exe.targetName, mode | stat.S_IWUSR)
Expand Down Expand Up @@ -225,17 +242,21 @@ def _GetDefaultBinExcludes(self):
def _GetDefaultBinIncludes(self):
"""Return the file names of libraries which must be included for the
frozen executable to work."""
python_shared_libs = []
if sys.platform == "win32":
pythonDlls = ["python%s.dll" % sys.version_info[0],
"python%s%s.dll" % sys.version_info[:2],
"vcruntime140.dll"]
return pythonDlls
if sysconfig.get_platform() == "mingw":
name = distutils.sysconfig.get_config_var("INSTSONAME")
if name:
python_shared_libs.append(name.replace(".dll.a", ".dll"))
else:
python_shared_libs += ["python%s.dll" % sys.version_info[0],
"python%s%s.dll" % sys.version_info[:2],
"vcruntime140.dll"]
else:
soName = distutils.sysconfig.get_config_var("INSTSONAME")
if soName is None:
return []
pythonSharedLib = self._RemoveVersionNumbers(soName)
return [pythonSharedLib]
name = distutils.sysconfig.get_config_var("INSTSONAME")
if name:
python_shared_libs.append(self._RemoveVersionNumbers(name))
return python_shared_libs

def _GetDefaultBinPathExcludes(self):
"""Return the paths of directories which contain files that should not
Expand Down Expand Up @@ -323,7 +344,7 @@ def _GetDependentFiles(self, path):
dependentFiles = [self._CheckDependentFile(f, dirname)
for f in dependentFiles if self._ShouldCopyFile(f)]
else:
dependentFiles = [f
dependentFiles = [os.path.normcase(f)
for f in dependentFiles if self._ShouldCopyFile(f)]
self.dependentFiles[path] = dependentFiles
return dependentFiles
Expand Down

0 comments on commit 21b1cfd

Please sign in to comment.