Skip to content

Commit

Permalink
Added nuitka to build scripts
Browse files Browse the repository at this point in the history
Added nuitka as an option to the build scripts. Updated nuitka command to embed version info inside the executable so it doesn't have to be manually patched afterward. Also made version.rc more abstract and moved the values inside the build script so they can be shared.
  • Loading branch information
bradytheinventor committed Feb 5, 2024
1 parent b72f3db commit 06127d4
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 12 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ src/imd-tmp/*

*.code-workspace

#Linux build script
# nuitka build
main.build/*
main.dist/*
main.onefile-build/*

# Linux build script
tmp/*
.environment_setup_complete
build/tmp/*
Expand Down
48 changes: 44 additions & 4 deletions build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,39 @@

import os
import subprocess
import argparse

import version

# Script parameters
build_dir = os.path.dirname(__file__)

# Version information to be embedded inside executable (Windows only)
version_csv = f'{version.MAJOR}, {version.MINOR}, {version.PATCH}, 0'
version_literal = f'{version.MAJOR}.{version.MINOR}.{version.PATCH}.0'
company_name = "Team Ternate"
product_name = "Infinite Music Discs Generator"
file_description = "Add lots of custom music discs to Minecraft"
copyright = f"Copyright (c) {company_name}"

# Use argparse to decide whether to run nuitka or pyinstaller
# nuitka is only used on Windows at this time due to incompatibility with the Linux build environment
parser = argparse.ArgumentParser(prog=f"{product_name} Build Script",
description=f"Builds {product_name} for Windows or Linux")

parser.add_argument('-n', '--nuitka', action='store_true', help='Use nuitka to compile instead of pyinstaller')
args = parser.parse_args()

# Write a copy of 'version.rc' with the version numbers autopopulated from version.py
# Use **locals() to grab all currently-defined local variables and format the
# template 'version.rc' with them (grabs all locals as a dict and splats them with
# the ** operator into a flattened list)
with open(os.path.join(build_dir, 'version.rc'), 'r') as v_orig:
with open(os.path.join(build_dir, 'version.rc.tmp'), 'w') as v_temp:
for line in v_orig.readlines():
v_temp.write(line.format(version_csv=version_csv, version_literal=version_literal))
v_temp.write(line.format(**locals()))

# Run pyinstaller
# Raise exception if pyinstaller errors out; calling process can check STDERR to detect pass/fail
# Command to run pyinstaller
pyinstaller_cmd = [
'pyinstaller', 'main.pyw',
'--onefile',
Expand All @@ -34,4 +52,26 @@
'--workpath', 'build'
]

subprocess.run(pyinstaller_cmd, check=True)
# Command to run nuitka
nuitka_cmd = [
'python', '-m', 'nuitka', 'main.pyw',
'-o', 'imd-gui.exe',
'--onefile',
'--plugin-enable=pyside6',
'--disable-console',
'--include-data-dir=data=data',
'--windows-icon-from-ico=data/jukebox_256.ico',
f'--company-name={company_name}',
f'--product-name={product_name}',
f'--file-version={version_literal}',
f'--product-version={version_literal}',
f'--file-description={file_description}',
f'--copyright={copyright}'
]

# Build with selected program
# Raise exception if the build program errors out; calling process can check STDERR to detect pass/fail
if(args.nuitka):
subprocess.run(nuitka_cmd, check=True)
else:
subprocess.run(pyinstaller_cmd, check=True)
2 changes: 1 addition & 1 deletion build/build_wrapper_win.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python ./build/build.py
python ./build/build.py %*
8 changes: 4 additions & 4 deletions build/version.rc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ VSVersionInfo(
[
StringTable(
u'040904B0',
[StringStruct(u'CompanyName', u'Team Ternate'),
StringStruct(u'FileDescription', u'Add lots of custom music discs to Minecraft'),
[StringStruct(u'CompanyName', u'{company_name}'),
StringStruct(u'FileDescription', u'{file_description}'),
StringStruct(u'FileVersion', u'{version_literal}'),
StringStruct(u'InternalName', u'imd-gui'),
StringStruct(u'LegalCopyright', u'Copyright (c) Team Ternate'),
StringStruct(u'LegalCopyright', u'{copyright}'),
StringStruct(u'OriginalFilename', u'imd-gui.exe'),
StringStruct(u'ProductName', u'Infinite Music Discs Generator'),
StringStruct(u'ProductName', u'{product_name}'),
StringStruct(u'ProductVersion', u'{version_literal}')])
]),
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
Expand Down
2 changes: 1 addition & 1 deletion build_win.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
call ./build/build_wrapper_win.bat
call ./build/build_wrapper_win.bat %*
2 changes: 1 addition & 1 deletion build_win_nuitka.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python -m nuitka main.pyw -o imd-gui.exe --onefile --plugin-enable=pyside6 --disable-console --include-data-dir=data=data --windows-icon-from-ico=data/jukebox_256.ico
call build_win.bat --nuitka

0 comments on commit 06127d4

Please sign in to comment.