wscript 4.34 KB
Newer Older
nextime's avatar
nextime committed
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
## -*- python -*-
#import Action
#import Object
#import Params
import Task

import sys
import os.path
import os
import pproc as subprocess

# uncomment to enable profiling information
# epydoc uses the profile data to generate call graphs
#os.environ["PYBINDGEN_ENABLE_PROFILING"] = ""


if 0:
    DEPRECATION_ERRORS = '-Werror::DeprecationWarning' # deprecations become errors
else:
    DEPRECATION_ERRORS = '-Wdefault::DeprecationWarning' # normal python behaviour


def build(bld):
    env = bld.env

    env['TOP_SRCDIR'] = bld.srcnode.abspath()

    gen = bld.new_task_gen(
        features='command',
        source='test-generation.py',
        target='test.cc',
        command='${PYTHON} ${SRC[0]} ${TOP_SRCDIR} > ${TGT[0]}')

    if env['CXX']:
        obj = bld.new_task_gen(features='cxx pyext')
        obj.source = 'test.cc'
        if env['CXX_NAME'] == 'gcc':
            obj.env.append_value('CXXFLAGS', ['-Werror', '-Wno-unused'])
    
    ## manual code generation using simple pybindgen API calls
    bindgen = bld.new_task_gen(
        features='command',
        source='foomodulegen.py',
        target='foomodule.cc',
        command='${PYTHON} %s ${SRC[0]} ${TOP_SRCDIR} > ${TGT[0]}' % (DEPRECATION_ERRORS,))

    if env['CXX']:
        obj = bld.new_task_gen(features='cxx cshlib pyext')
        obj.source = [
            'foo.cc',
            'foomodule.cc'
            ]
        obj.target = 'foo'
        obj.install_path = None
        obj.includes = '.'

    ## automatic code scanning using gccxml
    if env['ENABLE_PYGCCXML']:
        ### Same thing, but using gccxml autoscanning

        bld.new_task_gen(
            features='command',
            source='foomodulegen-auto.py foo.h',
            target='foomodule2.cc foomodulegen_generated.py',
            command='${PYTHON} %s ${SRC[0]} ${SRC[1]} ${cpp_path_repr} ${TGT[1]} > ${TGT[0]}' % (DEPRECATION_ERRORS,),
            variables=dict(cpp_path_repr=repr(bindgen.env['CPPPATH']+bindgen.env['CPPPATH_PYEXT'])))

        obj = bld.new_task_gen(features='cxx cshlib pyext')
        obj.source = [
            'foo.cc',
            'foomodule2.cc'
            ]
        obj.target = 'foo2'
        obj.install_path = None
        obj.includes = '.'

        ### Now using the generated python script

        bld.new_task_gen(
            features='command',
            source='foomodulegen3.py foomodulegen_generated.py',
            target='foomodule3.cc',
            command='${PYTHON} %s ${SRC[0]} ${TGT[0]} > ${TGT[0]}' % (DEPRECATION_ERRORS,))

        ## yes, this global manipulation of PYTHONPATH is kind of evil :-/
        ## TODO: add WAF command-output support for customising command OS environment
        os.environ["PYTHONPATH"] = os.pathsep.join([os.environ.get("PYTHONPATH", ''), bindgen.path.abspath(bindgen.env)])

        obj = bld.new_task_gen(features='cxx cshlib pyext')
        obj.source = [
            'foo.cc',
            'foomodule3.cc'
            ]
        obj.target = 'foo3'
        obj.install_path = None # do not install
        obj.includes = '.'

        ## ---

        bld.new_task_gen(
            features='command',
            source='foomodulegen-auto-split.py foo.h',
            target='foomodulegen_split.py foomodulegen_module1.py foomodulegen_module2.py',
            command='${PYTHON} %s ${SRC[0]} ${SRC[1]} ${cpp_path_repr} ${TGT[0]} ${TGT[1]} ${TGT[2]}' % (DEPRECATION_ERRORS,),
            variables=dict(cpp_path_repr=repr(bindgen.env['CPPPATH']+bindgen.env['CPPPATH_PYEXT'])))

        bld.new_task_gen(
            features='command',
            source=[
                'foomodulegen4.py',
                'foomodulegen_split.py',
                'foomodulegen_module1.py',
                'foomodulegen_module2.py',
                ],
            target=[
                'foomodule4.cc',
                'foomodule4.h',
                'foomodulegen_module1.cc',
                'foomodulegen_module2.cc',
                ],
            command='${PYTHON} %s ${SRC[0]} ${TGT[0]}' % (DEPRECATION_ERRORS,))


        obj = bld.new_task_gen(features='cxx cshlib pyext')
        obj.source = [
            'foo.cc',
            'foomodule4.cc',
            'foomodulegen_module1.cc',
            'foomodulegen_module2.cc',
            ]
        obj.target = 'foo4'
        obj.install_path = None # do not install
        obj.includes = '.'

    ## pure C tests
    bld.add_subdirs('c-hello')