2018-01-10 12:20:13 -08:00
#!/usr/bin/env python
"""
2020-07-13 13:25:27 -04:00
Build an executable of gdbgui for the current platform
2018-01-10 12:20:13 -08:00
"""
import subprocess
2018-02-10 15:37:05 -08:00
from sys import platform
2018-01-10 12:20:13 -08:00
from gdbgui import __version__
2020-07-13 13:25:27 -04:00
import hashlib
from pathlib import Path
import logging
2018-02-10 15:37:05 -08:00
2020-07-13 13:25:27 -04:00
logging . basicConfig ( level = logging . INFO )
2018-01-10 12:20:13 -08:00
def write_spec_with_gdbgui_version_in_name ( spec_path , binary_name ) :
2021-08-28 21:27:42 -07:00
spec = f """ # This pyinstaller spec file was generated by { __file__ }
2017-12-19 12:01:27 -08:00
block_cipher = None
2020-08-23 23:07:10 -07:00
a = Analysis([ ' gdbgui/cli.py ' ], # noqa
2017-12-19 12:01:27 -08:00
pathex=[ ' . ' ],
binaries=[],
datas=[
( ' ./gdbgui/static* ' , ' ./static ' ),
( ' ./gdbgui/templates* ' , ' ./templates ' ),
( ' ./gdbgui/VERSION.txt* ' , ' ./ ' )
],
hiddenimports=[
' engineio.async_threading ' ,
2020-07-12 17:16:07 -07:00
' engineio.async_drivers.threading ' ,
' pkg_resources.py2_warn ' ,
2017-12-19 12:01:27 -08:00
],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
)
pyz = PYZ(a.pure, a.zipped_data, # noqa
cipher=block_cipher)
exe = EXE(pyz, # noqa
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
2020-07-13 13:25:27 -04:00
name= " { binary_name } " ,
2017-12-19 12:01:27 -08:00
debug=False,
strip=False,
upx=False,
runtime_tmpdir=None,
console=True)
2018-01-10 12:20:13 -08:00
2018-05-26 13:45:18 -07:00
"""
2018-01-10 12:20:13 -08:00
2018-05-26 13:45:18 -07:00
with open ( spec_path , " w+ " ) as f :
2018-01-10 12:20:13 -08:00
f . write ( spec )
2020-07-13 13:25:27 -04:00
def verify ( binary_path : str , version : str ) :
cmd = [ str ( binary_path ) , " --version " ]
logging . info ( f " Smoke test: Running { ' ' . join ( cmd ) } " )
proc = subprocess . run ( cmd , stdout = subprocess . PIPE )
output = proc . stdout . decode ( ) . strip ( )
if output != __version__ :
raise ValueError ( f " Expected { __version__ } . Got { output } " )
logging . info ( " Success! " )
def generate_md5 ( binary : Path , output_file : Path ) :
2020-08-22 19:06:42 -07:00
checksum = hashlib . md5 ( binary . read_bytes ( ) ) . hexdigest ( )
2020-07-13 13:25:27 -04:00
with open ( output_file , " w+ " ) as f :
2020-08-22 19:06:42 -07:00
f . write ( checksum + " \n " )
2020-07-13 13:25:27 -04:00
logging . info ( f " Wrote md5 to { output_file } " )
2018-01-10 12:20:13 -08:00
def main ( ) :
2018-05-26 13:45:18 -07:00
binary_name = " gdbgui_ %s " % __version__
2021-08-28 21:27:42 -07:00
spec_path = " gdbgui_pyinstaller.spec "
2021-08-29 21:31:21 -07:00
distpath = Path ( " build/executable " ) . resolve ( )
2020-07-13 13:25:27 -04:00
extension = " .exe " if platform == " win32 " else " "
binary_path = Path ( distpath ) / f " { binary_name } { extension } "
2018-01-10 12:20:13 -08:00
2020-07-13 13:25:27 -04:00
write_spec_with_gdbgui_version_in_name ( spec_path , binary_name )
subprocess . run (
2018-05-26 13:45:18 -07:00
[
" pyinstaller " ,
spec_path ,
" --distpath " ,
2020-07-13 13:25:27 -04:00
distpath ,
2022-06-21 21:41:01 -07:00
] ,
check = True ,
2018-05-26 13:45:18 -07:00
)
2020-07-13 13:25:27 -04:00
verify ( binary_path , __version__ )
generate_md5 ( binary_path , distpath / f " { binary_name } .md5 " )
logging . info ( f " Saved executable to { binary_path } " )
2018-01-10 12:20:13 -08:00
2018-05-26 13:45:18 -07:00
if __name__ == " __main__ " :
2018-01-10 12:20:13 -08:00
main ( )