Skip to content

Commit

Permalink
Merge branch 'hotfix-cQtDeployer-dependencies' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
BuvinJ committed Dec 11, 2020
2 parents 230306c + 2c446b1 commit f5dfd63
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 46 deletions.
1 change: 1 addition & 0 deletions distbuilder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
, rootFileName \
, normBinaryName \
, normIconName \
, normLibName \
, copyToDir \
, moveToDir \
, removeFromDir \
Expand Down
95 changes: 50 additions & 45 deletions distbuilder/qt_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,16 @@ def qtDirPath( self ):
head, tail = splitPath( qtDir )
if tail=="bin" : qtDir=head
return qtDir

def toQtPath( self, relativePath ):
return absPath( relativePath, self.qtDirPath() )

def validate( self ):
if self.qtBinDirPath is None:
self.qtBinDirPath = getEnv( QT_BIN_DIR_ENV_VAR )
if self.qtBinDirPath is None or not isDir( self.qtBinDirPath ):
raise Exception( "Valid Qt Bin directory path required" )
if IS_WINDOWS or ( IS_LINUX and _isCqtdeployerInstalled() ):
if self.qtBinDirPath is None:
self.qtBinDirPath = getEnv( QT_BIN_DIR_ENV_VAR )
if self.qtBinDirPath is None or not isDir(self.qtBinDirPath):
raise Exception( "Valid Qt Bin directory path required" )

# Refer to: https://doc.qt.io/qt-5/deployment.html
def addDependencies( self, package ) :
Expand All @@ -169,8 +173,6 @@ def addDependencies( self, package ) :
exePath = joinPath( destDirPath, package.exeName )
if IS_WINDOWS :
self.__useWindeployqt( destDirPath, exePath )
elif IS_MACOS :
self.__useMacdeployqt( destDirPath, exePath )
elif IS_LINUX:
if _isCqtdeployerInstalled():
exePath = self.__useCqtdeployer( destDirPath, exePath )
Expand All @@ -197,18 +199,26 @@ def __useWindeployqt( self, destDirPath, exePath ):
copyToDir( joinPath( self.qtBinDirPath, fileName ),
destDirPath=destDirPath )

def __useMacdeployqt( self, destDirPath, exePath ):
# collect required dependencies via the Qt deploy utility for MacOS
qtUtilityPath = normpath( joinPath(
self.qtBinDirPath, QtCppConfig.__QT_MACOS_DEPLOY_EXE_NAME ) )
cmdList = [qtUtilityPath, exePath]
cmd = list2cmdline( cmdList )
# optionally detect and bundle QML resources
if self.qmlScrDirPath is not None:
cmd = '%s %s="%s"' % (cmd, QtCppConfig.__QT_MACOS_DEPLOY_QML_SWITCH,
normpath( self.qmlScrDirPath ))
util._system( cmd )

# This a fallback (limited) option to attempt on Linux systems which don't
# have the cqtdeploy utility installed.
# TODO: continue to develop this, so it more closely revivals cqtdeploy...
def __useLdd( self, destDirPath, exePath ):
# get the list of .so libraries the binary links against within the
# local environment, via the standard Linux utility for this.
# Parse that output and collect the files.
cmdList = [QtCppConfig.__LDD_CMD,
exePath]
lddLines = util._subProcessStdOut( cmdList, asCleanLines=True )
for line in lddLines:
try :
src = line.split( QtCppConfig.__LDD_DELIMITER_SRC )[1].strip()
path = src.split( QtCppConfig.__LDD_DELIMITER_PATH )[0].strip()
if isFile( path ):
copyToDir( path, destDirPath=destDirPath )
except: pass
# The Qt produced binary does not have execute permissions automatically!
chmod( exePath, 0o755 )

