-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSConstruct
277 lines (207 loc) · 9.46 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
#!/usr/bin/scons
#
# Top-level build file for the Dust Networks Serial Multiplexer
#
import sys
import os
import re
import SCons
from SCons.Script import *
import shutil
import platform
# TODO: if platform.uname()[0] starts with 'CYGWIN':
# print instructions for running under Windows
# OR support cygwin by running MSBuild using cmd.exe /C
# the shared/build directory is configured as a svn external, so it's always a
# subdirectory
sys.path += ['shared/build']
# Add some command line variables to SCons to support different build types.
command_line_options = Variables()
command_line_options.AddVariables(
('debug', 'Set to 1 to build with debugging enabled', 1),
('python', 'Path to the python interpreter', 'python'),
('boost_base', 'Path to the root of the Boost install', ''),
('boost_lib_suffix', 'Library name suffix for Boost libraries', ''),
('cxx', 'Name of the C++ compiler', 'g++'),
)
# Give some usage hints for this project
Help("""
Build Serial Mux using the Microsoft Visual Studio project:
scons mux
Build and release the Serial Mux:
scons release
Unit tests are built with the Boost Unit Test harness.
Run all unit tests with XML output:
\Python\Scripts\scons run-tests
Miscellaneous targets:
incr-version: increment the build number
""")
baseEnv = Environment(options = command_line_options)
# Ensure that no default targets exist, so you have to specify a target.
# Give some help about what targets are available.
def default(target, source, env): print SCons.Script.help_text
Default(baseEnv.Command('default', None, default))
# Find subversion
baseEnv['SVN_BINARY'] = 'svn.exe' # by default, trust that the path is good
# on Windows, make sure that the native subversion is used
SVN_PATH = [ os.path.join('\\','Program Files','CollabNet','Subversion Client'),
os.path.join('\\','Program Files','CollabNet Subversion'),
]
for d in SVN_PATH:
svn = os.path.join(d, 'svn.exe')
if os.path.isfile(svn):
baseEnv['SVN_BINARY'] = svn
# Paths
baseEnv['SHARED_DIR'] = '.'
baseEnv['VERSION_FILE'] = os.path.join('serial_mux', 'Version.h')
baseEnv['BUILD_FILE'] = os.path.join('serial_mux', 'Build.h')
baseEnv.Append(CPPPATH = ['$BOOST_BASE',
baseEnv['SHARED_DIR'] + '/shared/include',
baseEnv['SHARED_DIR'] + '/shared/include/cxxtest',
'serial_mux',
'ext-tools/LogUtilities'])
baseEnv.Append(LIBPATH = ['$BOOST_BASE' + '/stage/lib'])
# Build Tool Paths
def getLinuxEnv(baseEnv):
env = baseEnv.Clone()
env['ENGR_PUBLISH_DIR'] = os.path.join('/mnt', 'engineering', 'Software',
'Builds', 'SerialMux')
if env['boost_base']:
env['BOOST_BASE'] = env['boost_base']
else:
env['BOOST_BASE'] = os.path.join('/mnt', 'sdev', 'tools', 'boost', 'boost_1_46_1')
if env['cxx']:
env['CXX'] = env['cxx']
env.Append(CPPPATH = ['ext-tools'],
LINKFLAGS = ['-Wl,-Bstatic'], # link Boost libraries statically
LINKCOM = ' -Wl,-Bdynamic -lpthread', # some libraries must be dynamic
)
return env
def getOSXEnv(baseEnv):
env = baseEnv.Clone()
env['ENGR_PUBLISH_DIR'] = os.path.join('/Users', 'Shared', 'Software',
'Builds', 'SerialMux')
env['BOOST_BASE'] = os.path.join('/Users', 'Shared', 'boost', 'boost_1_46_1')
env.Append(CPPPATH = ['ext-tools'])
return env
def getWinEnv(baseEnv):
env = baseEnv.Clone()
env['ENGR_PUBLISH_DIR'] = os.path.join('\\\\filer01', 'Engineering', 'Software',
'Builds', 'SerialMux')
# Build configuration
env['DOTNET_VERSION'] = 'v4.0.30319'
env['NUNIT_VERSION'] = '2.5.7'
# TODO: support command line config of Build type
env['BUILD_CONFIGURATION'] = 'Release'
env['MSBuild'] = os.path.join('\\', 'Windows', 'Microsoft.NET', 'Framework',
env['DOTNET_VERSION'], 'MSBuild.exe')
env['NUnit'] = os.path.join('\\', 'Program Files', 'NUnit ' + env['NUNIT_VERSION'],
'bin', 'net-2.0', 'nunit-console.exe')
return env
if os.name in ['nt']:
baseEnv['platform'] = 'win32'
env = getWinEnv(baseEnv)
elif platform.system() in ['Linux']:
baseEnv['platform'] = 'linux'
env = getLinuxEnv(baseEnv)
elif platform.system() in ['Darwin']:
baseEnv['platform'] = 'osx'
env = getOSXEnv(baseEnv)
else:
env = baseEnv.Clone()
print 'Unknown platform:', platform.system()
# Serial Mux sources
serial_mux_sources = [ 'serial_mux/serial_mux.cpp',
'serial_mux/BasePicard.cpp',
'serial_mux/BoostClient.cpp',
'serial_mux/BoostClientListener.cpp',
'serial_mux/BoostClientManager.cpp',
'serial_mux/Common.cpp',
'serial_mux/HDLC.cpp',
'serial_mux/MuxMessageParser.cpp',
'serial_mux/PicardBoost.cpp',
'serial_mux/SerialMuxOptions.cpp',
'serial_mux/Subscriber.cpp',
'serial_mux/Version.cpp',
'ext-tools/LogUtilities/BoostLog.cpp',
]
# Serial Mux targets
if env['platform'] in ['win32']:
mux_exe = os.path.join(env['BUILD_CONFIGURATION'], 'serial_mux.exe')
sln = os.path.join('serial_mux.sln')
serial_mux = env.Command(mux_exe, sln,
Action('"%s" /target:serial_mux /property:Configuration=%s' %
(env['MSBuild'], env['BUILD_CONFIGURATION'])))
Alias('mux', serial_mux)
# NUnit tests
unittests_dll = os.path.join(env['BUILD_CONFIGURATION'], 'unit_tests.dll')
unittests = env.Command(unittests_dll, sln,
Action('"%s" /target:unit_tests /property:Configuration=%s' %
(env['MSBuild'], env['BUILD_CONFIGURATION'])))
runtests = env.Command('TestResults.xml', unittests,
Action('"%s" $SOURCES' % (env['NUnit'])))
Alias('run-tests', runtests)
elif env['platform'] in ['osx']:
mux_binary = 'serial_mux_%s' % env['platform']
serial_mux = env.Program(mux_binary, serial_mux_sources,
LIBS = ['boost_date_time',
'boost_program_options',
'boost_filesystem',
'boost_system',
'boost_thread',
'pthread'])
elif env['platform'] in ['linux']:
mux_binary = 'serial_mux_%s' % env['platform']
serial_mux = env.Program(mux_binary, serial_mux_sources,
LIBS = ['boost_date_time${boost_lib_suffix}',
'boost_program_options${boost_lib_suffix}',
'boost_filesystem${boost_lib_suffix}',
'boost_system${boost_lib_suffix}',
'boost_thread${boost_lib_suffix}',
])
Alias('mux', serial_mux)
# ----------------------------------------------------------------------
# Release actions
from VersionStandalone import CVersion
from SvnStandalone import SvnStandalone
env['Version'] = CVersion(env['VERSION_FILE'], env['BUILD_FILE'])
env['Svn'] = SvnStandalone(version_object = env['Version'])
get_version = env.Command('always.version', [ env['VERSION_FILE'], env['BUILD_FILE'] ],
'echo %s' % env['Version'].get_version_str())
Alias('get-version', get_version)
incr_version = env.Command('always.incr_build', env['BUILD_FILE'],
Action(env['Version'].increment_version_action))
Alias('incr-version', incr_version)
tag_incr = env.Command('always.tag_and_incr', [ ],
env['Svn'].tag_and_increment_action,
label='SerialMux_%s' % env['Version'].get_version_str(),
project_name='tools/SerialMux')
AlwaysBuild(tag_incr)
Alias('tag_incr', tag_incr)
def distribute_action(target, source, env):
'''
Publish the files to the release directory
'''
dry_run = env.has_key('dry_run') and bool(env['dry_run'])
if not os.path.isdir(env['DEST_DIR']) and not dry_run:
os.makedirs(env['DEST_DIR'])
for src in source:
print "Publishing %s to %s" % (src.path, env['DEST_DIR'])
#src_tail, src_ext = os.path.splitext(os.path.split(src.path)[1])
#dest_file = '%s_%s%s' % (src_tail, env['Version'].get_version_str(), src_ext)
dest_file = os.path.split(src.path)[1]
if not dry_run:
shutil.copyfile(src.path, os.path.join(env['DEST_DIR'], dest_file))
else:
print 'DRY RUN: copying %s to %s' % (src.path, os.path.join(env['DEST_DIR'], dest_file))
return 0
versioned_dir = os.path.join(env['ENGR_PUBLISH_DIR'],
'SerialMux_%s' % env['Version'].get_version_str())
# Ug. scons doesn't handle Windows server paths well. It assumes they are on
# the current drive (even with a \\ prefix). So we pass the destination
# through the environment.
env['DEST_DIR'] = versioned_dir
publish_exe = env.Command('always.publish', serial_mux,
Action(distribute_action))
Alias('publish', publish_exe)
Alias('release', [publish_exe, tag_incr])