Repository navigation
Expand file tree
/
Copy pathbuild.py
More file actions
112 lines (91 loc) · 3.15 KB
/
Copy pathbuild.py
File metadata and controls
112 lines (91 loc) · 3.15 KB
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
# type: ignore
"""Python script to build Swimming Canada Splash Utilities executable"""
import os
import shutil
import subprocess
import PyInstaller.__main__
import PyInstaller.utils.win32.versioninfo as vinfo
import semver # type: ignore
import app_version
print("Starting build process...\n")
# Remove any previous build artifacts
try:
shutil.rmtree("build")
except FileNotFoundError:
pass
# Remove any previous build artifacts
try:
shutil.rmtree("dist")
except FileNotFoundError:
pass
# Determine current git tag
git_ref = subprocess.check_output('git describe --tags --match "v*" --long', shell=True).decode("utf-8").rstrip()
APP_VERSION = app_version.git_semver(git_ref)
print(f"Building application, version: {APP_VERSION}")
version = semver.version.Version.parse(APP_VERSION)
with open("version.py", "w") as f:
f.write('"""Version information"""\n\n')
f.write(f'APP_VERSION = "{APP_VERSION}"\n')
# Sentry DSN
dsn = os.getenv("SENTRY_DSN")
if dsn is not None:
f.write(f'SENTRY_DSN = "{dsn}"\n')
else:
f.write("SENTRY_DSN = None\n")
f.flush()
f.close()
# Create file info to embed in executable
v = vinfo.VSVersionInfo(
ffi=vinfo.FixedFileInfo(
filevers=(version.major, version.minor, version.patch, 0),
prodvers=(version.major, version.minor, version.patch, 0),
mask=0x3F,
flags=0x0,
OS=0x4,
fileType=0x1,
subtype=0x0,
),
kids=[
vinfo.StringFileInfo(
[
vinfo.StringTable(
"040904e4",
[
# https://docs.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource
# Required fields:
vinfo.StringStruct("CompanyName", "Swimming Canada"),
vinfo.StringStruct("FileDescription", "Splash Utilities"),
vinfo.StringStruct("FileVersion", APP_VERSION),
vinfo.StringStruct("InternalName", "splashutilities"),
vinfo.StringStruct("ProductName", "Splash Utilities"),
vinfo.StringStruct("ProductVersion", APP_VERSION),
vinfo.StringStruct("OriginalFilename", "SplashUtilities.exe"),
# Optional fields
vinfo.StringStruct("LegalCopyright", "(c) NGN Management Inc."),
],
)
]
),
vinfo.VarFileInfo(
[
# 1033 -> Engligh; 1252 -> charsetID
vinfo.VarStruct("Translation", [1033, 1252])
]
),
],
)
with open("splashutilities.fileinfo", "w") as f:
f.write(str(v))
f.flush()
f.close()
print("Invoking PyInstaller to generate executable...\n")
# Build it
PyInstaller.__main__.run(["--distpath=dist", "--workpath=build", "splashutilities.spec"])
# Put back the original version.py
os.remove("version.py")
with open("version.py", "w") as f:
f.write('"""Version information"""\n\n')
f.write(f'APP_VERSION: str = "unreleased"\n')
f.write("SENTRY_DSN: str | None = None\n")
f.flush()
f.close()