From 8c16d81d8931daceacdb961a9a0633a7c0671880 Mon Sep 17 00:00:00 2001 From: bitraid Date: Fri, 20 Apr 2018 17:48:51 +0300 Subject: [PATCH 1/4] 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() From 3f1041eb0aee4b418d102b3a9df126ac15d6b8d5 Mon Sep 17 00:00:00 2001 From: bitraid Date: Sun, 22 Apr 2018 20:35:34 +0300 Subject: [PATCH 2/4] gen_versioninfo.py: remove unused import, rename most variables and reformat --- scripts/dev/gen_versioninfo.py | 57 ++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/scripts/dev/gen_versioninfo.py b/scripts/dev/gen_versioninfo.py index 2a96329d8..6d7188880 100644 --- a/scripts/dev/gen_versioninfo.py +++ b/scripts/dev/gen_versioninfo.py @@ -20,49 +20,52 @@ """Generate file_version_info.txt for Pyinstaller use with Windows builds.""" -import os import os.path import sys -from PyInstaller.utils.win32 import versioninfo +from PyInstaller.utils.win32 import versioninfo as vs 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,) +filevers = qutebrowser.__version_info__ + (0,) +prodvers = qutebrowser.__version_info__ + (0,) +str_filevers = qutebrowser.__version__ +str_prodvers = qutebrowser.__version__ -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" +comment_text = """\ +A keyboard-focused browser with a minimal GUI.\ +""" +copyright_text = """\ +© 2014-2018 Florian Bruhin (The Compiler) \ +""" +trademark_text = """\ +qutebrowser is free software under the GNU General Public License\ +""" -FixedFileInfo = versioninfo.FixedFileInfo(FileVersion, ProductVersion) +ffi = vs.FixedFileInfo(filevers, prodvers) -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])])] +kids = [vs.StringFileInfo( + [vs.StringTable('040904B0', + [vs.StringStruct('Comments', f'{comment_text}'), + vs.StringStruct('CompanyName', "qutebrowser.org"), + vs.StringStruct('FileDescription', "qutebrowser"), + vs.StringStruct('FileVersion', f'{str_filevers}'), + vs.StringStruct('InternalName', "qutebrowser"), + vs.StringStruct('LegalCopyright', f'{copyright_text}'), + vs.StringStruct('LegalTrademarks', f'{trademark_text}'), + vs.StringStruct('OriginalFilename', "qutebrowser.exe"), + vs.StringStruct('ProductName', "qutebrowser"), + vs.StringStruct('ProductVersion', f'{str_prodvers}')])]), + vs.VarFileInfo([vs.VarStruct('Translation', [1033, 1200])])] -VSVersionInfo = versioninfo.VSVersionInfo(FixedFileInfo, StringFileInfo) +file_version_info = vs.VSVersionInfo(ffi, kids) with open(out_filename, 'w', encoding='utf-8') as f: - f.write(f'{VSVersionInfo}') + f.write(f'{file_version_info}') f.close() From 1e5b325ea5a5f63e13bb9ee89406e331b73cae4a Mon Sep 17 00:00:00 2001 From: bitraid Date: Thu, 3 May 2018 15:50:18 +0300 Subject: [PATCH 3/4] Move file_version_info.txt to misc/ and add it to .gitignore --- .gitignore | 1 + file_version_info.txt | 45 ---------------------------------- misc/qutebrowser.spec | 2 +- scripts/dev/gen_versioninfo.py | 2 +- 4 files changed, 3 insertions(+), 47 deletions(-) delete mode 100644 file_version_info.txt diff --git a/.gitignore b/.gitignore index 85233aa2f..b41285fd3 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ TODO /scripts/testbrowser/cpp/webengine/testbrowser /scripts/testbrowser/cpp/webengine/.qmake.stash /scripts/dev/pylint_checkers/qute_pylint.egg-info +/misc/file_version_info.txt diff --git a/file_version_info.txt b/file_version_info.txt deleted file mode 100644 index a82dd4c93..000000000 --- a/file_version_info.txt +++ /dev/null @@ -1,45 +0,0 @@ -# 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 50a6ff888..c886fb0c4 100644 --- a/misc/qutebrowser.spec +++ b/misc/qutebrowser.spec @@ -60,7 +60,7 @@ exe = EXE(pyz, strip=False, upx=False, console=False, - version='file_version_info.txt' ) + version='misc/file_version_info.txt') coll = COLLECT(exe, a.binaries, a.zipfiles, diff --git a/scripts/dev/gen_versioninfo.py b/scripts/dev/gen_versioninfo.py index 6d7188880..afdb09fb2 100644 --- a/scripts/dev/gen_versioninfo.py +++ b/scripts/dev/gen_versioninfo.py @@ -30,7 +30,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, import qutebrowser -out_filename = 'file_version_info.txt' +out_filename = 'misc/file_version_info.txt' filevers = qutebrowser.__version_info__ + (0,) prodvers = qutebrowser.__version_info__ + (0,) From 00199ae60e25c171b5e862b673943ab9e3e5455c Mon Sep 17 00:00:00 2001 From: bitraid Date: Sun, 10 Jun 2018 02:24:47 +0300 Subject: [PATCH 4/4] Corrections to gen_versioninfo.py script - Use main() function - Call utils.change_cwd() - Import info text - Don't use fstrings --- scripts/dev/build_release.py | 2 +- scripts/dev/gen_versioninfo.py | 64 +++++++++++++++++----------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/scripts/dev/build_release.py b/scripts/dev/build_release.py index e0bcf80d5..68d148747 100755 --- a/scripts/dev/build_release.py +++ b/scripts/dev/build_release.py @@ -234,7 +234,7 @@ def build_windows(): artifacts = [] utils.print_title("Updating VersionInfo file") - gen_versioninfo + gen_versioninfo.main() utils.print_title("Running pyinstaller 32bit") _maybe_remove(out_32) diff --git a/scripts/dev/gen_versioninfo.py b/scripts/dev/gen_versioninfo.py index afdb09fb2..29b86a59b 100644 --- a/scripts/dev/gen_versioninfo.py +++ b/scripts/dev/gen_versioninfo.py @@ -29,43 +29,43 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) import qutebrowser +from scripts import utils -out_filename = 'misc/file_version_info.txt' -filevers = qutebrowser.__version_info__ + (0,) -prodvers = qutebrowser.__version_info__ + (0,) -str_filevers = qutebrowser.__version__ -str_prodvers = qutebrowser.__version__ +def main(): + utils.change_cwd() + out_filename = 'misc/file_version_info.txt' -comment_text = """\ -A keyboard-focused browser with a minimal GUI.\ -""" -copyright_text = """\ -© 2014-2018 Florian Bruhin (The Compiler) \ -""" -trademark_text = """\ -qutebrowser is free software under the GNU General Public License\ -""" + filevers = qutebrowser.__version_info__ + (0,) + prodvers = qutebrowser.__version_info__ + (0,) + str_filevers = qutebrowser.__version__ + str_prodvers = qutebrowser.__version__ -ffi = vs.FixedFileInfo(filevers, prodvers) + comment_text = qutebrowser.__doc__ + copyright_text = qutebrowser.__copyright__ + trademark_text = "qutebrowser is free software under the GNU General Public License" -kids = [vs.StringFileInfo( - [vs.StringTable('040904B0', - [vs.StringStruct('Comments', f'{comment_text}'), - vs.StringStruct('CompanyName', "qutebrowser.org"), - vs.StringStruct('FileDescription', "qutebrowser"), - vs.StringStruct('FileVersion', f'{str_filevers}'), - vs.StringStruct('InternalName', "qutebrowser"), - vs.StringStruct('LegalCopyright', f'{copyright_text}'), - vs.StringStruct('LegalTrademarks', f'{trademark_text}'), - vs.StringStruct('OriginalFilename', "qutebrowser.exe"), - vs.StringStruct('ProductName', "qutebrowser"), - vs.StringStruct('ProductVersion', f'{str_prodvers}')])]), - vs.VarFileInfo([vs.VarStruct('Translation', [1033, 1200])])] + ffi = vs.FixedFileInfo(filevers, prodvers) -file_version_info = vs.VSVersionInfo(ffi, kids) + kids = [vs.StringFileInfo( + [vs.StringTable('040904B0', + [vs.StringStruct('Comments', comment_text), + vs.StringStruct('CompanyName', "qutebrowser.org"), + vs.StringStruct('FileDescription', "qutebrowser"), + vs.StringStruct('FileVersion', str_filevers), + vs.StringStruct('InternalName', "qutebrowser"), + vs.StringStruct('LegalCopyright', copyright_text), + vs.StringStruct('LegalTrademarks', trademark_text), + vs.StringStruct('OriginalFilename', "qutebrowser.exe"), + vs.StringStruct('ProductName', "qutebrowser"), + vs.StringStruct('ProductVersion', str_prodvers)])]), + vs.VarFileInfo([vs.VarStruct('Translation', [1033, 1200])])] -with open(out_filename, 'w', encoding='utf-8') as f: - f.write(f'{file_version_info}') + file_version_info = vs.VSVersionInfo(ffi, kids) -f.close() + with open(out_filename, 'w', encoding='utf-8') as f: + f.write(str(file_version_info)) + + +if __name__ == '__main__': + main()