forked from KuhakuPixel/AceTheGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathACE_release.py
101 lines (91 loc) · 3.58 KB
/
ACE_release.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
"""
Make ACE's release for linux desktop and android (multi archs) automatically
This script run cmake and makefile to generate the build
for running a bash command in a directory
don't use cd but use cwd parameter
https://stackoverflow.com/questions/21406887/subprocess-changing-directory
"""
import subprocess
import os
import shutil
import multiprocessing
from typing import List
from util import assert_is_dir_and_exist, assert_is_file_and_exist, mkdir_overwrite
from build_option import ANDROID_ARCH_ABI_ARR, ANDROID_PLATFORM_TARGET
LINUX_RELEASE_DIR = "./linux"
ANDROID_RELEASE_DIR = "./android"
CMAKELIST_PATH = "./ACE/"
BUILD_DIR = "./build"
def gen_make_and_make_ACE(
build_dir: str,
install_dir: str,
CMAKElist_dir_path: str,
toolchain_path: str = None,
extra_args: List[str] = None,
# by default, use all cpu for fastest compilation
# https://unix.stackexchange.com/questions/208568/how-to-determine-the-maximum-number-to-pass-to-make-j-option
# https://stackoverflow.com/a/1006337/14073678
cpu_count_for_compile: int = multiprocessing.cpu_count(),
):
# recreate build and release directory in case its previously
# not empty
mkdir_overwrite(build_dir)
mkdir_overwrite(install_dir)
# get abs path when possible
assert_is_dir_and_exist(install_dir)
install_path = os.path.abspath(install_dir)
assert_is_dir_and_exist(CMAKElist_dir_path)
CMAKElist_path = os.path.abspath(CMAKElist_dir_path)
if toolchain_path != None:
assert_is_file_and_exist(toolchain_path)
toolchain_path = os.path.abspath(toolchain_path)
print(f"install path: {install_path}")
# generate makefile and run make
CMAKE_cmd_args = [
"cmake",
CMAKElist_path,
"-DCMAKE_BUILD_TYPE=Release",
# set install prefix
# https://stackoverflow.com/questions/6003374/what-is-cmake-equivalent-of-configure-prefix-dir-make-all-install
"-DCMAKE_INSTALL_PREFIX:PATH=" + install_path,
]
# append extra arguments
if extra_args != None:
CMAKE_cmd_args += extra_args
pass
# use custom toolchain if provided
if toolchain_path != None:
CMAKE_cmd_args.append("-DCMAKE_TOOLCHAIN_FILE=" + toolchain_path)
# run cmake
subprocess.run(CMAKE_cmd_args, cwd=build_dir)
# make the program and install to the specified target
subprocess.run(
["make", "all", "install", f"-j{cpu_count_for_compile}"], cwd=build_dir
)
def make_release(release_dir: str, android_toolchain_file: str):
# ============================ android =====================
# recreate build dir for building engine
android_release_dir = os.path.join(release_dir, ANDROID_RELEASE_DIR)
for arch in ANDROID_ARCH_ABI_ARR:
# create directory for specific arch release
current_android_release_dir = os.path.join(android_release_dir, arch)
#
gen_make_and_make_ACE(
build_dir=BUILD_DIR,
install_dir=current_android_release_dir,
CMAKElist_dir_path=CMAKELIST_PATH,
toolchain_path=android_toolchain_file,
extra_args=[
"-DANDROID_ABI=" + arch,
"-DANDROID_PLATFORM=" + ANDROID_PLATFORM_TARGET,
],
)
# ============================ linux =====================
# recreate build dir for building engine
linux_release_dir = os.path.join(release_dir, LINUX_RELEASE_DIR)
gen_make_and_make_ACE(
build_dir=BUILD_DIR,
install_dir=linux_release_dir,
CMAKElist_dir_path=CMAKELIST_PATH,
toolchain_path=None,
)