-
Notifications
You must be signed in to change notification settings - Fork 0
/
qvibe-analyser.spec
189 lines (157 loc) · 5.42 KB
/
qvibe-analyser.spec
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# -*- mode: python -*-
import os
import platform
import distro
# work-around for https://github.com/pyinstaller/pyinstaller/issues/4064
import distutils
distutils_dir = getattr(distutils, 'distutils_path', None)
if distutils_dir is not None and distutils_dir.endswith('__init__.py'):
distutils.distutils_path = os.path.dirname(distutils.distutils_path)
generic_linux_excludes = [
'libstdc++.so.',
'libtinfo.so.',
'libreadline.so.',
'libdrm.so.'
]
fedora_excludes = [
'libgio-2.0.so.',
'libglib-2.0.so.',
'libfreetype.so.',
'libssl.so.',
'libfontconfig.so.'
]
debian_excludes = [
'libfontconfig.so.'
]
ubuntu_excludes = [
'libgpg-error.so.',
'libgtk-3.so.*',
'libgio-2.0.so.*'
]
linux_excludes = {
'ubuntu': generic_linux_excludes + ubuntu_excludes,
'linuxmint': generic_linux_excludes + ubuntu_excludes,
'fedora': generic_linux_excludes + fedora_excludes,
'centos': generic_linux_excludes + fedora_excludes,
'debian': generic_linux_excludes + debian_excludes
}
# helper functions
def get_icon_file():
'''
:return: the full path to the icon file for the current platform.
'''
return f"src/main/icons/{'icon.icns' if platform.system() == 'Darwin' else 'Icon.ico'}"
def use_nsis():
'''
:return: true if pyinstaller is being run in order to create an installer.
'''
return platform.system() == 'Windows' and 'USE_NSIS' in os.environ
def get_exe_args():
'''
:return: the *args to pass to EXE, varies according to whether we are in "create an installer" mode or not.
'''
return (a.scripts,) if use_nsis() is True else (a.scripts, a.binaries, a.zipfiles, a.datas)
def get_data_args():
'''
:return: the data array for the analysis.
'''
return [
('src/main/icons/Icon.ico', '.'),
('src/main/python/style', 'style'),
('src/main/python/VERSION', '.'),
]
def should_keep_binary(x):
'''
:param x: the binary (from Analysis.binaries)
:return: True if we should keep the given binary in the resulting output.
'''
if platform.system().lower().startswith('linux'):
dist = distro.linux_distribution(full_distribution_name=False)[0]
return not __is_exclude(x, linux_excludes.get(dist, generic_linux_excludes))
return True
def __is_exclude(x, excludes):
for exclude in excludes:
if x[0].startswith(exclude):
import sys
print(f"EXCLUDING {x}", file=sys.stderr)
return True
return False
def remove_platform_specific_binaries(a):
'''
Removes elements from the analysis based on the current platform.
Provides equivalent behaviour to https://github.com/mherrmann/fbs/tree/master/fbs/freeze
:param a: the pyinstaller analysis.
'''
a.binaries = [x for x in a.binaries if should_keep_binary(x) is True]
def get_exe_name():
'''
Gets the executable name which is qvibe-analyser for osx & windows and has some dist specific suffix for linux.
'''
if platform.system().lower().startswith('linux'):
linux_dist = distro.linux_distribution(full_distribution_name=False)
return f"qvibe-analyser_{'_'.join((x for x in linux_dist if x is not None and len(x) > 0))}"
return 'qvibe-analyser'
def get_binaries():
'''
:return: the ssl binaries if we're on windows and they exist.
'''
if platform.system() == 'Windows':
import os
ssl_dll = 'c:/Windows/System32/libssl-1_1-x64.dll'
crypto_dll = 'c:/Windows/System32/libcrypto-1_1-x64.dll'
if os.path.isfile(ssl_dll):
if os.path.isfile(crypto_dll):
return [
(ssl_dll, '.'),
(crypto_dll, '.'),
]
else:
print(f"MISSING libcrypto-1_1-x64.dll")
else:
print(f"MISSING libssl-1_1-x64.dll")
return None
block_cipher = None
spec_root = os.path.abspath(SPECPATH)
a = Analysis(['src/main/python/qvibe.py'],
pathex=[spec_root],
binaries=get_binaries(),
datas=get_data_args(),
hiddenimports=['numpy.random'],
hookspath=['hooks/'],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
remove_platform_specific_binaries(a)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(pyz,
*get_exe_args(),
name=get_exe_name(),
debug=False,
strip=False,
upx=False,
console=True,
exclude_binaries=use_nsis(),
icon=get_icon_file())
if platform.system() == 'Darwin':
app = BUNDLE(exe,
name='qvibe-analyser.app',
bundle_identifier='com.3ll3d00d.qvibe-analyser',
icon='src/main/icons/icon.icns',
info_plist={
'NSHighResolutionCapable': 'True',
'LSBackgroundOnly': 'False',
'NSRequiresAquaSystemAppearance': 'False',
'LSEnvironment': {
'PATH': '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:'
}
})
if use_nsis() is True:
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=False,
name='qvibe-analyser')