ncrewrite: Add --nop option for rewriting in the other direction
[nativeclient.git] / SConstruct
blobb038ce9d68e10cc514fc465c4f035b7d4eef0fe5
1 # -*- python -*-
2 # Copyright 2008, Google Inc.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
14 # distribution.
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 import glob
33 import os
34 import stat
35 import sys
36 sys.path.append("./common")
37 import nacl_util
40 # Underlay gtest
41 Dir('gtest').addRepository(Dir('../third_party/gtest/files'))
44 environment_list = []
46 # ----------------------------------------------------------
47 # Base environment for both nacl and non-nacl variants.
48 pre_base_env = Environment(
49 tools = ['component_setup'],
50 # Makes SOURCE_ROOT independent of site_init.
51 SOURCE_ROOT = Dir('#/../..').abspath,
52 # Publish dlls as final products (to staging).
53 COMPONENT_LIBRARY_PUBLISH = True,
55 pre_base_env.Append(BUILD_GROUPS=['most'])
56 # ----------------------------------------------------------
57 # Small tests are usually unit tests
59 def AddNodeToSmallTestsSuite(env, node):
60 Alias('small_tests', node)
62 pre_base_env.AddMethod(AddNodeToSmallTestsSuite)
64 # ----------------------------------------------------------
65 # Convenient alias
66 Alias('unit_tests', 'small_tests')
68 # ----------------------------------------------------------
69 # Medium tests are usually larger than unit tests, but don't take as much time
70 # as large tests
71 def AddNodeToMediumTestsSuite(env, node):
72 Alias('medium_tests', node)
74 pre_base_env.AddMethod(AddNodeToMediumTestsSuite)
76 # ----------------------------------------------------------
77 # Large tests are usually long tests
79 def AddNodeToLargeTestsSuite(env, node):
80 Alias('large_tests', node)
82 pre_base_env.AddMethod(AddNodeToLargeTestsSuite)
84 # ----------------------------------------------------------
86 def AddNodeToSmokeTestSuite(env, node):
87 env.Alias('smoke_test', node)
89 pre_base_env.AddMethod(AddNodeToSmokeTestSuite)
91 def _SmokeTestIntro(**args):
92 Banner("Running Smoke Test")
94 node = pre_base_env.Command(target='dummy',
95 source=[],
96 action=_SmokeTestIntro)
98 AlwaysBuild(node)
99 pre_base_env.AddNodeToSmokeTestSuite(node)
101 # ----------------------------------------------------------
102 def Banner(text):
103 print '=' * 70
104 print text
105 print '=' * 70
107 pre_base_env.AddMethod(Banner)
110 def FindLikelySelLdr(directory):
111 candidates = []
112 if (nacl_util.GetSelLdr('opt')):
113 candidates.append(nacl_util.GetSelLdr('opt'))
114 if (nacl_util.GetSelLdr('dbg')):
115 candidates.append(nacl_util.GetSelLdr('dbg'))
116 latest = (None, 0)
117 for c in candidates:
118 mtime = os.stat(c)[stat.ST_MTIME]
119 if mtime > latest[1]:
120 latest = (c, mtime)
121 return latest[0]
124 def CommandSelLdrTestNacl(env, name, exe, guess_sel_ldr=False, flags='" "',
125 stdin='None', stdout='None', filter='""',
126 stderr='None',
127 stderr_filter=('"^(NeverMatched AlwaysIgnoreStderr)'
128 '{999}"'),
129 exit_status=0,
130 log_golden='None', log_filter='".*"',
131 log_verbosity=2):
132 # the default for stderr_filter is a heuristic: it should only
133 # match the phrase "NeverMatched AlwaysIgnoreStderr" repeated 999
134 # times, so should serve as a filter that ignores all stderr
135 # output. (There is, AFAIK, no regexp that always fails to match.)
136 # Since for non-death tests we had been ignoring stderr output,
137 # this way we get (approximately) the same behavior.
138 script = '${SCONSTRUCT_DIR}/tools/sel_ldr_tester.py'
139 if guess_sel_ldr:
140 sel_ldr = FindLikelySelLdr(env.subst('$DESTINATION_ROOT'))
141 # Bail out if sel_ldr can't be found.
142 if not sel_ldr: return []
143 else:
144 sel_ldr = '$STAGING_DIR/${PROGPREFIX}sel_ldr${PROGSUFFIX}'
145 deps = [script, sel_ldr, exe]
146 if stdin != 'None': deps.append(stdin)
147 if stdout != 'None': deps.append(stdout)
148 log_output = 'None'
149 if log_golden != 'None':
150 log_output = '${TARGET}.log'
151 # TODO: consider redirecting output into tests/results
152 return env.Command(name, deps,
153 '$PYTHON ${SOURCES[0].abspath} '
154 '${SOURCES[1].abspath} '
155 '${SOURCES[2].abspath} '
156 '%s %s %s %s %s %s %d %s %s %d %s > $TARGET' % (
157 flags, stdin, stdout, filter,
158 stderr, stderr_filter, exit_status,
159 log_golden, log_filter, log_verbosity, log_output))
161 pre_base_env.AddMethod(CommandSelLdrTestNacl)
163 # ----------------------------------------------------------
164 if ARGUMENTS.get('pp', 0):
165 def CommandPrettyPrinter(cmd, targets, source, env):
166 prefix = env.subst('$SOURCE_ROOT') + '/googleclient/'
167 target = targets[0]
168 cmd_tokens = cmd.split()
169 if "python" in cmd_tokens[0]:
170 cmd_name = cmd_tokens[1]
171 else:
172 cmd_name = cmd_tokens[0].split('(')[0]
173 if cmd_name.startswith(prefix):
174 cmd_name = cmd_name[len(prefix):]
175 env_name = env.subst('${BUILD_TYPE}${BUILD_SUBTYPE}')
176 print '[%s] [%s] %s' % (cmd_name, env_name, target.get_path())
177 pre_base_env.Append(PRINT_CMD_LINE_FUNC = CommandPrettyPrinter)
179 # ----------------------------------------------------------
180 base_env = pre_base_env.Clone()
181 base_env.Append(
182 BUILD_SUBTYPE = '',
183 BUILD_SCONSCRIPTS = [
184 # NOTE: this dir also has a SConscript.nacl
185 'tests/npapi_bridge/SConscript',
186 'ncv',
187 'platform_qual_test',
188 'service_runtime',
189 'service_runtime/nrd_xfer_lib',
190 'tools/libsrpc',
191 'tools/npapi_runtime',
192 'intermodule_comm',
193 'npapi_plugin',
194 'npapi_plugin/install.scons',
195 'gtest',
196 'nonnacl_util',
197 # 'nacl_ie_plugin',
199 CPPDEFINES = [
200 ['NACL_BLOCK_SHIFT', '5'],
201 ['NACL_BLOCK_SIZE', '32'],
203 GEN2_FLAGS = '-c -f "Video|Audio|Multimedia"',
205 base_env.Replace(
206 SDL_HERMETIC_LINUX_DIR='$MAIN_DIR/../third_party/sdl/linux/v1_2_13',
207 SDL_HERMETIC_MAC_DIR='$MAIN_DIR/../third_party/sdl/osx/v1_2_13',
208 SDL_HERMETIC_WINDOWS_DIR='$MAIN_DIR/../third_party/sdl/win/v1_2_13',
213 # Optionally ignore the build process.
214 DeclareBit('prebuilt', 'Disable all build steps, only support install steps')
215 base_env.SetBitFromOption('prebuilt', False)
216 if base_env.Bit('prebuilt'):
217 base_env.Replace(BUILD_SCONSCRIPTS = ['npapi_plugin/install.scons'])
219 # Add the sdk root path (without setting up the tools).
220 base_env['NACL_SDK_ROOT_ONLY'] = True
221 base_env.Tool('naclsdk')
224 base_env.Help("""\
225 ======================================================================
226 Help for NaCl
227 ======================================================================
229 Common tasks:
230 -------------
232 * cleaning: scons -c
233 * build mandel: scons MODE=all mandel.nexe
234 * some unittests: scons small_tests
235 * a smoke test: scons -k pp=1 smoke_test
236 * 2nd smoke test: scons -k pp=1 MODE=nacl smoke_test
237 * documentation: scons MODE=doc
238 * firefox plugin: scons MODE=opt-linux npGoogleNaClPlugin
239 * sel_ldr: scons MODE=opt-linux sel_ldr
240 * firefox install: scons firefox_install
241 * firefox install pre-built copy : scons firefox_install --prebuilt
243 Options:
244 --------
245 pp=1 use command line pretty printing (more concise output)
246 sdl=<mode> where <mode>:
247 'none': don't use SDL (default)
248 'local': use locally installed SDL
249 'hermetic': use the hermetic SDL copy
250 naclsdk_mode=<mode> where <mode>:
251 'local': use locally installed sdk kit
252 'download': use the download copy (default)
253 'custom:<path>': use kit at <path>
255 --prebuilt Do not build things, just do install steps
257 Automagically generated help:
258 -----------------------------
259 """)
261 # ----------------------------------------------------------
262 windows_env = base_env.Clone(
263 tools = ['target_platform_windows'],
264 ASCOM = '$ASPPCOM /E | as -o $TARGET',
265 PDB = '${TARGET.base}.pdb',
267 windows_env.Append(
268 CPPDEFINES = [
269 ['NACL_WINDOWS', '1'],
270 ['NACL_OSX', '0'],
271 ['NACL_LINUX', '0'],
272 ['_WIN32_WINNT', '0x0501']
274 NACL_PLATFORM = 'win',
275 LIBS = ['wsock32', 'advapi32'],
276 CCFLAGS = ['/EHsc', '/WX'],
279 windows_debug_env = windows_env.Clone(
280 tools = ['target_debug'],
281 BUILD_TYPE = 'dbg-win',
282 BUILD_TYPE_DESCRIPTION = 'Windows debug build',
285 windows_debug_env.Append(BUILD_GROUPS = ['default'])
286 environment_list.append(windows_debug_env)
288 windows_optimized_env = windows_env.Clone(
289 tools = ['target_optimized'],
290 BUILD_TYPE = 'opt-win',
291 BUILD_TYPE_DESCRIPTION = 'Windows optimized build',
293 environment_list.append(windows_optimized_env)
295 if ARGUMENTS.get('sdl', 'hermetic') != 'none':
296 # These will only apply to sdl!=none builds!
297 windows_debug_env.Append(
298 CPPDEFINES = [
299 '_DLL',
300 '_MT'])
301 windows_optimized_env.Append(
302 CPPDEFINES = [
303 '_DLL',
304 '_MT'])
305 # SDL likes DLLs
306 if '/MT' in windows_optimized_env['CCFLAGS']:
307 windows_optimized_env.FilterOut(CCFLAGS=['/MT']);
308 windows_optimized_env.Append(CCFLAGS=['/MD']);
309 if '/MTd' in windows_debug_env['CCFLAGS']:
310 windows_debug_env.FilterOut(CCFLAGS=['/MTd']);
311 windows_debug_env.Append(CCFLAGS=['/MDd']);
312 # this doesn't feel right, but fixes dbg-win
313 windows_debug_env.Append(LINKFLAGS = ['/NODEFAULTLIB:msvcrt'])
314 # make source level debugging a little easier
315 if '/Z7' not in windows_debug_env['CCFLAGS']:
316 if '/Zi' not in windows_debug_env['CCFLAGS']:
317 windows_debug_env.Append(CCFLAGS=['/Z7'])
319 # ----------------------------------------------------------
321 unix_like_env = base_env.Clone()
322 unix_like_env.Append(
323 CCFLAGS = [
324 # '-malign-double',
325 '-Werror',
326 '-Wall',
327 # '-Wswitch-enum',
328 '-fvisibility=hidden',
329 '-Wno-unused-variable',
330 # '-Wsign-compare',
332 CFLAGS = ['-std=gnu99'],
333 LIBS = ['pthread', 'ssl', 'crypto'],
336 # ----------------------------------------------------------
338 mac_env = unix_like_env.Clone(
339 tools = ['target_platform_mac'],
340 # TODO: this should really be able to live in unix_like_env
341 # but can't due to what the target_platform_x module is
342 # doing.
343 LINK = '$CXX',
344 PLUGIN_SUFFIX = '.bundle',
346 mac_env.Append(
347 CPPDEFINES = [
348 ['NACL_WINDOWS', '0'],
349 ['NACL_OSX', '1'],
350 ['NACL_LINUX', '0'],
351 ['MAC_OS_X_VERSION_MIN_REQUIRED', 'MAC_OS_X_VERSION_10_4'],
353 NACL_PLATFORM = 'osx',
354 CCFLAGS = ['-mmacosx-version-min=10.4']
357 mac_debug_env = mac_env.Clone(
358 tools = ['target_debug'],
359 BUILD_TYPE = 'dbg-mac',
360 BUILD_TYPE_DESCRIPTION = 'MacOS debug build',
362 mac_debug_env.Append(BUILD_GROUPS = ['default'])
363 environment_list.append(mac_debug_env)
365 mac_optimized_env = mac_env.Clone(
366 tools = ['target_optimized'],
367 BUILD_TYPE = 'opt-mac',
368 BUILD_TYPE_DESCRIPTION = 'MacOS optimized build',
370 environment_list.append(mac_optimized_env)
372 # ----------------------------------------------------------
374 linux_env = unix_like_env.Clone(
375 tools = ['target_platform_linux'],
376 # TODO: this should really be able to live in unix_like_env
377 # but can't due to what the target_platform_x module is
378 # doing.
379 LINK = '$CXX',
382 # -m32 and -L/usr/lib32 are needed to do 32-bit builds on 64-bit
383 # user-space machines; requires ia32-libs-dev to be installed; or,
384 # failing that, ia32-libs and symbolic links *manually* created for
385 # /usr/lib32/libssl.so and /usr/lib32/libcrypto.so to the current
386 # /usr/lib32/lib*.so.version (tested with ia32-libs 2.2ubuntu11; no
387 # ia32-libs-dev was available for testing).
388 # Additional symlinks of this sort are needed for gtk,
389 # see nonnacl_util/SConscript.
391 linux_env.SetDefault(
392 # NOTE: look into http://www.scons.org/wiki/DoxygenBuilder
393 DOXYGEN = ARGUMENTS.get('DOXYGEN', '/usr/bin/doxygen'),
396 linux_env.Append(
397 ASFLAGS = [ '-m32', ],
398 CFLAGS = [ '-m32', ],
399 CCFLAGS = [ '-m32', ],
400 CPPDEFINES = [
401 ['NACL_WINDOWS', '0'],
402 ['NACL_OSX', '0'],
403 ['NACL_LINUX', '1'],
405 LIBS = ['rt'],
406 LINKFLAGS = [ '-m32', '-L/usr/lib32', ],
407 NACL_PLATFORM = 'linux',
411 linux_debug_env = linux_env.Clone(
412 tools = ['target_debug'],
413 BUILD_TYPE = 'dbg-linux',
414 BUILD_TYPE_DESCRIPTION = 'Linux debug build',
416 linux_debug_env.Append(BUILD_GROUPS = ['default'])
417 environment_list.append(linux_debug_env)
419 linux_optimized_env = linux_env.Clone(
420 tools = ['target_optimized'],
421 BUILD_TYPE = 'opt-linux',
422 BUILD_TYPE_DESCRIPTION = 'Linux optimized build',
424 environment_list.append(linux_optimized_env)
427 # ----------------------------------------------------------
428 # The nacl_env is used to build native_client modules
429 # using a special tool chain which produces platform
430 # independent binaries
431 # ----------------------------------------------------------
432 nacl_env = pre_base_env.Clone(
433 tools = ['naclsdk'],
434 BUILD_TYPE = 'nacl',
435 BUILD_TYPE_DESCRIPTION = 'NaCl module build',
436 # TODO: explain this
437 LINK = '$CXX',
438 # TODO: This doesn't work at the moment due to a scons
439 # limitation. Commented out until scons is fixed.
440 # hook for app to specify extra libraries
441 #LIBS = "$EXTRA_LIBS",
442 # optimize binaries
443 CCFLAGS = ['-O2', '-mfpmath=sse', '-msse', '-fomit-frame-pointer'],
444 # TODO: explain this
445 CPPPATH = ['$SOURCE_ROOT/googleclient'],
448 Banner('Building nexe binaries using sdk at [%s]' %
449 nacl_env.subst('$NACL_SDK_ROOT'))
452 nacl_env.Append(
453 BUILD_SCONSCRIPTS = [
454 #### ALPHABETICALLY SORTED ####
455 'intermodule_comm/SConscript.nacl',
458 'tests/app_lib/SConscript.nacl',
459 'tests/cloudfs/SConscript.nacl',
460 'tests/earth/SConscript.nacl',
461 'tests/fib/SConscript.nacl',
462 'tests/file/SConscript.nacl',
463 'tests/hello_world/SConscript.nacl',
464 'tests/imc_shm_mmap/SConscript.nacl',
465 'tests/life/SConscript.nacl',
466 'tests/mandel/SConscript.nacl',
467 'tests/mandel_nav/SConscript.nacl',
468 'tests/many/SConscript.nacl',
469 'tests/mmap/SConscript.nacl',
470 'tests/noop/SConscript.nacl',
471 'tests/npapi_bridge/SConscript.nacl',
472 'tests/npapi_hw/SConscript.nacl',
473 'tests/npapi_pi/SConscript.nacl',
474 'tests/nrd_xfer/SConscript.nacl',
475 'tests/null/SConscript.nacl',
476 'tests/srpc/SConscript.nacl',
477 'tests/srpc_hw/SConscript.nacl',
478 'tests/syscalls/SConscript.nacl',
479 'tests/threads/SConscript.nacl',
480 'tests/tone/SConscript.nacl',
481 'tests/voronoi/SConscript.nacl',
483 'tools/stubs/SConscript.nacl',
484 'tools/libnacl/SConscript.nacl',
485 'tools/libsrpc/SConscript.nacl',
486 'tools/nc_threads/SConscript.nacl',
487 'tools/libav/SConscript.nacl',
488 'tools/libunimpl/SConscript.nacl',
489 'tools/npapi_runtime/SConscript.nacl',
490 #### ALPHABETICALLY SORTED ####
494 # Uncomment this if you want the nacl stuff to be build by default.
495 #nacl_env.Append(BUILD_GROUPS = ['default'])
496 environment_list.append(nacl_env)
498 # ----------------------------------------------------------
499 # CODE COVERAGE
500 # ----------------------------------------------------------
501 # ----------------------------------------------------------
502 # VARIOUS HELPERS
503 # ----------------------------------------------------------
505 doc_env = pre_base_env.Clone(
506 BUILD_TYPE = 'doc',
507 BUILD_TYPE_DESCRIPTION = 'Documentation build',
508 HOST_PLATFORMS = '*',
510 doc_env.FilterOut(BUILD_GROUPS=['most'])
511 environment_list.append(doc_env)
512 doc_env.Append(
513 BUILD_SCONSCRIPTS = [
514 'documentation',
519 # ----------------------------------------------------------
521 # Blank out defaults.
522 Default(None)
524 BuildComponents(environment_list)
526 # Change default to build everything, but not run tests.
527 Default(['all_programs', 'all_bundles', 'all_test_programs', 'all_libraries'])
529 # ----------------------------------------------------------
532 # Generate a solution, defer to the end.
533 solution_env = base_env.Clone(tools = ['visual_studio_solution'])
534 solution = solution_env.Solution(
535 'nacl', environment_list,
536 exclude_pattern = '.*third_party.*',
537 extra_build_targets = {
538 'Firefox': 'c:/Program Files/Mozilla FireFox/firefox.exe',
541 solution_env.Alias('solution', solution)