forked from open-source-parsers/jsoncpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwscript
More file actions
225 lines (190 loc) · 6.92 KB
/
wscript
File metadata and controls
225 lines (190 loc) · 6.92 KB
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
VERSION='0.1.0'
APPNAME='CppUnit2'
srcdir = '.'
blddir = 'build'
import Options
import Logs
import UnitTest
import Utils
import os.path
import sys
import glob
CPPUT_EXAMPLES = '''
checking_assertions
ignore_failure_demo
input_test
light_fixture
log_demo
parametrized_test
stringize_demo
test_function
'''.split()
BROKEN_CPPUT_EXAMPLES = '''
input_based_test
opentest_demo
table_fixture
'''.split()
def _get_example_dirs():
return [ os.path.join( 'examples', d )
for d in CPPUT_EXAMPLES ]
def _get_main_script_dir():
"""Gets the path of the directory containing this script."""
# The main script path is only valid once the it has been executed, hence this can not be a global var.
assert Utils.g_module is not None
return os.path.split( Utils.g_module.root_path )[0]
def _fix_import_path():
"""Adds the main script directory to be able to import waftools modules."""
import_dir = _get_main_script_dir()
if import_dir not in sys.path:
sys.path.append( import_dir )
def _get_tool_dir():
return os.path.join( main_script_dir, 'waftools' )
def set_options(opt):
"""Always called first during the build."""
_fix_import_path()
import waftools.log_output
waftools.log_output.set_options( opt )
# Adds command-line options for compiler
opt.tool_options('compiler_cxx')
# from compiler_cxx tools, set_options
import Tools.ccroot as ccroot
opt.add_option('-d', '--debug-level',
action = 'store',
default = ccroot.DEBUG_LEVELS.RELEASE,
help = "Specify the debug level, does nothing if CXXFLAGS is set in the environment. [Allowed Values: '%s'] " % "', '".join(ccroot.DEBUG_LEVELS.ALL) +
"[default: %default]",
choices = ccroot.DEBUG_LEVELS.ALL,
dest = 'debug_level')
def init():
"""Called set_options() once the command-line has been parsed.
Command-line options value are accessed through Options.options.
"""
import waftools.log_output
waftools.log_output.init()
def configure(conf):
# There is a link issue with msvc 9!
conf.env['MSVC_VERSIONS'] = ['msvc 8.0']
# CXX=g++-3.0 ./waf.py configure will use g++-3.0 instead of 'g++'
conf.check_tool('compiler_cxx')
# Select debug/optimize flags
debug_level = Options.options.debug_level.upper()
conf.env.append_unique('CXXFLAGS', conf.env['CXXFLAGS_' + debug_level])
compiler = conf.env['COMPILER_CXX']
if compiler == 'msvc': # Microsoft Visual Studio specifics
# Select run-time library variant
if 'DEBUG' in debug_level:
crt_variant = 'MULTITHREADED_DLL_DBG'
else:
crt_variant = 'MULTITHREADED_DLL'
# MULTITHREADED, MULTITHREADED_DLL, MULTITHREADED_DBG, MULTITHREADED_DLL_DBG
conf.env.append_unique('CPPFLAGS', conf.env['CPPFLAGS_CRT_' + crt_variant])
conf.env.append_unique('CPPDEFINES', conf.env['CPPDEFINES_CRT_' + crt_variant])
## batched builds can be enabled by including the module optim_cc
# conf.check_tool('batched_cc')
# WAF command:
def build(bld):
# process subfolders from here
bld.add_subdirs('''src/cpptl
src/cpput
src/cpputtest''')
bld.add_subdirs( _get_example_dirs() )
def gen_examples_wscript(ctx):
for example_dir in _get_example_dirs():
wscript_path = os.path.join( example_dir, 'wscript_build' )
sources = glob.glob( os.path.join( example_dir, '*.cpp' ) )
Logs.info( 'Generating "%s"' % wscript_path )
open( wscript_path, 'wb' ).write( """\
#! /usr/bin/env python
# encoding: utf-8
# Baptiste Lepilleur, 2009
bld.new_task_gen(
features = 'cxx cprogram',
source = '''%(sources)s''',
includes = '../.. ../../include', # for examples/common
uselib_local = 'cpptl cpput',
name = 'example_%(name)s',
target = 'example_%(name)s' )
""" % {
'sources': ' '.join( [os.path.basename(s) for s in sources] ),
'name': os.path.basename( example_dir )
} )
def _fix_python_source( path, is_dry_run = True, verbose = True ):
"""Makes sure that all sources have unix EOL and replace tabs with 4 spaces."""
from waftools import reindent
if not os.path.isfile( path ):
raise ValueError( 'Path "%s" is not a file' % path )
try:
f = open(path, 'rb')
except IOError, msg:
print >> sys.stderr, "%s: I/O Error: %s" % (file, str(msg))
return False
if verbose:
print '%s =>' % path,
try:
r = reindent.Reindenter(f)
finally:
f.close()
if r.run(): # File need to be fixed ?
if not is_dry_run:
f = open(path, "wb")
try:
r.write(f)
finally:
f.close()
if verbose:
print is_dry_run and ' NEED FIX' or ' FIXED'
elif verbose:
print ' OK'
return True
def _fix_source_eol( path, is_dry_run = True, verbose = True, eol = '\n' ):
"""Makes sure that all sources have the specified eol sequence (default: unix)."""
if not os.path.isfile( path ):
raise ValueError( 'Path "%s" is not a file' % path )
try:
f = open(path, 'rb')
except IOError, msg:
print >> sys.stderr, "%s: I/O Error: %s" % (file, str(msg))
return False
try:
raw_lines = f.readlines()
finally:
f.close()
fixed_lines = [line.rstrip('\r\n') + eol for line in raw_lines]
if raw_lines != fixed_lines:
print '%s =>' % path,
if not is_dry_run:
f = open(path, "wb")
try:
f.writelines(fixed_lines)
finally:
f.close()
if verbose:
print is_dry_run and ' NEED FIX' or ' FIXED'
return True
def _do_fix( is_dry_run = True ):
from waftools import antglob
python_sources = antglob.glob( '.',
includes = '**/*.py **/wscript **/wscript_build',
excludes = antglob.default_excludes + './waf.py',
prune_dirs = antglob.prune_dirs + 'waf-* ./build' )
for path in python_sources:
_fix_python_source( path, is_dry_run )
cpp_sources = antglob.glob( '.',
includes = '**/*.cpp **/*.h **/*.inl',
prune_dirs = antglob.prune_dirs + 'waf-* ./build' )
for path in cpp_sources:
_fix_source_eol( path, is_dry_run )
def dry_fix(context):
_do_fix( is_dry_run = True )
def fix(context):
_do_fix( is_dry_run = False )
def shutdown():
pass
def check(context):
# Unit tests are run when "check" target is used
ut = UnitTest.unit_test()
ut.change_to_testfile_dir = True
ut.want_to_see_test_output = True
ut.want_to_see_test_error = True
ut.run()
ut.print_results()