refactor the build system to avoid generating .py[co] files in the source tree (which WAF doesn't like)

This commit is contained in:
Gustavo J. A. M. Carneiro
2007-06-02 15:02:23 +01:00
parent c501e5ba9b
commit 67843fa924
6 changed files with 49 additions and 74 deletions
+36
View File
@@ -0,0 +1,36 @@
#! /usr/bin/env python
import sys
from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink)
from pybindgen import (CppMethod, CppConstructor, CppClass)
def my_module_gen(out_file):
print >> out_file, "#include <Python.h>"
print >> out_file, "#include \"foo.h\""
mod = Module('foo')
mod.add_function(Function(ReturnValue('int'), 'print_something',
[Parameter('const char*', 'message')]))
mod.add_function(Function(ReturnValue('int'), 'print_something_else',
[Parameter('const char*', 'message2')]))
SomeObject = CppClass('SomeObject')
SomeObject.add_method(CppMethod(ReturnValue('int'), 'add_prefix',
[Parameter('std::string&', 'message',
direction=Parameter.DIRECTION_INOUT)]))
SomeObject.add_constructor(
CppConstructor([Parameter('std::string', 'prefix')]))
mod.add_class(SomeObject)
mod.generate(FileCodeSink(out_file))
if __name__ == '__main__':
my_module_gen(sys.stdout)
+5 -65
View File
@@ -4,73 +4,13 @@ import Object
import Params
import Task
import os, sys
sys.path.insert(0, os.getcwd()) # to work with uninstalled pybindgen
from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink)
from pybindgen import (CppMethod, CppConstructor, CppClass)
def _pybindgen_action(task):
target, = task.m_outputs
out_file = file(target.bldpath(task.m_env), "w")
task.function(out_file)
out_file.close()
class PyBindGen(Object.genobj):
def __init__(self, env=None):
Object.genobj.__init__(self, 'other')
self.install_var = 0
self.env = env
if not self.env:
self.env = Params.g_build.m_allenvs['default'].copy()
self.function = None
self.target = None
self.prio = 5
def apply(self):
function = self.function
task = self.create_task('pybindgen', self.env, self.prio)
task.function = self.function
target = self.path.find_build(self.target)
task.set_outputs([target])
task.set_inputs([self.path.find_source('wscript')])
def install(self):
pass
def my_module_gen(out_file):
print >> out_file, "#include <Python.h>"
print >> out_file, "#include \"foo.h\""
mod = Module('foo')
mod.add_function(Function(ReturnValue('int'), 'print_something',
[Parameter('const char*', 'message')]))
mod.add_function(Function(ReturnValue('int'), 'print_something_else',
[Parameter('const char*', 'message2')]))
SomeObject = CppClass('SomeObject')
SomeObject.add_method(CppMethod(ReturnValue('int'), 'add_prefix',
[Parameter('std::string&', 'message')]))
SomeObject.add_constructor(
CppConstructor([Parameter('std::string', 'prefix')]))
mod.add_class(SomeObject)
mod.generate(FileCodeSink(out_file))
def build(bld):
Object.register('pybindgen', PyBindGen)
Action.Action('pybindgen', func=_pybindgen_action, color='BLUE')
bindgen = bld.create_obj('pybindgen')
bindgen.target = 'foomodule.cc'
bindgen.function = my_module_gen
bindgen.prio = 1
bindgen = bld.create_obj('command-output')
bindgen.stdout = 'foomodule.cc'
bindgen.stdin = 'foomodulegen.py'
bindgen.command = 'foomodulegen.py'
bindgen.prio = 3 # must run after the 'py' objects in ../pybindgen
obj = bld.create_obj('cpp', 'shlib', 'pyext')
obj.source = [
+2
View File
@@ -7,8 +7,10 @@ def build(bld):
# commented, triggers a WAF bug (Issue #40)
#obj.source.append('version.py')
obj.inst_dir = 'pybindgen'
obj.prio = 2
obj = bld.create_obj('py')
obj.find_sources_in_dirs('typehandlers')
obj.inst_dir = 'pybindgen/typehandlers'
obj.prio = 2
-5
View File
@@ -2,11 +2,6 @@
import sys
try:
path = sys.argv[1]
except IndexError:
path = '..'
sys.path.insert(0, path)
from pybindgen import typehandlers
from pybindgen.typehandlers import codesink
+2 -4
View File
@@ -13,18 +13,16 @@ def build(bld):
gen.stdin = 'test-generation.py'
top_srcdir = bld.m_srcnode.abspath()
gen.argv = [top_srcdir]
gen.priority = 5
gen.prio = 5
obj = bld.create_obj('cpp', 'objects', 'pyext')
obj.source = 'test.cc'
obj.env.append_value('CXXFLAGS', ['-Wall', '-Werror', '-Wno-unused'])
cwd = os.getcwd()
env = dict(os.environ)
env['PYTHONPATH'] = top_srcdir
os.chdir(top_srcdir)
try:
if subprocess.Popen(['python', 'tests/test.py'], env=env).wait():
if subprocess.Popen(['python', 'tests/test.py']).wait():
raise SystemExit(1)
finally:
os.chdir(cwd)
+4
View File
@@ -8,6 +8,10 @@ import os
import pproc as subprocess
import shutil
os.environ['PYTHONPATH'] = os.path.join(os.getcwd(), 'build', 'default')
def get_version_from_bzr():
import bzrlib.tag, bzrlib.branch
branch = bzrlib.branch.Branch.open('file://' + os.getcwd())