-
Notifications
You must be signed in to change notification settings - Fork 16
/
SConstruct
192 lines (154 loc) · 6.58 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
#!/usr/bin/env python
# -----------------------------------------------------------------------------
# The copyright notice below is for the SCons build scripts included with this
# software, which were initially developed by Michael Park
# (see https://github.com/mpark/bob) and customized at if(we). Many thanks to
# Michael for this useful contribution.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# The MIT License (MIT)
# Copyright (c) 2014 Michael Park
# Copyright (c) 2014 if(we)
#
# 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.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# -----------------------------------------------------------------------------
import filecmp
import os
import shutil
import stat
import subprocess
import sys
def is_path_prefix(path1, path2):
if path1 is None:
return True
c1 = path1.split('/')
if c1[-1] == '':
# Eliminate empty item after trailing '/'.
c1 = c1[:-1]
c2 = path2.split('/')
if len(c1) > len(c2):
return False
for i in range(len(c1)):
if c2[i] != c1[i]:
return False
return True
# Options.
AddOption('--test',
action='store_true',
help='Compile and execute unit tests.')
AddOption('--release',
action='store_true',
help='Build release targets (debug targets are built by default).')
AddOption('--import_path',
action='store_true',
help='Import PATH environment variable into build environment.')
AddOption('--asan',
action='store',
help='Enable or disable address sanitizer in debug build ' + \
'(ignored for production build).', dest='asan',
choices=('yes', 'no'), default='yes')
# Our mode.
if GetOption('release') is None:
mode = 'debug'
else:
mode = 'release'
# Paths.
root = Dir('#')
src = root.Dir('src')
third_party = src.Dir('third_party')
tclap = third_party.Dir('tclap-1.2.0').Dir('include')
gtestbasedir = third_party.Dir('googletest')
gtestincdir = gtestbasedir.Dir('googletest-release-1.7.0').Dir('include')
out_base = root.Dir('out')
out = out_base.Dir(mode)
if GetOption('clean'):
try:
shutil.rmtree(out_base.get_path())
except OSError:
pass
sys.exit(0)
if not is_path_prefix(src.get_abspath(), GetLaunchDir()):
sys.stderr.write('You must build from within the "src" part of the ' + \
'tree, unless you are doing a "clean" operation (-c option).\n')
sys.exit(1)
if not BUILD_TARGETS:
print 'No build target specified'
sys.exit(0)
# Look for Bruce's generated version file. If the file exists and its version
# string is incorrect, delete it. Deleting the file will cause the build to
# regenerate it with the correct version string.
def check_version_file(ver_file):
check_ver = src.Dir('bruce').Dir('scripts').File('gen_version') \
.get_abspath()
try:
subprocess.check_call([check_ver, '-c', ver_file]);
except subprocess.CalledProcessError:
sys.stderr.write(
'Failed to execute script that checks generated version file ' + \
ver_file +'\n')
sys.exit(1)
check_version_file(out.Dir('bruce').File('build_id.c').get_abspath())
check_version_file(out.Dir('bruce').Dir('client').File('build_id.c').
get_abspath())
# Environment.
prog_libs = {'pthread', 'dl', 'rt'}
env = Environment(CFLAGS=['-Wwrite-strings'],
CCFLAGS=['-Wall', '-Wextra', '-Werror', '-Wformat=2',
'-Winit-self', '-Wunused-parameter', '-Wshadow',
'-Wpointer-arith', '-Wcast-align', '-Wlogical-op'],
CPPDEFINES=[('SRC_ROOT', '\'"' + src.abspath + '"\'')],
CPPPATH=[src, tclap, gtestincdir],
CXXFLAGS=['-std=c++11', '-Wold-style-cast'],
DEP_SUFFIXES=['.cc', '.cpp', '.c', '.cxx', '.c++', '.C'],
PROG_LIBS=[lib for lib in prog_libs],
TESTSUFFIX='.test',
GENERATED_SOURCE_MAP={},
LIB_HEADER_MAP={})
if GetOption('import_path'):
env['ENV']['PATH'] = os.environ['PATH']
def set_debug_options():
# Note: If you specify -fsanitize=address, you must also specify
# -fno-omit-frame-pointer and be sure libasan is installed (RPM package
# libasan on RHEL, Fedora, and CentOS).
env.AppendUnique(CCFLAGS=['-g', '-fno-omit-frame-pointer',
'-fvisibility=hidden'])
env.AppendUnique(CXXFLAGS=['-D_GLIBCXX_DEBUG',
'-D_GLIBCXX_DEBUG_PEDANTIC'])
env.AppendUnique(LINKFLAGS=['-rdynamic'])
if GetOption('asan') == 'yes':
env.AppendUnique(CCFLAGS=['-fsanitize=address'])
env.AppendUnique(LINKFLAGS=['-fsanitize=address'])
def set_release_options():
# Enabling link-time optimizations breaks the build on Ubuntu 15, so for
# now we avoid enabling them. What a chore it is to get stuff to build on
# multiple platforms. :-(
env.AppendUnique(CCFLAGS=['-O2', '-DNDEBUG', '-Wno-unused',
'-Wno-unused-parameter', '-fvisibility=hidden'])
# Unfortunately this is needed to prevent spurious build errors on Ubuntu
# 14. :-(
env.AppendUnique(CPPFLAGS=['-U_FORTIFY_SOURCE'])
env.AppendUnique(LINKFLAGS=['-rdynamic'])
# Append 'mode' specific environment variables.
{'debug' : lambda: set_debug_options(),
'release': lambda: set_release_options()
}[mode]()
# Export variables.
Export(['env', 'src', 'out'])
# Run the SConscript file.
env.SConscript(src.File('SConscript'), variant_dir=out, duplicate=False)