| 1 |
from harvest import generateWixFragment |
| 2 |
from packagewindows import ( |
| 3 |
PackageInfo, emptyOrCreateDirectory, generateInstallFiles |
| 4 |
) |
| 5 |
|
| 6 |
from io import open |
| 7 |
from os import environ, mkdir, system, unlink |
| 8 |
from os.path import exists, join as joinpath |
| 9 |
from zipfile import ZIP_DEFLATED, ZipFile |
| 10 |
import sys |
| 11 |
|
| 12 |
def _writeFragment( |
| 13 |
wxsFile, sourcePath, componentGroup, directoryRef, |
| 14 |
virtualDir, excludedFile, win64 |
| 15 |
): |
| 16 |
print('Generating ' + wxsFile) |
| 17 |
with open(wxsFile, 'w', encoding='utf-8') as out: |
| 18 |
out.writelines( |
| 19 |
line + '\n' |
| 20 |
for line in generateWixFragment( |
| 21 |
sourcePath, componentGroup, directoryRef, virtualDir, |
| 22 |
excludedFile, win64 |
| 23 |
) |
| 24 |
) |
| 25 |
|
| 26 |
def packageMSI(info): |
| 27 |
assert info.packageCatapult, "MSI packaging is only supported when also packaging Catapult!" |
| 28 |
print('Generating install files...') |
| 29 |
generateInstallFiles(info) |
| 30 |
|
| 31 |
wixIntermediatePath = joinpath(info.buildPath, 'build\\WiX') |
| 32 |
emptyOrCreateDirectory(wixIntermediatePath) |
| 33 |
|
| 34 |
if not exists(info.packagePath): |
| 35 |
mkdir(info.packagePath) |
| 36 |
|
| 37 |
print('Generating fragments...') |
| 38 |
|
| 39 |
|
| 40 |
openMSXExeFile = joinpath(wixIntermediatePath, 'openmsxexe.wxs') |
| 41 |
openMSXExeObjFile = joinpath(wixIntermediatePath, 'openmsxexe.wixobj') |
| 42 |
sourcePath = joinpath(info.makeInstallPath, 'bin\\openmsx.exe') |
| 43 |
_writeFragment( |
| 44 |
openMSXExeFile, sourcePath, 'openMSXExe', 'OPENMSXINSTALLDIR', |
| 45 |
None, None, info.win64 |
| 46 |
) |
| 47 |
|
| 48 |
openMSXDocFile = joinpath(wixIntermediatePath, 'openmsxdoc.wxs') |
| 49 |
openMSXDocObjFile = joinpath(wixIntermediatePath, 'openmsxdoc.wixobj') |
| 50 |
sourcePath = joinpath(info.makeInstallPath, 'doc') |
| 51 |
_writeFragment( |
| 52 |
openMSXDocFile, sourcePath, 'openMSXDoc', 'OPENMSXINSTALLDIR', |
| 53 |
'doc', None, info.win64 |
| 54 |
) |
| 55 |
|
| 56 |
openMSXShareFile = joinpath(wixIntermediatePath, 'openmsxshare.wxs') |
| 57 |
openMSXShareObjFile = joinpath(wixIntermediatePath, 'openmsxshare.wixobj') |
| 58 |
sourcePath = joinpath(info.makeInstallPath, 'share') |
| 59 |
_writeFragment( |
| 60 |
openMSXShareFile, sourcePath, 'openMSXShare', 'OPENMSXINSTALLDIR', |
| 61 |
'share', None, info.win64 |
| 62 |
) |
| 63 |
|
| 64 |
openMSXIconFile = joinpath(wixIntermediatePath, 'openmsxicon.wxs') |
| 65 |
openMSXIconObjFile = joinpath(wixIntermediatePath, 'openmsxicon.wixobj') |
| 66 |
sourcePath = joinpath(info.sourcePath, 'resource\\openmsx.ico') |
| 67 |
_writeFragment( |
| 68 |
openMSXIconFile, sourcePath, 'openMSXIcon', 'OPENMSXINSTALLDIR', |
| 69 |
'share\\icons', None, info.win64 |
| 70 |
) |
| 71 |
|
| 72 |
|
| 73 |
ZMBVCodecFile = joinpath(wixIntermediatePath, 'zmbvcodec.wxs') |
| 74 |
ZMBVCodecObjFile = joinpath(wixIntermediatePath, 'zmbvcodec.wixobj') |
| 75 |
sourcePath = joinpath(info.codecPath, 'zmbv.dll') |
| 76 |
_writeFragment( |
| 77 |
ZMBVCodecFile, sourcePath, 'ZMBVCodec', 'SystemFolder', |
| 78 |
None, None, False |
| 79 |
) |
| 80 |
|
| 81 |
ZMBVFilesFile = joinpath(wixIntermediatePath, 'zmbvfiles.wxs') |
| 82 |
ZMBVFilesObjFile = joinpath(wixIntermediatePath, 'zmbvfiles.wixobj') |
| 83 |
sourcePath = info.codecPath |
| 84 |
_writeFragment( |
| 85 |
ZMBVFilesFile, sourcePath, 'ZMBVFiles', 'OPENMSXINSTALLDIR', |
| 86 |
'codec', 'zmbv.dll', info.win64 |
| 87 |
) |
| 88 |
|
| 89 |
|
| 90 |
catapultBinFile = joinpath(wixIntermediatePath, 'catapultbin.wxs') |
| 91 |
catapultBinObjFile = joinpath(wixIntermediatePath, 'catapultbin.wixobj') |
| 92 |
sourcePath = joinpath(info.catapultBuildPath, 'install\\catapult.exe') |
| 93 |
_writeFragment( |
| 94 |
catapultBinFile, sourcePath, 'CatapultBin', 'OPENMSXINSTALLDIR', |
| 95 |
'Catapult\\bin', None, info.win64 |
| 96 |
) |
| 97 |
|
| 98 |
catapultDocFile = joinpath(wixIntermediatePath, 'catapultdoc.wxs') |
| 99 |
catapultDocObjFile = joinpath(wixIntermediatePath, 'catapultdoc.wixobj') |
| 100 |
sourcePath = joinpath(info.catapultPath, 'doc') |
| 101 |
_writeFragment( |
| 102 |
catapultDocFile, sourcePath, 'CatapultDoc', 'OPENMSXINSTALLDIR', |
| 103 |
'Catapult\\doc', 'release-process.txt', info.win64 |
| 104 |
) |
| 105 |
|
| 106 |
catapultBitmapsFile = joinpath(wixIntermediatePath, 'catapultbitmaps.wxs') |
| 107 |
catapultBitmapsObjFile = joinpath( |
| 108 |
wixIntermediatePath, 'catapultbitmaps.wixobj' |
| 109 |
) |
| 110 |
sourcePath = joinpath(info.catapultPath, 'resources\\bitmaps') |
| 111 |
_writeFragment( |
| 112 |
catapultBitmapsFile, sourcePath, 'CatapultBitmaps', 'OPENMSXINSTALLDIR', |
| 113 |
'Catapult\\resources\\bitmaps', 'release-process.txt', info.win64 |
| 114 |
) |
| 115 |
|
| 116 |
catapultDialogsFile = joinpath(wixIntermediatePath, 'catapultdialogs.wxs') |
| 117 |
catapultDialogsObjFile = joinpath( |
| 118 |
wixIntermediatePath, 'catapultdialogs.wixobj' |
| 119 |
) |
| 120 |
sourcePath = joinpath(info.catapultBuildPath, 'install\\dialogs') |
| 121 |
_writeFragment( |
| 122 |
catapultDialogsFile, sourcePath, 'CatapultDialogs', 'OPENMSXINSTALLDIR', |
| 123 |
'Catapult\\resources\\dialogs', None, info.win64 |
| 124 |
) |
| 125 |
|
| 126 |
catapultIconsFile = joinpath(wixIntermediatePath, 'catapulticons.wxs') |
| 127 |
catapultIconsObjFile = joinpath(wixIntermediatePath, 'catapulticons.wixobj') |
| 128 |
sourcePath = joinpath(info.catapultBuildPath, 'src\\catapult.xpm') |
| 129 |
_writeFragment( |
| 130 |
catapultIconsFile, sourcePath, 'CatapultIcons', 'OPENMSXINSTALLDIR', |
| 131 |
'Catapult\\resources\\icons', None, info.win64 |
| 132 |
) |
| 133 |
|
| 134 |
catapultReadmeFile = joinpath(wixIntermediatePath, 'catapultreadme.wxs') |
| 135 |
catapultReadmeObjFile = joinpath( |
| 136 |
wixIntermediatePath, 'catapultreadme.wixobj' |
| 137 |
) |
| 138 |
sourcePath = joinpath(info.catapultPath, 'README') |
| 139 |
_writeFragment( |
| 140 |
catapultReadmeFile, sourcePath, 'CatapultReadme', 'OPENMSXINSTALLDIR', |
| 141 |
'Catapult\\doc', None, info.win64 |
| 142 |
) |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
environ.update( |
| 149 |
OPENMSX_VERSION = info.version, |
| 150 |
OPENMSX_ICON_PATH = info.openmsxExePath, |
| 151 |
OPENMSX_PACKAGE_WINDOWS_PATH = info.packageWindowsPath, |
| 152 |
) |
| 153 |
|
| 154 |
openMSXFile = joinpath(info.packageWindowsPath, 'openmsx.wxs') |
| 155 |
openMSXObjFile = joinpath(wixIntermediatePath, 'openmsx.wixobj') |
| 156 |
|
| 157 |
candleCmd = ' '.join(( |
| 158 |
'candle.exe', |
| 159 |
'-arch %s' % info.cpu, |
| 160 |
'-o "%s\\\\"' % wixIntermediatePath, |
| 161 |
'-ext WixUtilExtension', |
| 162 |
'"%s"' % openMSXFile, |
| 163 |
'"%s"' % openMSXExeFile, |
| 164 |
'"%s"' % openMSXDocFile, |
| 165 |
'"%s"' % openMSXShareFile, |
| 166 |
'"%s"' % openMSXIconFile, |
| 167 |
'"%s"' % ZMBVCodecFile, |
| 168 |
'"%s"' % ZMBVFilesFile, |
| 169 |
'"%s"' % catapultBinFile, |
| 170 |
'"%s"' % catapultDocFile, |
| 171 |
'"%s"' % catapultBitmapsFile, |
| 172 |
'"%s"' % catapultDialogsFile, |
| 173 |
'"%s"' % catapultIconsFile, |
| 174 |
'"%s"' % catapultReadmeFile, |
| 175 |
)) |
| 176 |
|
| 177 |
|
| 178 |
print(candleCmd) |
| 179 |
system(candleCmd) |
| 180 |
|
| 181 |
msiFileName = info.packageFileName + '-bin.msi' |
| 182 |
msiFilePath = joinpath(info.packagePath, msiFileName) |
| 183 |
if exists(msiFilePath): |
| 184 |
unlink(msiFilePath) |
| 185 |
|
| 186 |
print('Generating ' + msiFilePath) |
| 187 |
|
| 188 |
lightCmd = ' '.join(( |
| 189 |
'light.exe', |
| 190 |
'-o "%s"' % msiFilePath, |
| 191 |
'-sw1076', |
| 192 |
'-ext WixUtilExtension', |
| 193 |
'-ext WixUIExtension', |
| 194 |
'-loc "%s"' % joinpath(info.packageWindowsPath, 'openmsx1033.wxl'), |
| 195 |
'"%s"' % openMSXObjFile, |
| 196 |
'"%s"' % openMSXExeObjFile, |
| 197 |
'"%s"' % openMSXDocObjFile, |
| 198 |
'"%s"' % openMSXShareObjFile, |
| 199 |
'"%s"' % openMSXIconObjFile, |
| 200 |
'"%s"' % ZMBVCodecObjFile, |
| 201 |
'"%s"' % ZMBVFilesObjFile, |
| 202 |
'"%s"' % catapultBinObjFile, |
| 203 |
'"%s"' % catapultDocObjFile, |
| 204 |
'"%s"' % catapultBitmapsObjFile, |
| 205 |
'"%s"' % catapultDialogsObjFile, |
| 206 |
'"%s"' % catapultIconsObjFile, |
| 207 |
'"%s"' % catapultReadmeObjFile, |
| 208 |
)) |
| 209 |
|
| 210 |
|
| 211 |
print(lightCmd) |
| 212 |
system(lightCmd) |
| 213 |
|
| 214 |
|
| 215 |
zipFileName = info.packageFileName + '-bin-msi.zip' |
| 216 |
zipFilePath = joinpath(info.packagePath, zipFileName) |
| 217 |
|
| 218 |
print('Generating ' + zipFilePath) |
| 219 |
zipFile = ZipFile(zipFilePath, 'w') |
| 220 |
zipFile.write(msiFilePath, msiFileName, ZIP_DEFLATED) |
| 221 |
zipFile.close() |
| 222 |
|
| 223 |
if __name__ == '__main__': |
| 224 |
if len(sys.argv) == 4: |
| 225 |
packageMSI(PackageInfo(*sys.argv[1 : ])) |
| 226 |
else: |
| 227 |
print( |
| 228 |
'Usage: py packagemsi.py ' |
| 229 |
'platform configuration catapultPath', |
| 230 |
file=sys.stderr |
| 231 |
) |
| 232 |
sys.exit(2) |