-
Notifications
You must be signed in to change notification settings - Fork 0
/
sconstruct
executable file
·278 lines (235 loc) · 8.05 KB
/
sconstruct
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# This file is licensed under the MIT License.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
"""
Main SConstruct file for building the OpenDoorGL library along with tests.
"""
# python
import sys
import time
import datetime
import atexit
import os
start_time = time.time()
# SCons
import SCons.Action
from SCons.Environment import Environment
from SCons.Script import SConscript
from SCons.Script.Main import AddOption
from SCons.Script.Main import GetOption
# project
from BuildUtils import get_num_cpus
from BuildUtils import chmod_build_dir
from BuildUtils.SconsUtils import cppcheck_command
from BuildUtils import run_visual_tests
from BuildUtils import run_unit_tests
from BuildUtils.SconsUtils import display_build_status
from BuildUtils.ColorPrinter import ColorPrinter
from BuildUtils.SconsUtils import ProgressCounter
AddOption(
'--debug_build',
dest='debug_build',
action='store_true',
metavar='BOOL',
default=False,
help='Build in debug mode'
)
AddOption(
'--test',
dest='run_test',
action='store_true',
metavar='BOOL',
default=False,
help='run tests after build'
)
AddOption(
'--unit',
dest='run_unit',
action='store_true',
metavar='BOOL',
default=False,
help='run unit tests after build'
)
AddOption(
'--analyze',
dest='run_analyzer',
action='store_true',
metavar='BOOL',
default=False,
help='run clang static anaylyzer'
)
AddOption(
'--coverage',
dest='run_coverage',
action='store_true',
metavar='BOOL',
default=False,
help='run clang static anaylyzer'
)
SetOption('silent', True)
MAIN_ENV = Environment(
DEBUG_BUILD=GetOption('debug_build'),
TARGET_ARCH='x86_64',
RUN_TEST=GetOption('run_test'),
RUN_ANALYZER=GetOption('run_analyzer'),
RUN_GCOV=GetOption('run_coverage'),
INSTALLSTR='$NOTHING'
)
MAIN_ENV['PROJECT_DIR'] = MAIN_ENV.Dir('.').abspath.replace('\\', '/')
MAIN_ENV['BUILD_DIR'] = MAIN_ENV['PROJECT_DIR'] + "/build"
MAIN_ENV['PROGRESS'] = ProgressCounter()
###################################################
# Determine number of Jobs
# start by assuming num_jobs was not set
NUM_JOBS_SET = False
if GetOption("num_jobs") == 1:
# if num_jobs is the default we need to check sys.argv
# to see if the user happened to set the default
for arg in sys.argv:
if arg.startswith("-j") or arg.startswith("--jobs"):
if arg == "-j" or arg == "--jobs":
if int(sys.argv[sys.argv.index(arg)+1]) == 1:
NUM_JOBS_SET = True
else:
if arg.startswith("-j"):
if int(arg[2:]) == 1:
NUM_JOBS_SET = True
else:
# user must have set something if it wasn't default
NUM_JOBS_SET = True
# num_jobs wasn't specificed so let use the
# max number since the user doesn't seem to care
if not NUM_JOBS_SET:
NUM_CPUS = get_num_cpus()
ColorPrinter().InfoPrint(" Building with " + str(NUM_CPUS) + " parallel jobs")
MAIN_ENV.SetOption("num_jobs", NUM_CPUS)
else:
# user wants a certain number of jobs so do that
ColorPrinter().InfoPrint(
" Building with " + str(GetOption('num_jobs')) + " parallel jobs")
###
# build subProjects
DEPEND_LIBS = SConscript(
'Dependencies/sconscript',
duplicate=0,
exports='MAIN_ENV'
)
DEPENDS = DEPEND_LIBS['libs']
CORE_LIBS = SConscript(
'Core/sconscript',
exports='MAIN_ENV',
duplicate=0,
)
FRAMEWORK_LIBS = SConscript(
'AppFrameworks/sconscript',
duplicate=0,
exports='MAIN_ENV'
)
TESTS = SConscript(
'Testing/sconscript',
duplicate=0,
exports='MAIN_ENV'
)
def print_cmd_line(s, targets, sources, env):
with open(env['PROJECT_DIR'] + "/build/build_logs/build_" + datetime.datetime.fromtimestamp(time.time()).strftime('%Y_%m_%d__%H_%M_%S') + ".log", "a") as f:
f.write(s + "\n")
if(GetOption('no_progress')):
MAIN_ENV['PRINT_CMD_LINE_FUNC'] = print_cmd_line
Progress(MAIN_ENV['PROGRESS'], interval=1)
# setup installs
for header in DEPEND_LIBS['headers']['GLEW']:
MAIN_ENV.Install("build/include/GLEW", header)
for header in DEPEND_LIBS['headers']['GLFW']:
MAIN_ENV.Install("build/include/GLFW", header)
for header in DEPEND_LIBS['headers']['SOIL']:
MAIN_ENV.Install("build/include/SOIL", header)
for root, dirs, files in os.walk(str(DEPEND_LIBS['headers']['GLM']), topdown=False):
for name in files:
install_dir = root.replace(str(DEPEND_LIBS['headers']['GLM']), '')
MAIN_ENV.Install("build/include/glm" + install_dir,
os.path.join(root, name))
for lib in DEPEND_LIBS['libs']:
if str(lib).endswith(".dll"):
MAIN_ENV.Install("build/bin", lib)
else:
MAIN_ENV.Install("build/lib", lib)
for bin in DEPEND_LIBS['bins']:
MAIN_ENV.Install("build/bin", bin)
for buildFile in CORE_LIBS:
if str(buildFile).endswith(".hpp"):
MAIN_ENV.Install("build/include", buildFile)
elif str(buildFile).endswith(".dll"):
MAIN_ENV.Install("build/bin", buildFile)
elif 'Textures' in str(buildFile):
MAIN_ENV.Install("build/bin/resources", buildFile)
else:
MAIN_ENV.Install("build/lib", buildFile)
for buildFile in FRAMEWORK_LIBS:
if str(buildFile).endswith(".hpp"):
MAIN_ENV.Install("build/include", buildFile)
elif str(buildFile).endswith(".dll"):
MAIN_ENV.Install("build/bin", buildFile)
else:
MAIN_ENV.Install("build/lib", buildFile)
CHMOD_CALLBACK = SCons.Action.ActionFactory(
chmod_build_dir,
lambda: ColorPrinter().InfoString(' Setting build to exec permissions')
)
CHMOD_COMMAND = MAIN_ENV.Command('never_exists', 'build', CHMOD_CALLBACK())
MAIN_ENV.Depends(CHMOD_COMMAND, FRAMEWORK_LIBS)
MAIN_ENV.AlwaysBuild(CHMOD_COMMAND)
VISUAL_TEST_CALLBACK = SCons.Action.ActionFactory(
run_visual_tests,
lambda base_dir: ColorPrinter().InfoString(
' Running Visual Tests... Please be Patient')
)
UNIT_TEST_CALLBACK = SCons.Action.ActionFactory(
run_unit_tests,
lambda base_dir: ColorPrinter().InfoString(' Running Unit Tests...')
)
atexit.register(display_build_status, MAIN_ENV['PROJECT_DIR'], start_time)
TEST_BINS = []
for test in TESTS:
TEST_BINS.append(MAIN_ENV.Install("build/bin", test['executable']))
MAIN_ENV.Depends(CHMOD_COMMAND, test['executable'])
for resource in test['resources']:
MAIN_ENV.Install("build/bin/resources", resource)
if MAIN_ENV['RUN_ANALYZER']:
CPPCHECK_CALLBACK = SCons.Action.ActionFactory(
cppcheck_command,
lambda base_dir: ColorPrinter().InfoString(
' Analyzing code with Cppcheck, this will take a while...')
)
CPPCHECK_COMMAND = MAIN_ENV.Command(
'cppcheck_target',
'build',
CPPCHECK_CALLBACK(MAIN_ENV['PROJECT_DIR']))
if GetOption('run_unit'):
UNIT_TEST_COMMAND = MAIN_ENV.Command(
'unit_tests',
TEST_BINS,
UNIT_TEST_CALLBACK(MAIN_ENV['PROJECT_DIR']))
MAIN_ENV.Depends(UNIT_TEST_COMMAND, CHMOD_COMMAND)
MAIN_ENV.AlwaysBuild(UNIT_TEST_COMMAND)
if GetOption('run_test'):
VISUAL_TEST_COMMAND = MAIN_ENV.Command(
MAIN_ENV.Dir('Testing/VisualTests/SikuliX'),
TEST_BINS,
VISUAL_TEST_CALLBACK(MAIN_ENV['PROJECT_DIR']))
if GetOption('run_unit'):
MAIN_ENV.Depends(VISUAL_TEST_COMMAND, UNIT_TEST_COMMAND)
else:
MAIN_ENV.Depends(VISUAL_TEST_COMMAND, CHMOD_COMMAND)
MAIN_ENV.AlwaysBuild(VISUAL_TEST_COMMAND)
build_bin = MAIN_ENV.Dir('build/bin')
build_lib = MAIN_ENV.Dir('build/lib')
build_include = MAIN_ENV.Dir('build/include')
Return(['build_bin', 'build_lib', 'build_include'])