Baptiste Lepilleur | 7c171ee | 2010-02-23 08:44:52 +0000 | [diff] [blame^] | 1 | VERSION='0.1.0'
|
| 2 | APPNAME='CppUnit2'
|
| 3 | srcdir = '.'
|
| 4 | blddir = 'build'
|
| 5 |
|
| 6 | import Options
|
| 7 | import Logs
|
| 8 | import UnitTest
|
| 9 | import Utils
|
| 10 | import os.path
|
| 11 | import sys
|
| 12 | import glob
|
| 13 |
|
| 14 | CPPUT_EXAMPLES = '''
|
| 15 | checking_assertions
|
| 16 | ignore_failure_demo
|
| 17 | input_test
|
| 18 | light_fixture
|
| 19 | log_demo
|
| 20 | parametrized_test
|
| 21 | stringize_demo
|
| 22 | test_function
|
| 23 | '''.split()
|
| 24 |
|
| 25 | BROKEN_CPPUT_EXAMPLES = '''
|
| 26 | input_based_test
|
| 27 | opentest_demo
|
| 28 | table_fixture
|
| 29 | '''.split()
|
| 30 |
|
| 31 | def _get_example_dirs():
|
| 32 | return [ os.path.join( 'examples', d )
|
| 33 | for d in CPPUT_EXAMPLES ]
|
| 34 |
|
| 35 | def _get_main_script_dir():
|
| 36 | """Gets the path of the directory containing this script."""
|
| 37 | # The main script path is only valid once the it has been executed, hence this can not be a global var.
|
| 38 | assert Utils.g_module is not None
|
| 39 | return os.path.split( Utils.g_module.root_path )[0]
|
| 40 |
|
| 41 | def _fix_import_path():
|
| 42 | """Adds the main script directory to be able to import waftools modules."""
|
| 43 | import_dir = _get_main_script_dir()
|
| 44 | if import_dir not in sys.path:
|
| 45 | sys.path.append( import_dir )
|
| 46 |
|
| 47 | def _get_tool_dir():
|
| 48 | return os.path.join( main_script_dir, 'waftools' )
|
| 49 |
|
| 50 | def set_options(opt):
|
| 51 | """Always called first during the build."""
|
| 52 | _fix_import_path()
|
| 53 | import waftools.log_output
|
| 54 | waftools.log_output.set_options( opt )
|
| 55 |
|
| 56 | # Adds command-line options for compiler
|
| 57 | opt.tool_options('compiler_cxx')
|
| 58 |
|
| 59 | # from compiler_cxx tools, set_options
|
| 60 | import Tools.ccroot as ccroot
|
| 61 | opt.add_option('-d', '--debug-level',
|
| 62 | action = 'store',
|
| 63 | default = ccroot.DEBUG_LEVELS.RELEASE,
|
| 64 | help = "Specify the debug level, does nothing if CXXFLAGS is set in the environment. [Allowed Values: '%s'] " % "', '".join(ccroot.DEBUG_LEVELS.ALL) +
|
| 65 | "[default: %default]",
|
| 66 | choices = ccroot.DEBUG_LEVELS.ALL,
|
| 67 | dest = 'debug_level')
|
| 68 |
|
| 69 | def init():
|
| 70 | """Called set_options() once the command-line has been parsed.
|
| 71 | Command-line options value are accessed through Options.options.
|
| 72 | """
|
| 73 | import waftools.log_output
|
| 74 | waftools.log_output.init()
|
| 75 |
|
| 76 |
|
| 77 | def configure(conf):
|
| 78 | # There is a link issue with msvc 9!
|
| 79 | conf.env['MSVC_VERSIONS'] = ['msvc 8.0']
|
| 80 |
|
| 81 | # CXX=g++-3.0 ./waf.py configure will use g++-3.0 instead of 'g++'
|
| 82 | conf.check_tool('compiler_cxx')
|
| 83 |
|
| 84 | # Select debug/optimize flags
|
| 85 | debug_level = Options.options.debug_level.upper()
|
| 86 | conf.env.append_unique('CXXFLAGS', conf.env['CXXFLAGS_' + debug_level])
|
| 87 |
|
| 88 | compiler = conf.env['COMPILER_CXX']
|
| 89 | if compiler == 'msvc': # Microsoft Visual Studio specifics
|
| 90 | # Select run-time library variant
|
| 91 | if 'DEBUG' in debug_level:
|
| 92 | crt_variant = 'MULTITHREADED_DLL_DBG'
|
| 93 | else:
|
| 94 | crt_variant = 'MULTITHREADED_DLL'
|
| 95 | # MULTITHREADED, MULTITHREADED_DLL, MULTITHREADED_DBG, MULTITHREADED_DLL_DBG
|
| 96 | conf.env.append_unique('CPPFLAGS', conf.env['CPPFLAGS_CRT_' + crt_variant])
|
| 97 | conf.env.append_unique('CPPDEFINES', conf.env['CPPDEFINES_CRT_' + crt_variant])
|
| 98 |
|
| 99 | ## batched builds can be enabled by including the module optim_cc
|
| 100 | # conf.check_tool('batched_cc')
|
| 101 |
|
| 102 |
|
| 103 | # WAF command:
|
| 104 |
|
| 105 | def build(bld):
|
| 106 | # process subfolders from here
|
| 107 | bld.add_subdirs('''src/cpptl
|
| 108 | src/cpput
|
| 109 | src/cpputtest''')
|
| 110 |
|
| 111 | bld.add_subdirs( _get_example_dirs() )
|
| 112 |
|
| 113 | def gen_examples_wscript(ctx):
|
| 114 | for example_dir in _get_example_dirs():
|
| 115 | wscript_path = os.path.join( example_dir, 'wscript_build' )
|
| 116 | sources = glob.glob( os.path.join( example_dir, '*.cpp' ) )
|
| 117 | Logs.info( 'Generating "%s"' % wscript_path )
|
| 118 | open( wscript_path, 'wb' ).write( """\
|
| 119 | #! /usr/bin/env python |
| 120 | # encoding: utf-8
|
| 121 | # Baptiste Lepilleur, 2009
|
| 122 |
|
| 123 | bld.new_task_gen(
|
| 124 | features = 'cxx cprogram',
|
| 125 | source = '''%(sources)s''',
|
| 126 | includes = '../.. ../../include', # for examples/common
|
| 127 | uselib_local = 'cpptl cpput',
|
| 128 | name = 'example_%(name)s',
|
| 129 | target = 'example_%(name)s' )
|
| 130 | """ % {
|
| 131 | 'sources': ' '.join( [os.path.basename(s) for s in sources] ),
|
| 132 | 'name': os.path.basename( example_dir )
|
| 133 | } )
|
| 134 |
|
| 135 | def _fix_python_source( path, is_dry_run = True, verbose = True ):
|
| 136 | """Makes sure that all sources have unix EOL and replace tabs with 4 spaces."""
|
| 137 | from waftools import reindent
|
| 138 | if not os.path.isfile( path ):
|
| 139 | raise ValueError( 'Path "%s" is not a file' % path )
|
| 140 | try:
|
| 141 | f = open(path, 'rb')
|
| 142 | except IOError, msg:
|
| 143 | print >> sys.stderr, "%s: I/O Error: %s" % (file, str(msg))
|
| 144 | return False
|
| 145 |
|
| 146 | if verbose:
|
| 147 | print '%s =>' % path,
|
| 148 | try:
|
| 149 | r = reindent.Reindenter(f)
|
| 150 | finally:
|
| 151 | f.close()
|
| 152 | if r.run(): # File need to be fixed ?
|
| 153 | if not is_dry_run:
|
| 154 | f = open(path, "wb")
|
| 155 | try:
|
| 156 | r.write(f)
|
| 157 | finally:
|
| 158 | f.close()
|
| 159 | if verbose:
|
| 160 | print is_dry_run and ' NEED FIX' or ' FIXED'
|
| 161 | elif verbose:
|
| 162 | print ' OK'
|
| 163 | return True
|
| 164 |
|
| 165 | def _fix_source_eol( path, is_dry_run = True, verbose = True, eol = '\n' ):
|
| 166 | """Makes sure that all sources have the specified eol sequence (default: unix)."""
|
| 167 | if not os.path.isfile( path ):
|
| 168 | raise ValueError( 'Path "%s" is not a file' % path )
|
| 169 | try:
|
| 170 | f = open(path, 'rb')
|
| 171 | except IOError, msg:
|
| 172 | print >> sys.stderr, "%s: I/O Error: %s" % (file, str(msg))
|
| 173 | return False
|
| 174 | try:
|
| 175 | raw_lines = f.readlines()
|
| 176 | finally:
|
| 177 | f.close()
|
| 178 | fixed_lines = [line.rstrip('\r\n') + eol for line in raw_lines]
|
| 179 | if raw_lines != fixed_lines:
|
| 180 | print '%s =>' % path,
|
| 181 | if not is_dry_run:
|
| 182 | f = open(path, "wb")
|
| 183 | try:
|
| 184 | f.writelines(fixed_lines)
|
| 185 | finally:
|
| 186 | f.close()
|
| 187 | if verbose:
|
| 188 | print is_dry_run and ' NEED FIX' or ' FIXED'
|
| 189 | return True
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 | def _do_fix( is_dry_run = True ):
|
| 194 | from waftools import antglob
|
| 195 | python_sources = antglob.glob( '.',
|
| 196 | includes = '**/*.py **/wscript **/wscript_build',
|
| 197 | excludes = antglob.default_excludes + './waf.py',
|
| 198 | prune_dirs = antglob.prune_dirs + 'waf-* ./build' )
|
| 199 | for path in python_sources:
|
| 200 | _fix_python_source( path, is_dry_run )
|
| 201 |
|
| 202 | cpp_sources = antglob.glob( '.',
|
| 203 | includes = '**/*.cpp **/*.h **/*.inl',
|
| 204 | prune_dirs = antglob.prune_dirs + 'waf-* ./build' )
|
| 205 | for path in cpp_sources:
|
| 206 | _fix_source_eol( path, is_dry_run )
|
| 207 |
|
| 208 |
|
| 209 | def dry_fix(context):
|
| 210 | _do_fix( is_dry_run = True )
|
| 211 |
|
| 212 | def fix(context):
|
| 213 | _do_fix( is_dry_run = False )
|
| 214 |
|
| 215 | def shutdown():
|
| 216 | pass
|
| 217 |
|
| 218 | def check(context):
|
| 219 | # Unit tests are run when "check" target is used
|
| 220 | ut = UnitTest.unit_test()
|
| 221 | ut.change_to_testfile_dir = True
|
| 222 | ut.want_to_see_test_output = True
|
| 223 | ut.want_to_see_test_error = True
|
| 224 | ut.run()
|
| 225 | ut.print_results()
|