def __useCqtdeployer( self, destDirPath, exePath ):
# collect required dependencies via the third party cqtdeployer utility
qmakePath = normpath( joinPath(
Expand Down Expand Up @@ -242,36 +252,33 @@ def __useCqtdeployer( self, destDirPath, exePath ):
src = joinPath( qmlSrcDirPath, subDir )
dest = joinPath( qmlDestDirPath, subDir )
print( "Copying %s to %s..." % (src, dest) )
copyDir( src, dest )
copyDir( src, dest )
# inject missing dependencies
if cfg and len(cfg.hiddenDependencies) > 0:
for depend in cfg.hiddenDependencies:
src, dest = util._toSrcDestPair( depend, destDir=destDirPath )
print( 'Copying "%s" to "%s"...' % ( src, dest ) )
if isFile( src ) :
destDir = dirPath( dest )
if not exists( destDir ): makeDir( destDir )
try: copyFile( src, dest )
except Exception as e: printExc( e )
elif isDir( src ):
try: copyDir( src, dest )
except Exception as e: printExc( e )
else:
printErr( 'Invalid path: "%s"' % (src,) )

# return the path to the exe produced
return exePath

# This a fallback (limited) option to attempt on Linux systems which don't
# have the cqtdeploy utility installed.
# TODO: continue to develop this, so it more closely revivals cqtdeploy...
def __useLdd( self, destDirPath, exePath ):
# get the list of .so libraries the binary links against within the
# local environment, via the standard Linux utility for this.
# Parse that output and collect the files.
cmdList = [QtCppConfig.__LDD_CMD,
exePath]
lddLines = util._subProcessStdOut( cmdList, asCleanLines=True )
for line in lddLines:
try :
src = line.split( QtCppConfig.__LDD_DELIMITER_SRC )[1].strip()
path = src.split( QtCppConfig.__LDD_DELIMITER_PATH )[0].strip()
if isFile( path ):
copyToDir( path, destDirPath=destDirPath )
except: pass
# The Qt produced binary does not have execute permissions automatically!
chmod( exePath, 0o755 )

class CQtDeployerConfig:

def __init__( self ):
self.libDirs = []
self.plugins = []
self.hiddenQml = []
self.libDirs = []
self.plugins = []
self.hiddenQml = []
self.hiddenDependencies = []

self.ignoreLibs = []
self.ignoreEnv = []
Expand Down Expand Up @@ -336,9 +343,6 @@ def exeWrapper( exePath, isGui ):

__QT_WINDOWS_DEPLOY_EXE_NAME = "windeployqt.exe"
__QT_WINDOWS_DEPLOY_QML_SWITCH = "--qmldir"

__QT_MACOS_DEPLOY_EXE_NAME = "macdeployqt"
__QT_MACOS_DEPLOY_QML_SWITCH = "-qmldir"

#TODO: Add more of these dlls?
#TODO: Add additional logic to determine the need for this...
Expand All @@ -357,6 +361,7 @@ def exeWrapper( exePath, isGui ):
__C_QT_DEPLOYER_TARGET_SWITCH = "-targetDir"
__C_QT_DEPLOYER_TARGET_BIN_DIR = "bin"
__C_QT_DEPLOYER_TARGET_QML_DIR = "qml"
__C_QT_DEPLOYER_TARGET_PLUGINS_DIR = "plugins"
__C_QT_DEPLOYER_QML_SWITCH = "-qmlDir"

__LDD_CMD = "ldd"
Expand Down
16 changes: 15 additions & 1 deletion distbuilder/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@

__NOT_SUPPORTED_MSG =(
"This operation/feature is not supported on the current platform!" )
# library types across the platforms
_WINDOWS_LIB_EXT = ".dll"
_MACOS_LIB_EXT = ".so"
_LINUX_LIB_EXT = ".so"

__SCRUB_CMD_TMPL = "{0}{1}"
__DBL_QUOTE = '"'
Expand Down Expand Up @@ -509,7 +513,7 @@ def sitePackagePath( packageName ):
def importFromPath( path, memberName=None ):
scriptDir, scriptName = splitPath( path )
moduleName = rootFileName( scriptName )
sysPath.insert( 0, scriptDir )
sysPath.insert( 0, scriptDir )
if memberName is None : exec( __IMPORT_TMPLT % (moduleName,) )
else: exec( __FROM_IMPORT_TMPLT % (moduleName, memberName) )
sysPath.remove( scriptDir )
Expand Down Expand Up @@ -558,6 +562,16 @@ def normIconName( path, isPathPreserved=False ):
elif IS_LINUX: return "%s%s" % (base, _LINUX_ICON_EXT)
raise Exception( __NOT_SUPPORTED_MSG )
return base

def normLibName( path, isPathPreserved=False ):
if path is None : return None
if not isPathPreserved : path = fileBaseName( path )
base, _ = splitExt( path )
if IS_WINDOWS: return "%s%s" % (base, _WINDOWS_LIB_EXT)
elif IS_MACOS: return "%s%s" % (base, _MACOS_LIB_EXT)
elif IS_LINUX: return "%s%s" % (base, _LINUX_LIB_EXT)
raise Exception( __NOT_SUPPORTED_MSG )
return base

def _isMacApp( path ):
if path is None : return False
Expand Down

0 comments on commit f5dfd63

Please sign in to comment.