-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbuild.py
executable file
·176 lines (127 loc) · 3.8 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env python
""" CETech engine build script
"""
###########
# IMPORTS #
################################################################################
import argparse
import multiprocessing
import os
import platform
import shutil
import subprocess
import sys
###########
# GLOBALS #
################################################################################
CPU_COUNT = multiprocessing.cpu_count()
CPU_COUNT_STR = str(CPU_COUNT)
OS_NAME = platform.system().lower()
OS_ARCH = 64 if sys.maxsize > 2 ** 32 else 32
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
BUILD_DIR = os.path.abspath(os.path.join(ROOT_DIR, 'build'))
BIN_DIR = os.path.abspath(os.path.join(ROOT_DIR, 'bin'))
EXTERNAL_BUILD_DIR = os.path.abspath(
os.path.join(ROOT_DIR, 'externals', 'build'))
DEFAULT_BUILD = "%s%s" % (OS_NAME, OS_ARCH)
##########
# CONFIG #
################################################################################
# Command line actions.
ACTIONS = {
'',
'build',
'clean'
}
BUILD_ACTION = ('build', '')
# Build platform.
PLATFORMS = {
'linux64',
'darwin64',
}
def make_make(config, platform_, debug):
if not debug:
cmds = ['make']
else:
cmds = ['make']
return cmds
PLATFORMS_MAKE = {
'linux64': make_make,
'darwin64': make_make
}
########
# ARGS #
################################################################################
ARGS_PARSER = argparse.ArgumentParser(description='CETech build script')
ARGS_PARSER.add_argument(
"action",
help="Build action",
nargs='?', type=str, default='', choices=ACTIONS)
ARGS_PARSER.add_argument(
"-g", "--generate",
help='Only generate project files',
action='store_true')
# ARGS_PARSER.add_argument(
# "-c", "--config",
# help='Build configuration',
# default='develop', choices=CONFIG)
ARGS_PARSER.add_argument(
"-d", "--debug",
help='Debug build',
action='store_true')
ARGS_PARSER.add_argument(
"-p", "--platform",
default=DEFAULT_BUILD, choices=PLATFORMS, help='Target platform')
###########
# PROGRAM #
################################################################################
def run_cmake(config, platform_, action=''):
"""Run platform specific genie command.
"""
print('Runing cmake')
os.makedirs(BUILD_DIR, exist_ok=True)
os.chdir(BUILD_DIR)
cmds = ['cmake', os.pardir, '-DCMAKE_C_COMPILER=clang',
'-DCMAKE_CXX_COMPILER=clang++', '-DCMAKE_BUILD_TYPE=Debug']
subprocess.check_call(cmds)
def make(config, platform_, debug, generate_only=False):
"""Make build
:param config: Build configuration.
:param platform_: Build platform.
:param generate_only: Do not run build, only create projects files.
"""
run_cmake(config=config, platform_=platform_)
if not generate_only:
cmds = PLATFORMS_MAKE[platform_](config=config, platform_=platform_,
debug=debug)
subprocess.check_call(cmds)
def clean(config, platform_):
""" Remove build dir.
"""
print('Cleaning...')
try:
shutil.rmtree(BUILD_DIR)
except FileNotFoundError:
pass
try:
shutil.rmtree(BIN_DIR)
except FileNotFoundError:
pass
def main(args=None):
""" ENTRY POINT
"""
args = ARGS_PARSER.parse_args(args=args)
action = args.action
if action in BUILD_ACTION:
make(config=None, # args.config,
platform_=args.platform,
generate_only=args.generate,
debug=args.debug)
elif action == 'clean':
clean(config=None, platform_=args.platform)
########
# MAIN #
################################################################################
if __name__ == '__main__':
main()
################################################################################