-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.py
124 lines (109 loc) · 4.1 KB
/
build.py
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
# Wahoo! Results - https://github.com/JohnStrunk/wahoo-results
# Copyright (C) 2022 - John D. Strunk
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Python script to build Wahoo! Results executable."""
import os
import shutil
import subprocess
import PyInstaller.__main__
import PyInstaller.utils.win32.versioninfo as vinfo
import semver # type: ignore
import wh_version
print("Starting build process...\n")
# Remove any previous build artifacts
try:
shutil.rmtree("build")
except FileNotFoundError:
pass
# Determine current git tag
git_ref = (
subprocess.check_output('git describe --tags --match "v*" --long', shell=True)
.decode("utf-8")
.rstrip()
)
wr_version = wh_version.git_semver(git_ref)
print(f"Building Wahoo Results, version: {wr_version}")
version = semver.version.Version.parse(wr_version)
with open("version.py", "w") as f:
f.write('"""Version information."""\n\n')
f.write(f'WAHOO_RESULTS_VERSION = "{wr_version}"\n')
# Sentry API key
dsn = os.getenv("SENTRY_DSN")
if dsn is not None:
f.write(f'SENTRY_DSN = "{dsn}"\n')
else:
f.write("SENTRY_DSN = None\n")
# Segment API key
segment = os.getenv("SEGMENT_WRITE_KEY")
if segment is None:
segment = "unknown"
f.write(f'SEGMENT_WRITE_KEY = "{segment}"\n')
# ipinfo.io
ipinfo = os.getenv("IPINFO_TOKEN")
if ipinfo is not None:
f.write(f'IPINFO_TOKEN = "{ipinfo}"\n')
else:
f.write("IPINFO_TOKEN = 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( # type: ignore
[
vinfo.StringTable( # type: ignore
"040904e4",
[
# https://docs.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource
# Required fields:
vinfo.StringStruct("CompanyName", "John D. Strunk"), # type: ignore
vinfo.StringStruct("FileDescription", "Wahoo! Results"), # type: ignore
vinfo.StringStruct("FileVersion", wr_version), # type: ignore
vinfo.StringStruct("InternalName", "wahoo_results"), # type: ignore
vinfo.StringStruct("ProductName", "Wahoo! Results"), # type: ignore
vinfo.StringStruct("ProductVersion", wr_version), # type: ignore
vinfo.StringStruct("OriginalFilename", "wahoo-results.exe"), # type: ignore
# Optional fields
vinfo.StringStruct( # type: ignore
"LegalCopyright", "(c) John D. Strunk - AGPL-3.0-or-later"
),
],
)
]
),
vinfo.VarFileInfo( # type: ignore
[
# 1033 -> Engligh; 1252 -> charsetID
vinfo.VarStruct("Translation", [1033, 1252]) # type: ignore
]
),
],
)
with open("wahoo-results.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=.", "--workpath=build", "wahoo-results.spec"])