From 8c16d81d8931daceacdb961a9a0633a7c0671880 Mon Sep 17 00:00:00 2001 From: bitraid Date: Fri, 20 Apr 2018 17:48:51 +0300 Subject: [PATCH] Pyinstaller: add VERSIONINFO resource to Windows executables. --- file_version_info.txt | 45 ++++++++++++++++++++++ misc/qutebrowser.spec | 3 +- scripts/dev/build_release.py | 4 ++ scripts/dev/gen_versioninfo.py | 68 ++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 file_version_info.txt create mode 100644 scripts/dev/gen_versioninfo.py diff --git a/file_version_info.txt b/file_version_info.txt new file mode 100644 index 000000000..a82dd4c93 --- /dev/null +++ b/file_version_info.txt @@ -0,0 +1,45 @@ +# UTF-8 +# +# For more details about fixed file info 'ffi' see: +# http://msdn.microsoft.com/en-us/library/ms646997.aspx +VSVersionInfo( + ffi=FixedFileInfo( + # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4) + # Set not needed items to zero 0. + filevers=(1, 2, 1, 0), + prodvers=(1, 2, 1, 0), + # Contains a bitmask that specifies the valid bits 'flags'r + mask=0x3f, + # Contains a bitmask that specifies the Boolean attributes of the file. + flags=0x0, + # The operating system for which this file was designed. + # 0x4 - NT and there is no need to change it. + OS=0x40004, + # The general type of file. + # 0x1 - the file is an application. + fileType=0x1, + # The function of the file. + # 0x0 - the function is not defined for this fileType + subtype=0x0, + # Creation date and time stamp. + date=(0, 0) + ), + kids=[ + StringFileInfo( + [ + StringTable( + u'040904B0', + [StringStruct(u'Comments', u'A keyboard-focused browser with a minimal GUI.'), + StringStruct(u'CompanyName', u'qutebrowser.org'), + StringStruct(u'FileDescription', u'qutebrowser'), + StringStruct(u'FileVersion', u'1.2.1'), + StringStruct(u'InternalName', u'qutebrowser'), + StringStruct(u'LegalCopyright', u'© 2014-2018 Florian Bruhin (The Compiler) '), + StringStruct(u'LegalTrademarks', u'qutebrowser is free software under the GNU General Public License'), + StringStruct(u'OriginalFilename', u'qutebrowser.exe'), + StringStruct(u'ProductName', u'qutebrowser'), + StringStruct(u'ProductVersion', u'1.2.1')]) + ]), + VarFileInfo([VarStruct(u'Translation', [1033, 1200])]) + ] +) diff --git a/misc/qutebrowser.spec b/misc/qutebrowser.spec index 8029e2a44..50a6ff888 100644 --- a/misc/qutebrowser.spec +++ b/misc/qutebrowser.spec @@ -59,7 +59,8 @@ exe = EXE(pyz, debug=False, strip=False, upx=False, - console=False ) + console=False, + version='file_version_info.txt' ) coll = COLLECT(exe, a.binaries, a.zipfiles, diff --git a/scripts/dev/build_release.py b/scripts/dev/build_release.py index 84e897eee..e0bcf80d5 100755 --- a/scripts/dev/build_release.py +++ b/scripts/dev/build_release.py @@ -40,6 +40,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, import qutebrowser from scripts import utils # from scripts.dev import update_3rdparty +from scripts.dev import gen_versioninfo def call_script(name, *args, python=sys.executable): @@ -232,6 +233,9 @@ def build_windows(): artifacts = [] + utils.print_title("Updating VersionInfo file") + gen_versioninfo + utils.print_title("Running pyinstaller 32bit") _maybe_remove(out_32) call_tox('pyinstaller', '-r', python=python_x86) diff --git a/scripts/dev/gen_versioninfo.py b/scripts/dev/gen_versioninfo.py new file mode 100644 index 000000000..2a96329d8 --- /dev/null +++ b/scripts/dev/gen_versioninfo.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2018 Florian Bruhin (The Compiler) +# +# This file is part of qutebrowser. +# +# qutebrowser 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 3 of the License, or +# (at your option) any later version. +# +# qutebrowser 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 qutebrowser. If not, see . + +"""Generate file_version_info.txt for Pyinstaller use with Windows builds.""" + +import os +import os.path +import sys + +from PyInstaller.utils.win32 import versioninfo + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, + os.pardir)) + +import qutebrowser + + +out_filename = 'file_version_info.txt' + +FileVersion = qutebrowser.__version_info__ + (0,) +ProductVersion = qutebrowser.__version_info__ + (0,) + +CommentText = "A keyboard-focused browser with a minimal GUI." +CopyrightText = "© 2014-2018 Florian Bruhin (The Compiler) \ +" +TrademarkText = "qutebrowser is free software under the GNU General Public \ +License" + +FixedFileInfo = versioninfo.FixedFileInfo(FileVersion, ProductVersion) + +StringFileInfo = [versioninfo.StringFileInfo( + [versioninfo.StringTable('040904B0', + [versioninfo.StringStruct('Comments',f'{CommentText}'), + versioninfo.StringStruct('CompanyName',"qutebrowser.org"), + versioninfo.StringStruct('FileDescription',"qutebrowser"), + versioninfo.StringStruct('FileVersion',f'{qutebrowser.__version__}'), + versioninfo.StringStruct('InternalName',"qutebrowser"), + versioninfo.StringStruct('LegalCopyright',f'{CopyrightText}'), + versioninfo.StringStruct('LegalTrademarks',f'{TrademarkText}'), + versioninfo.StringStruct('OriginalFilename',"qutebrowser.exe"), + versioninfo.StringStruct('ProductName',"qutebrowser"), + versioninfo.StringStruct('ProductVersion',f'{qutebrowser.__version__}')])]), + versioninfo.VarFileInfo([versioninfo.VarStruct('Translation', + [1033, 1200])])] + +VSVersionInfo = versioninfo.VSVersionInfo(FixedFileInfo, StringFileInfo) + +with open(out_filename, 'w', encoding='utf-8') as f: + f.write(f'{VSVersionInfo}') + +f.close()