cleanup build script
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 05 May 2011 14:27:14 +0200
changeset 6919d7af80f47f
parent 68 a384d3f2f086
child 70 f88649919a71
cleanup build script
ns3waf/__init__.py
ns3waf/__init__.pyc
wscript
     1.1 --- a/ns3waf/__init__.py	Thu May 05 09:49:28 2011 +0200
     1.2 +++ b/ns3waf/__init__.py	Thu May 05 14:27:14 2011 +0200
     1.3 @@ -399,12 +399,34 @@
     1.4      bld.install_files(os.path.join('${PREFIX}', 'lib', 'pkgconfig'), [target])
     1.5  
     1.6  class Module:
     1.7 -    def __init__(self, dirs, bld, name):
     1.8 -        self._source_dirs = dirs
     1.9 +    def __init__(self, bld, name, *k, **kw):
    1.10 +        self._source_dirs = _dirs(kw.get('source'))
    1.11          self._bld = bld
    1.12          self._name = name
    1.13 -    def add_tests(self, name = None, **kw):
    1.14 -        import copy
    1.15 +        needed = kw.get('needed', [])
    1.16 +        if modules_found(bld, needed):
    1.17 +            self._needed_ok = True
    1.18 +        else:
    1.19 +            self._needed_ok = False
    1.20 +            return
    1.21 +        kw['use'] = kw.get('use', []) + modules_uselib(bld, needed)
    1.22 +        _build_library(bld, name, *k, **kw)
    1.23 +        _build_headers(bld, name, kw.get('headers'))
    1.24 +        _build_pkgconfig(bld, name, kw.get('use', []))
    1.25 +    def add_example(self, needed = [], **kw):
    1.26 +        if not self._needed_ok:
    1.27 +            return
    1.28 +        if not self._bld.env['NS3_ENABLE_EXAMPLES']:
    1.29 +            return
    1.30 +        external = [i for i in needed if not i == self._name]
    1.31 +        if not modules_found(self._bld, external):
    1.32 +            return
    1.33 +        kw['use'] = kw.get('use', []) + modules_uselib(self._bld, needed)
    1.34 +        if 'features' not in kw:
    1.35 +            kw['features'] = 'cxx cxxprogram'
    1.36 +        self._bld(**kw)
    1.37 +
    1.38 +    def add_runner_test(self, needed = [], name = None, **kw):
    1.39          import os
    1.40          import tempfile
    1.41  
    1.42 @@ -413,24 +435,7 @@
    1.43          else:
    1.44              target='ns3test-%s' % self._name
    1.45          target = os.path.join('bin', target)
    1.46 -
    1.47 -        uselib = kw.get('use', [])
    1.48 -        if not modules_uselib(self._bld, [self._name]) in uselib:
    1.49 -            uselib = uselib + modules_uselib(self._bld, [self._name])
    1.50 -        kw['use'] = uselib
    1.51 -        kw['includes'] = kw.get('includes', []) + self._source_dirs
    1.52 -
    1.53 -        tmp = self._bld.path.relpath_gen(self._bld.srcnode)
    1.54 -        objects = []
    1.55 -        for src in kw['source']:
    1.56 -            src_target = '%s_object' % src
    1.57 -            objects.append(src_target)
    1.58 -            kw_copy = copy.copy (kw)
    1.59 -            path = os.path.dirname(os.path.join(tmp, src))
    1.60 -            kw_copy['source'] = [src]
    1.61 -            kw_copy['target'] = src_target
    1.62 -            kw_copy['defines'] = kw_copy.get('defines', []) + ['NS_TEST_SOURCEDIR=%s' % path]
    1.63 -            self._bld.objects(**kw_copy)
    1.64 +        kw['target'] = target
    1.65          handle, filename = tempfile.mkstemp(suffix='.cc')
    1.66          os.write (handle, """
    1.67  #include "ns3/test.h"
    1.68 @@ -441,25 +446,44 @@
    1.69  }
    1.70  """)
    1.71          os.close(handle)
    1.72 -        kw['source'] = [os.path.relpath(filename, self._bld.bldnode.abspath())]
    1.73 -        kw['use'] = uselib + objects
    1.74 -        kw['target'] = target
    1.75 +        kw['source'] = kw['source'] + [os.path.relpath(filename, self._bld.bldnode.abspath())]
    1.76 +        self.add_test(needed, **kw)
    1.77 +
    1.78 +    def add_test(self, needed = [], **kw):
    1.79 +        if not self._needed_ok:
    1.80 +            return
    1.81 +        if not self._bld.env['NS3_ENABLE_TESTS']:
    1.82 +            return
    1.83 +        external = [i for i in needed if not i == self._name]
    1.84 +        if not modules_found(self._bld, external):
    1.85 +            return
    1.86 +        kw['use'] = kw.get('use', []) + modules_uselib(self._bld, needed)
    1.87 +
    1.88 +        import copy
    1.89 +        import os
    1.90 +
    1.91 +        kw['includes'] = kw.get('includes', []) + self._source_dirs
    1.92 +
    1.93 +        tmp = self._bld.path.relpath_gen(self._bld.srcnode)
    1.94 +        objects = []
    1.95 +        for src in kw['source'][0:-1]:
    1.96 +            src_target = '%s_object' % src
    1.97 +            objects.append(src_target)
    1.98 +            kw_copy = copy.copy (kw)
    1.99 +            path = os.path.dirname(os.path.join(tmp, src))
   1.100 +            kw_copy['source'] = [src]
   1.101 +            kw_copy['target'] = src_target
   1.102 +            kw_copy['defines'] = kw_copy.get('defines', []) + ['NS_TEST_SOURCEDIR=%s' % path]
   1.103 +            self._bld.objects(**kw_copy)
   1.104 +        kw['use'] = kw.get('use', []) + objects
   1.105 +        kw['source'] = kw['source'][-1:]
   1.106 +        path = os.path.dirname(os.path.join(tmp, kw['source'][0]))
   1.107 +        kw['defines'] = kw.get('defines', []) + ['NS_TEST_SOURCEDIR=%s' % path]
   1.108          kw['install_path'] = None
   1.109 -        self._bld.program(**kw)
   1.110 +        if 'features' not in kw:
   1.111 +            kw['features'] = 'cxx cxxprogram'
   1.112 +        self._bld(**kw)
   1.113  
   1.114  
   1.115  def create_module(bld, name, *k, **kw):
   1.116 -    _build_library(bld, name, *k, **kw)
   1.117 -    _build_headers(bld, name, kw.get('headers'))
   1.118 -    _build_pkgconfig(bld, name, kw.get('use'))
   1.119 -    return Module(_dirs(kw.get('source')), bld, name)
   1.120 -
   1.121 -def build_program(bld, target=None, source = None, use = None):
   1.122 -    bld.program(source=source, target=target, use=use)
   1.123 -
   1.124 -def build_example(bld, target=None, source = None, use = None):
   1.125 -    if bld.env['NS3_ENABLE_EXAMPLES']:
   1.126 -        bld.program(source=source, target=target, use=use)
   1.127 -
   1.128 -
   1.129 -
   1.130 +    return Module(bld, name, *k, **kw)
     2.1 Binary file ns3waf/__init__.pyc has changed
     3.1 --- a/wscript	Thu May 05 09:49:28 2011 +0200
     3.2 +++ b/wscript	Thu May 05 14:27:14 2011 +0200
     3.3 @@ -77,23 +77,20 @@
     3.4      module_headers = [
     3.5          'netlink/netlink-socket-factory.h'
     3.6          ]
     3.7 -    if ns3waf.modules_found(bld, ['internet', 'core']):
     3.8 -        uselib = ns3waf.modules_uselib(bld, ['internet', 'core'])
     3.9 -        module = ns3waf.create_module(bld, name='netlink',
    3.10 -                                      source=module_source,
    3.11 -                                      headers=module_headers,
    3.12 -                                      use=uselib)
    3.13 +    module = ns3waf.create_module(bld, 
    3.14 +                                  name='netlink',
    3.15 +                                  needed = ['internet', 'core'],
    3.16 +                                  source=module_source,
    3.17 +                                  headers=module_headers)
    3.18  
    3.19 -        if ns3waf.modules_found(bld, ['point-to-point']):
    3.20 -            module_tests = [
    3.21 -                'test/netlink-socket-test.cc',
    3.22 -                ]
    3.23 -            uselib = ns3waf.modules_uselib(bld, ['internet', 
    3.24 -                                                 'point-to-point', 
    3.25 -                                                 'core'])
    3.26 -            module.add_tests(source=module_tests, use = uselib)
    3.27 +    module_tests = [
    3.28 +        'test/netlink-socket-test.cc',
    3.29 +        ]
    3.30 +    module.add_runner_test(needed = ['internet', 'point-to-point', 'core', 'netlink'],
    3.31 +                           source=module_tests)
    3.32  
    3.33 -def create_dce_program(bld, **kw):
    3.34 +def dce_kw(**kw):
    3.35 +    d = dict(**kw)
    3.36      if os.uname()[4] == 'x86_64':
    3.37          mcmodel = ['-mcmodel=large']
    3.38      else:
    3.39 @@ -101,19 +98,15 @@
    3.40      nofortify = ['-U_FORTIFY_SOURCE']
    3.41      #debug_dl = ['-Wl,--dynamic-linker=/usr/lib/debug/ld-linux-x86-64.so.2']
    3.42      debug_dl = []
    3.43 -    kw['cxxflags'] = kw.get('cxxflags', []) + ['-fpie'] + mcmodel + nofortify
    3.44 -    kw['cflags'] = kw.get('cflags', []) + ['-fpie'] + mcmodel + nofortify
    3.45 -    kw['linkflags'] = kw.get('linkflags', []) + ['-pie'] + debug_dl
    3.46 -    bld.program(**kw)
    3.47 +    d['cxxflags'] = d.get('cxxflags', []) + ['-fpie'] + mcmodel + nofortify
    3.48 +    d['cflags'] = d.get('cflags', []) + ['-fpie'] + mcmodel + nofortify
    3.49 +    d['linkflags'] = d.get('linkflags', []) + ['-pie'] + debug_dl
    3.50 +    return d
    3.51  
    3.52 -def new_test(bld,name,uselib):
    3.53 -    obj = create_dce_program(bld, target='bin/' + name, source = ['test/' + name + '.cc'],
    3.54 -                             use = uselib + ['lib/test'])
    3.55 -
    3.56 -
    3.57 -def build_dce_tests(bld):
    3.58 -    test = bld.shlib(source=['test/test-macros.cc'], target='lib/test',
    3.59 -                     linkflags=['-Wl,-soname=libtest.so'])
    3.60 +def build_dce_tests(module):
    3.61 +    module.add_runner_test(needed=['core', 'dce', 'internet'], source=['test/dce-manager-test.cc'])
    3.62 +    module.add_test(features='cxx cxxshlib', source=['test/test-macros.cc'], 
    3.63 +                    target='lib/test', linkflags=['-Wl,-soname=libtest.so'])
    3.64  
    3.65      tests = [['test-empty', []],
    3.66               ['test-sleep', []],
    3.67 @@ -140,52 +133,43 @@
    3.68               ['test-fork', []],
    3.69               ]
    3.70      for name,uselib in tests:
    3.71 -        new_test(bld, name, uselib)
    3.72 +        module.add_test(**dce_kw(target='bin/' + name, source = ['test/' + name + '.cc'],
    3.73 +                                 use = uselib + ['lib/test']))
    3.74  
    3.75 -def build_example(bld, needed, **kw):
    3.76 -    external = [i for i in needed if not i == 'dce' ]
    3.77 -    if not ns3waf.modules_found(bld, external):
    3.78 -        return
    3.79 -    kw['use'] = kw.get('use', []) + ns3waf.modules_uselib(bld, needed)
    3.80 -    bld.program(**kw)
    3.81 +def build_dce_examples(module):
    3.82 +    dce_examples = [['udp-server', []],
    3.83 +                    ['udp-client', []],
    3.84 +                    ['udp-perf', ['m']],
    3.85 +                    ['tcp-server', []],
    3.86 +                    ['tcp-client', []],
    3.87 +                    ]
    3.88 +    for name,lib in dce_examples:
    3.89 +        module.add_example(**dce_kw(target = 'bin/' + name, 
    3.90 +                                    source = ['example/' + name + '.cc'],
    3.91 +                                    lib = lib))
    3.92 +
    3.93 +    module.add_example(needed = ['core', 'internet', 'dce'], 
    3.94 +                       target='bin/dce-tcp-simple',
    3.95 +                       source=['example/dce-tcp-simple.cc'])
    3.96 +
    3.97 +    module.add_example(needed = ['core', 'internet', 'dce'], 
    3.98 +                       target='bin/dce-udp-simple',
    3.99 +                       source=['example/dce-udp-simple.cc'])
   3.100      
   3.101 +    module.add_example(needed = ['core', 'internet', 'dce', 'point-to-point'], 
   3.102 +                       target='bin/dce-udp-perf',
   3.103 +                       source=['example/dce-udp-perf.cc'])
   3.104  
   3.105 -def build_dce_examples(bld):
   3.106 -    create_dce_program(bld, target = 'bin/udp-server', 
   3.107 -                       source = ['example/udp-server.cc'])
   3.108 -    create_dce_program(bld, target = 'bin/udp-client', 
   3.109 -                       source = ['example/udp-client.cc'])
   3.110 -    create_dce_program(bld, target = 'bin/tcp-server', 
   3.111 -                       source = ['example/tcp-server.cc'])
   3.112 -    create_dce_program(bld, target = 'bin/tcp-client', 
   3.113 -                       source = ['example/tcp-client.cc'])
   3.114 -    create_dce_program(bld, target = 'bin/tcp-loopback', 
   3.115 -                       source = ['example/tcp-loopback.cc'])
   3.116 -    create_dce_program(bld, target = 'bin/udp-perf', 
   3.117 -                       source = ['example/udp-perf.cc'],
   3.118 -                       lib='m')
   3.119  
   3.120 -    build_example(bld, ['core', 'internet', 'dce'], 
   3.121 -                  target='bin/dce-tcp-simple',
   3.122 -                  source=['example/dce-tcp-simple.cc'])
   3.123 +def build_dce_kernel_examples(module):
   3.124 +    module.add_example(needed = ['core', 'network', 'dce'], 
   3.125 +                       target='bin/dce-linux-simple',
   3.126 +                       source=['example/dce-linux-simple.cc'])
   3.127  
   3.128 -    build_example(bld, ['core', 'internet', 'dce'], 
   3.129 -                  target='bin/dce-udp-simple',
   3.130 -                  source=['example/dce-udp-simple.cc'])
   3.131 -
   3.132 -    build_example(bld, ['core', 'internet', 'dce', 'point-to-point'], 
   3.133 -                  target='bin/dce-udp-perf',
   3.134 -                  source=['example/dce-udp-perf.cc'])
   3.135 -
   3.136 -
   3.137 -    if bld.env['KERNEL_STACK']:
   3.138 -        build_example(bld, ['core', 'network', 'dce'], 
   3.139 -                      target='bin/dce-linux-simple',
   3.140 -                      source=['example/dce-linux-simple.cc'])
   3.141 -
   3.142 -        build_example(bld, ['core', 'network', 'dce', 'wifi', 'point-to-point', 'csma', 'mobility'],
   3.143 -                      target='bin/dce-linux',
   3.144 -                      source=['example/dce-linux.cc'])
   3.145 +    module.add_example(needed = ['core', 'network', 'dce', 'wifi', 
   3.146 +                                 'point-to-point', 'csma', 'mobility'],
   3.147 +                       target='bin/dce-linux',
   3.148 +                       source=['example/dce-linux.cc'])
   3.149  
   3.150  
   3.151  def build(bld):
   3.152 @@ -272,24 +256,23 @@
   3.153                                    use=uselib,
   3.154                                    includes=kernel_includes,
   3.155                                    lib=['dl'])
   3.156 -    module_tests = [
   3.157 -        'test/dce-manager-test.cc',
   3.158 -        ]
   3.159 -    module.add_tests(source=module_tests, use = uselib)
   3.160 -    build_dce_tests(bld)
   3.161 -    build_dce_examples(bld)
   3.162 +    build_dce_tests(module)
   3.163 +    build_dce_examples(module)
   3.164 +
   3.165 +    if bld.env['KERNEL_STACK']:
   3.166 +        build_dce_kernel_examples(module)
   3.167  
   3.168      bld.add_group('dce_version_files')
   3.169  
   3.170      bld(source=['model/libc-ns3.version'],
   3.171 -            target='model/libc.version',
   3.172 -            rule='readversiondef ' + bld.env['LIBC_FILE'] + ' |' \
   3.173 -                'cat ${SRC[0].abspath()} - > ${TGT}')
   3.174 +        target='model/libc.version',
   3.175 +        rule='readversiondef ' + bld.env['LIBC_FILE'] + ' |' \
   3.176 +            'cat ${SRC[0].abspath()} - > ${TGT}')
   3.177  
   3.178      bld(source=['model/libpthread-ns3.version'],
   3.179 -            target='model/libpthread.version',
   3.180 -            rule='readversiondef ' + bld.env['LIBPTHREAD_FILE'] + ' |' \
   3.181 -                'cat ${SRC[0].abspath()} - > ${TGT}')
   3.182 +        target='model/libpthread.version',
   3.183 +        rule='readversiondef ' + bld.env['LIBPTHREAD_FILE'] + ' |' \
   3.184 +            'cat ${SRC[0].abspath()} - > ${TGT}')
   3.185  
   3.186      bld.add_group('dce_use_version_files')
   3.187