Skip to content

Commit 7051b4b

Browse files
committed
Add build script
1 parent 3666955 commit 7051b4b

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

scripts/build.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
"""Script to build the OpenAndroidInstaller executable on different platforms with pyinstaller."""
2+
3+
# This file is part of OpenAndroidInstaller.
4+
# OpenAndroidInstaller is free software: you can redistribute it and/or modify it under the terms of
5+
# the GNU General Public License as published by the Free Software Foundation,
6+
# either version 3 of the License, or (at your option) any later version.
7+
8+
# OpenAndroidInstaller is distributed in the hope that it will be useful, but WITHOUT ANY
9+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11+
12+
# You should have received a copy of the GNU General Public License along with OpenAndroidInstaller.
13+
# If not, see <https://www.gnu.org/licenses/>."""
14+
# Author: Tobias Sterbak
15+
16+
import sys
17+
import subprocess
18+
from loguru import logger
19+
20+
21+
added_files = [
22+
("openandroidinstaller/assets", "assets"),
23+
("openandroidinstaller/bin", "bin"),
24+
]
25+
26+
27+
def build_linux():
28+
added_data = [f"--add-data={src}:{dst}" for src, dst in added_files]
29+
pyinstaller_options = [
30+
"--onefile",
31+
"--noconsole",
32+
"--noconfirm",
33+
"--windowed",
34+
"--clean",
35+
"--icon=openandroidinstaller/assets/favicon.ico",
36+
] + added_data
37+
38+
logger.info(f"Running pyinstaller with: {' '.join(pyinstaller_options)}")
39+
res = subprocess.call(
40+
["pyinstaller", "openandroidinstaller/openandroidinstaller.py"]
41+
+ pyinstaller_options,
42+
shell=False,
43+
)
44+
return res
45+
46+
47+
def build_macos():
48+
"""Build on MacOS."""
49+
added_data = [f"--add-data={src}:{dst}" for src, dst in added_files]
50+
pyinstaller_options = [
51+
"--onefile",
52+
"--noconsole",
53+
"--noconfirm",
54+
"--windowed",
55+
"--clean",
56+
"--icon=openandroidinstaller/assets/favicon.ico",
57+
] + added_data
58+
59+
logger.info(f"Running pyinstaller with: {' '.join(pyinstaller_options)}")
60+
res = subprocess.check_output(
61+
["pyinstaller", "openandroidinstaller/openandroidinstaller.py"]
62+
+ pyinstaller_options,
63+
stderr=subprocess.STDOUT,
64+
shell=False,
65+
)
66+
return res
67+
68+
69+
def build_windows():
70+
"""Build on windows."""
71+
added_data = [f"--add-data={src};{dst}" for src, dst in added_files]
72+
pyinstaller_options = [
73+
"--onefile",
74+
"--noconsole",
75+
"--noconfirm",
76+
"--windowed",
77+
"--clean",
78+
"--icon=openandroidinstaller\assetsf\avicon.ico",
79+
] + added_data
80+
81+
logger.info(f"Running pyinstaller with: {' '.join(pyinstaller_options)}")
82+
res = subprocess.check_output(
83+
["pyinstaller", "openandroidinstaller/openandroidinstaller.py"]
84+
+ pyinstaller_options,
85+
stderr=subprocess.STDOUT,
86+
shell=False,
87+
)
88+
return res
89+
90+
91+
def build():
92+
"""Run the build for your OS and save it in the current directory."""
93+
if sys.platform.startswith("linux"):
94+
logger.info("Building for Linux")
95+
res = build_linux()
96+
elif sys.platform.startswith("darwin"):
97+
logger.info("Building for macOS")
98+
res = build_macos()
99+
elif sys.platform.startswith("win"):
100+
logger.info("Building for Windows")
101+
build_windows()
102+
else:
103+
raise RuntimeError("Unsupported operating system")
104+
105+
106+
if __name__ == "__main__":
107+
build()

0 commit comments

Comments
 (0)