qutebrowser/scripts/dev/freeze.py

136 lines
4.1 KiB
Python
Raw Normal View History

2014-09-22 20:21:00 +02:00
#!/usr/bin/env python3
2014-06-19 09:04:37 +02:00
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
2016-01-04 07:12:39 +01:00
# Copyright 2014-2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
2014-05-13 22:51:03 +02:00
#
# 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 <http://www.gnu.org/licenses/>.
"""cx_Freeze script for qutebrowser.
Builds a standalone executable.
"""
import os
import os.path
2014-05-13 22:51:03 +02:00
import sys
2014-08-26 19:10:14 +02:00
import distutils
2014-05-13 22:51:03 +02:00
import cx_Freeze as cx # pylint: disable=import-error,useless-suppression
2014-12-05 12:55:20 +01:00
# cx_Freeze is hard to install (needs C extensions) so we don't check for it.
2014-05-13 22:51:03 +02:00
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir,
2016-04-27 18:30:54 +02:00
os.pardir))
2014-08-26 19:10:14 +02:00
from scripts import setupcommon
2014-12-15 22:44:11 +01:00
BASEDIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
os.path.pardir, os.path.pardir)
2014-05-13 22:51:03 +02:00
def get_egl_path():
"""Get the path for PyQt5's libEGL.dll."""
if not sys.platform.startswith('win'):
return None
2014-08-26 19:10:14 +02:00
return os.path.join(distutils.sysconfig.get_python_lib(),
r'PyQt5\libEGL.dll')
2014-05-13 22:51:03 +02:00
def get_build_exe_options(skip_html=False):
"""Get the options passed as build_exe_options to cx_Freeze.
If either skip_html or --qute-skip-html as argument is given, doesn't
freeze the documentation.
"""
if '--qute-skip-html' in sys.argv:
skip_html = True
sys.argv.remove('--qute-skip-html')
include_files = [
('qutebrowser/javascript', 'javascript'),
('qutebrowser/img', 'img'),
('qutebrowser/git-commit-id', 'git-commit-id'),
('qutebrowser/utils/testfile', 'utils/testfile'),
('qutebrowser/html', 'html'),
]
if os.path.exists(os.path.join('qutebrowser', '3rdparty', 'pdfjs')):
include_files.append(('qutebrowser/3rdparty/pdfjs', '3rdparty/pdfjs'))
else:
print("Warning: excluding pdfjs as it's not present!")
if not skip_html:
include_files += [
('qutebrowser/html/doc', 'html/doc'),
]
egl_path = get_egl_path()
if egl_path is not None:
include_files.append((egl_path, 'libEGL.dll'))
return {
'include_files': include_files,
'include_msvcr': True,
'includes': [],
'excludes': ['tkinter'],
'packages': ['pygments', 'pkg_resources._vendor.packaging',
'pkg_resources._vendor.pyparsing',
'pkg_resources._vendor.six'],
}
2014-05-13 22:51:03 +02:00
2015-09-18 22:23:18 +02:00
def get_exe(base, target_name):
2015-09-19 22:03:56 +02:00
"""Get the qutebrowser cx.Executable to build."""
2015-09-18 22:23:18 +02:00
return cx.Executable('qutebrowser/__main__.py', base=base,
targetName=target_name, shortcutName='qutebrowser',
shortcutDir='ProgramMenuFolder',
icon=os.path.join(BASEDIR, 'icons',
'qutebrowser.ico'))
2014-05-13 22:51:03 +02:00
2015-09-18 22:33:50 +02:00
def main():
2015-09-18 22:23:18 +02:00
if sys.platform.startswith('win'):
base = 'Win32GUI'
target_name = 'qutebrowser.exe'
else:
base = None
target_name = 'qutebrowser'
2015-09-18 22:33:50 +02:00
bdist_msi_options = {
# random GUID generated by uuid.uuid4()
'upgrade_code': '{a7119e75-4eb7-466c-ae0d-3c0eccb45196}',
'add_to_path': False,
}
try:
setupcommon.write_git_file()
cx.setup(
2015-09-18 22:23:18 +02:00
executables=[get_exe(base, target_name)],
options={
'build_exe': get_build_exe_options(),
'bdist_msi': bdist_msi_options,
},
**setupcommon.setupdata
)
finally:
path = os.path.join(BASEDIR, 'qutebrowser', 'git-commit-id')
if os.path.exists(path):
os.remove(path)
2015-09-18 22:33:50 +02:00
if __name__ == '__main__':
main()