/
SConstruct
235 lines (205 loc) · 8.5 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
import sys
import os
opts = Variables('Local.sc')
opts.AddVariables(
("CC", "C Compiler"),
("CPPPATH", "The list of directories that the C preprocessor "
"will search for include directories", []),
("CXX", "C++ Compiler"),
("CXXFLAGS", "Options that are passed to the C++ compiler", []),
("LINKFLAGS", "Options that are passed to the linker", []),
("AS", "Assembler"),
("LIBPATH", "Library paths that are passed to the linker", []),
("LINK", "Linker"),
("BUILDTYPE", "Build type (RELEASE or DEBUG)", "DEBUG"),
("VERBOSE", "Show full build information (0 or 1)", "0"),
("NUMCPUS", "Number of CPUs to use for build (0 means auto).", "0"),
)
env = Environment(options = opts,
tools = ['default', 'protoc', 'packaging'],
ENV = os.environ)
Help(opts.GenerateHelpText(env))
env.Prepend(CXXFLAGS = [
"-std=c++0x",
"-Wall",
"-Wextra",
"-Wcast-align",
"-Wcast-qual",
"-Wconversion",
"-Weffc++",
"-Wformat=2",
"-Wmissing-format-attribute",
"-Wno-non-template-friend",
"-Wno-unused-parameter",
"-Woverloaded-virtual",
"-Wwrite-strings",
"-DSWIG", # For some unknown reason, this suppresses some definitions in
# headers generated by protobuf 1.6 (but not 1.5) that we don't
# use and that cause warnings with -Weffc++.
])
if env["BUILDTYPE"] == "DEBUG":
env.Append(CPPFLAGS = [ "-g", "-DDEBUG" ])
elif env["BUILDTYPE"] == "RELEASE":
env.Append(CPPFLAGS = [ "-DNDEBUG", "-O2" ])
else:
print "Error BUILDTYPE must be RELEASE or DEBUG"
sys.exit(-1)
if env["VERBOSE"] == "0":
env["CCCOMSTR"] = "Compiling $SOURCE"
env["CXXCOMSTR"] = "Compiling $SOURCE"
env["SHCCCOMSTR"] = "Compiling $SOURCE"
env["SHCXXCOMSTR"] = "Compiling $SOURCE"
env["ARCOMSTR"] = "Creating library $TARGET"
env["LINKCOMSTR"] = "Linking $TARGET"
env.Append(CPPPATH = '#')
env.Append(CPPPATH = '#/include')
# Define protocol buffers builder to simplify SConstruct files
def Protobuf(env, source):
# First build the proto file
cc = env.Protoc(os.path.splitext(source)[0] + '.pb.cc',
source,
PROTOCPROTOPATH = ["."],
PROTOCPYTHONOUTDIR = ".",
PROTOCOUTDIR = ".")[1]
# Then build the resulting C++ file with no warnings
return env.StaticObject(cc,
CXXFLAGS = "-std=c++0x -Ibuild")
env.AddMethod(Protobuf)
def GetNumCPUs():
if env["NUMCPUS"] != "0":
return int(env["NUMCPUS"])
if os.sysconf_names.has_key("SC_NPROCESSORS_ONLN"):
cpus = os.sysconf("SC_NPROCESSORS_ONLN")
if isinstance(cpus, int) and cpus > 0:
return 2*cpus
else:
return 2
return 2*int(os.popen2("sysctl -n hw.ncpu")[1].read())
env.SetOption('num_jobs', GetNumCPUs())
object_files = {}
Export('object_files')
Export('env')
SConscript('Core/SConscript', variant_dir='build/Core')
SConscript('Event/SConscript', variant_dir='build/Event')
SConscript('RPC/SConscript', variant_dir='build/RPC')
SConscript('Protocol/SConscript', variant_dir='build/Protocol')
SConscript('Tree/SConscript', variant_dir='build/Tree')
SConscript('Client/SConscript', variant_dir='build/Client')
SConscript('Storage/SConscript', variant_dir='build/Storage')
SConscript('Server/SConscript', variant_dir='build/Server')
SConscript('test/SConscript', variant_dir='build/test')
SConscript('Examples/SConscript', variant_dir='build/Examples')
# This function is taken from http://www.scons.org/wiki/PhonyTargets
def PhonyTargets(env = None, **kw):
if not env: env = DefaultEnvironment()
for target,action in kw.items():
env.AlwaysBuild(env.Alias(target, [], action))
PhonyTargets(check = "scripts/cpplint.py")
PhonyTargets(lint = "scripts/cpplint.py")
PhonyTargets(doc = "doxygen docs/Doxyfile")
PhonyTargets(docs = "doxygen docs/Doxyfile")
PhonyTargets(tags = "ctags -R --exclude=build --exclude=docs .")
clientlib = env.StaticLibrary("build/logcabin",
(object_files['Client'] +
object_files['Tree'] +
object_files['Protocol'] +
object_files['RPC'] +
object_files['Event'] +
object_files['Core']))
env.Default(clientlib)
daemon = env.Program("build/LogCabin",
(["build/Server/Main.cc"] +
object_files['Server'] +
object_files['Storage'] +
object_files['Tree'] +
object_files['Protocol'] +
object_files['RPC'] +
object_files['Event'] +
object_files['Core']),
LIBS = [ "pthread", "protobuf", "rt", "cryptopp" ])
env.Default(daemon)
### scons install target
env.InstallAs('/etc/init.d/logcabin', 'scripts/logcabin-init-redhat')
env.InstallAs('/usr/bin/logcabind', 'build/LogCabin')
env.InstallAs('/usr/bin/logcabin-benchmark', 'build/Examples/Benchmark')
env.InstallAs('/usr/bin/logcabin-dumptree', 'build/Examples/DumpTree')
env.InstallAs('/usr/bin/logcabin-helloworld', 'build/Examples/HelloWorld')
env.InstallAs('/usr/bin/logcabin-reconfigure', 'build/Examples/Reconfigure')
env.InstallAs('/usr/bin/logcabin-serverstats', 'build/Examples/ServerStats')
env.InstallAs('/usr/bin/logcabin-smoketest', 'build/Examples/SmokeTest')
env.Alias('install', ['/etc', '/usr'])
#### 'scons rpm' target
# monkey-patch for SCons.Tool.packaging.rpm.collectintargz, which tries to put
# way too many files into the source tarball (the source tarball should only
# contain the installed files, since we're not building it)
def decent_collectintargz(target, source, env):
tarball = env['SOURCE_URL'].split('/')[-1]
from SCons.Tool.packaging import src_targz
tarball = src_targz.package(env, source=source, target=tarball,
PACKAGEROOT=env['PACKAGEROOT'])
return target, tarball
import SCons.Tool.packaging.rpm as RPMPackager
RPMPackager.collectintargz = decent_collectintargz
# set the install target in the .spec file to just copy over the files that
# 'scons install' would install. Default scons behavior is to invoke scons in
# the source tarball, which doesn't make a ton of sense unless you're doing the
# build in there.
install_commands = []
for target in env.FindInstalledFiles():
parent = target.get_dir()
source = target.sources[0]
install_commands.append('mkdir -p $RPM_BUILD_ROOT%s' % parent)
install_commands.append('cp %s $RPM_BUILD_ROOT%s' % (source, target))
VERSION = '0.0.1-alpha.0'
# https://fedoraproject.org/wiki/Packaging:NamingGuidelines#NonNumericRelease
RPM_VERSION = '0.0.1'
RPM_RELEASE = '0.1.alpha.0'
PACKAGEROOT = 'logcabin-%s' % RPM_VERSION
rpms=RPMPackager.package(env,
target = ['logcabin-%s' % RPM_VERSION],
source = env.FindInstalledFiles(),
X_RPM_INSTALL = '\n'.join(install_commands),
PACKAGEROOT = PACKAGEROOT,
NAME = 'logcabin',
VERSION = RPM_VERSION,
PACKAGEVERSION = RPM_RELEASE,
LICENSE = 'ISC',
SUMMARY = 'LogCabin is clustered consensus deamon',
X_RPM_GROUP = 'Application/logcabin',
DESCRIPTION =
'LogCabin is a distributed system that provides a small amount of\n'
'highly replicated, consistent storage. It is a reliable place for\n'
'other distributed systems to store their core metadata and\n'
'is helpful in solving cluster management issues. Although its key\n'
'functionality is in place, LogCabin is not yet recommended\n'
'for actual use.',
)
# Rename .rpm files into build/
def rename(env, target, source):
for (t, s) in zip(target, source):
os.rename(str(s), str(t))
# Rename files used to build .rpm files
def remove_sources(env, target, source):
garbage = set()
for s in source:
garbage.update(s.sources)
for s2 in s.sources:
garbage.update(s2.sources)
for g in list(garbage):
if str(g).endswith('.spec'):
garbage.update(g.sources)
for g in garbage:
if env['VERBOSE'] == '1':
print 'rm %s' % g
os.remove(str(g))
# Rename PACKAGEROOT directory and subdirectories (should be empty)
def remove_packageroot(env, target, source):
if env['VERBOSE'] == '1':
print 'rm -r %s' % PACKAGEROOT
import shutil
shutil.rmtree(str(PACKAGEROOT))
# Wrap cleanup around (moved) RPM targets
rpms = env.Command(['build/%s' % str(rpm) for rpm in rpms],
rpms,
[rename, remove_sources, remove_packageroot])
env.Alias('rpm', rpms)