1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#!/usr/bin/env python
# create-win-installer.py
#
# This file is part of Charm, a task-based time tracking application.
#
# Copyright (C) 2016-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
#
# Author: Hannah von Reth <hannah.vonreth@kdab.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import os
import subprocess
import sys
import shutil
import argparse
import glob
class DeployHelper(object):
def __init__(self, args):
self.args = args
self.gitDir = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
self.deployImage = os.path.realpath("./deployImage")
if not os.path.exists(self.args.buildDir):
self._die("Build dir %s does not exist" % self.args.buildDir)
def _die(self, message):
print(message, file=sys.stderr)
exit(1)
def _logExec(self, command):
print(command)
sys.stdout.flush()
subprocess.check_call(command, shell=True)
def _copyToImage(self, src, destDir = None, deploy = True):
if destDir is None:
destDir = self.deployImage
print("Copy %s to %s" % (src, destDir))
shutil.copy(src, destDir)
if deploy:
self._logExec("windeployqt --%s --dir \"%s\" --qmldir \"%s\" \"%s\"" % (self.args.buildType, self.deployImage, self.gitDir, src))
def _sign(self, fileName):
if self.args.sign:
self._logExec("signtool.exe sign -t http://timestamp.globalsign.com/scripts/timestamp.dll -fd SHA256 -v \"%s\"" % fileName)
def cleanImage(self):
if os.path.exists(self.deployImage):
shutil.rmtree(self.deployImage)
os.makedirs(self.deployImage)
def _locateDll(self, dllName, fatal=True):
pathext = os.environ.get("PATHEXT")
os.environ["PATHEXT"] = ".dll"
found = shutil.which(dllName, path=os.pathsep.join([self.deployImage, os.environ.get("PATH")]))
os.environ["PATHEXT"] = pathext
if not found and fatal:
self._die("Unable to locate %s" % dllName)
return found
def deploy(self):
if self.args.deployDlls:
for dll in self.args.deployDlls.split(";"):
self._copyToImage(self._locateDll(dll))
app = os.path.join(self.args.buildDir, self.args.applicationFileName)
shutil.copy(app, self.deployImage)
self._logExec("windeployqt --%s --compiler-runtime --dir \"%s\" --qmldir \"%s\" \"%s\"" % (self.args.buildType, self.deployImage, self.gitDir, app))
for folder in self.args.pluginFolders.split(";"):
for f in glob.glob(os.path.join(self.args.buildDir, folder, "*.dll")):
self._copyToImage(f)
if self.args.deployOpenSSL:
foundSomething = False
for dll in ["libeay32.dll", "libssl32.dll", "ssleay32.dll" ]:
src = os.path.join(self.args.deployOpenSSL, dll )
if not os.path.exists(src):
src = self._locateDll(dll, fatal=False)
if src:
foundSomething = True
print(src)
self._copyToImage(src, deploy=False)
if not foundSomething:
self._die("Failed to deploy openssl")
if self.args.sign:
for f in glob.glob(os.path.join(self.deployImage, "**/*.exe"), recursive=True):
self._sign(f)
for f in glob.glob(os.path.join(self.deployImage, "**/*.dll"), recursive=True):
self._sign(f)
def makeInstaller(self):
if self.args.architecture == "x64":
programDir = "$PROGRAMFILES64"
else:
programDir = "$PROGRAMFILES"
defines = {}
defines["productName"] = self.args.productName
defines["companyName"] = self.args.companyName
defines["productVersion"] = self.args.productVersion
defines["setupname"] = self.args.installerName
defines["applicationName"] = os.path.basename(self.args.applicationFileName)
defines["applicationIcon"] = self.args.applicationIcon
defines["programFilesDir"] = programDir
defines["deployDir"] = self.deployImage
defines["productLicence"] = "" if not self.args.productLicence else "!insertmacro MUI_PAGE_LICENSE \"%s\"" % self.args.productLicence
redist = "vcredist_%s.exe" % self.args.architecture
if os.path.exists(os.path.join(self.deployImage, redist)):
defines["vcredist"] = "vcredist_%s.exe" % self.args.architecture
else:
defines["vcredist"] = "none"
definestring = ""
for key in defines:
definestring += " /D%s=\"%s\"" % (key, defines[key])
command = "makensis /NOCD %s %s" %\
(definestring, os.path.join(os.path.dirname(__file__), "NullsoftInstaller.nsi"))
self._logExec(command)
installer = os.path.realpath(self.args.installerName)
self._sign(installer)
print("""Generated package file: %s """ % installer)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--architecture", action = "store", default="x64" )
parser.add_argument("--buildType", action = "store", default="release" )
parser.add_argument("--installerName", action = "store" )
parser.add_argument("--applicationFileName", action = "store" )
parser.add_argument("--applicationIcon", action = "store" )
parser.add_argument("--buildDir", action = "store" )
parser.add_argument("--pluginFolders", action = "store", default="" )
parser.add_argument("--productName", action = "store" )
parser.add_argument("--companyName", action = "store" )
parser.add_argument("--productVersion", action = "store" )
parser.add_argument("--productLicence", action = "store" )
parser.add_argument("--deployDlls", action = "store" )
parser.add_argument("--deployOpenSSL", action = "store" )
parser.add_argument("--sign", action = "store_true", default=False)
args = parser.parse_args()
helper = DeployHelper(args)
helper.cleanImage()
helper.deploy()
helper.makeInstaller()
|