mirror of https://gitlab.com/ita1024/waf.git
cython cache for Issue 1167
This commit is contained in:
parent
f597fa65ab
commit
359518dc05
|
@ -0,0 +1,37 @@
|
||||||
|
#! /usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
# Thomas Nagy, 2012
|
||||||
|
|
||||||
|
"""
|
||||||
|
A simple cache layer to enable the redistribution of precompiled cython files
|
||||||
|
"""
|
||||||
|
|
||||||
|
from waflib.Task import ASK_LATER
|
||||||
|
from waflib.extras.cython import cython as cython_base
|
||||||
|
|
||||||
|
class cython(cython_base):
|
||||||
|
|
||||||
|
def runnable_status(self):
|
||||||
|
ret = cython_base.runnable_status(self)
|
||||||
|
if ret != ASK_LATER:
|
||||||
|
# we can create Node objects since we are in the main thread
|
||||||
|
bld = self.generator.bld
|
||||||
|
cache = bld.srcnode.make_node('cython_cache')
|
||||||
|
if self.env.CYTHON: # write to the cache directory
|
||||||
|
self.cython_cache_outputs = [cache.make_node(x.path_from(bld.bldnode)) for x in self.outputs]
|
||||||
|
else: # use the files in the cache directory
|
||||||
|
self.cython_cache_outputs = [cache.find_node(x.path_from(bld.bldnode)) for x in self.outputs]
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
if not self.env.CYTHON:
|
||||||
|
for (x, y) in zip(self.outputs, self.cython_cache_outputs):
|
||||||
|
x.write(y.read('rb'), 'wb')
|
||||||
|
else:
|
||||||
|
ret = cython_base.run(self)
|
||||||
|
if not ret:
|
||||||
|
for (x, y) in zip(self.outputs, self.cython_cache_outputs):
|
||||||
|
y.parent.mkdir()
|
||||||
|
y.write(x.read('rb'), 'wb')
|
||||||
|
return ret
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef __PYX_HAVE__cy_cxxtest
|
||||||
|
#define __PYX_HAVE__cy_cxxtest
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __PYX_HAVE_API__cy_cxxtest
|
||||||
|
|
||||||
|
#ifndef __PYX_EXTERN_C
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define __PYX_EXTERN_C extern "C"
|
||||||
|
#else
|
||||||
|
#define __PYX_EXTERN_C extern
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__PYX_EXTERN_C DL_IMPORT(void) cy_hello(void);
|
||||||
|
|
||||||
|
#endif /* !__PYX_HAVE_API__cy_cxxtest */
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
|
PyMODINIT_FUNC initcy_cxxtest(void);
|
||||||
|
#else
|
||||||
|
PyMODINIT_FUNC PyInit_cy_cxxtest(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* !__PYX_HAVE__cy_cxxtest */
|
|
@ -0,0 +1,97 @@
|
||||||
|
#ifndef __PYX_HAVE_API__cy_cxxtest
|
||||||
|
#define __PYX_HAVE_API__cy_cxxtest
|
||||||
|
#include "Python.h"
|
||||||
|
#include "cy_cxxtest.h"
|
||||||
|
|
||||||
|
static void (*__pyx_f_10cy_cxxtest_cy_hello)(void) = 0;
|
||||||
|
#define cy_hello __pyx_f_10cy_cxxtest_cy_hello
|
||||||
|
|
||||||
|
#ifndef __PYX_HAVE_RT_ImportModule
|
||||||
|
#define __PYX_HAVE_RT_ImportModule
|
||||||
|
static PyObject *__Pyx_ImportModule(const char *name) {
|
||||||
|
PyObject *py_name = 0;
|
||||||
|
PyObject *py_module = 0;
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
|
py_name = PyString_FromString(name);
|
||||||
|
#else
|
||||||
|
py_name = PyUnicode_FromString(name);
|
||||||
|
#endif
|
||||||
|
if (!py_name)
|
||||||
|
goto bad;
|
||||||
|
py_module = PyImport_Import(py_name);
|
||||||
|
Py_DECREF(py_name);
|
||||||
|
return py_module;
|
||||||
|
bad:
|
||||||
|
Py_XDECREF(py_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __PYX_HAVE_RT_ImportFunction
|
||||||
|
#define __PYX_HAVE_RT_ImportFunction
|
||||||
|
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
|
||||||
|
PyObject *d = 0;
|
||||||
|
PyObject *cobj = 0;
|
||||||
|
union {
|
||||||
|
void (*fp)(void);
|
||||||
|
void *p;
|
||||||
|
} tmp;
|
||||||
|
|
||||||
|
d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
|
||||||
|
if (!d)
|
||||||
|
goto bad;
|
||||||
|
cobj = PyDict_GetItemString(d, funcname);
|
||||||
|
if (!cobj) {
|
||||||
|
PyErr_Format(PyExc_ImportError,
|
||||||
|
"%s does not export expected C function %s",
|
||||||
|
PyModule_GetName(module), funcname);
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
|
||||||
|
if (!PyCapsule_IsValid(cobj, sig)) {
|
||||||
|
PyErr_Format(PyExc_TypeError,
|
||||||
|
"C function %s.%s has wrong signature (expected %s, got %s)",
|
||||||
|
PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
tmp.p = PyCapsule_GetPointer(cobj, sig);
|
||||||
|
#else
|
||||||
|
{const char *desc, *s1, *s2;
|
||||||
|
desc = (const char *)PyCObject_GetDesc(cobj);
|
||||||
|
if (!desc)
|
||||||
|
goto bad;
|
||||||
|
s1 = desc; s2 = sig;
|
||||||
|
while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
|
||||||
|
if (*s1 != *s2) {
|
||||||
|
PyErr_Format(PyExc_TypeError,
|
||||||
|
"C function %s.%s has wrong signature (expected %s, got %s)",
|
||||||
|
PyModule_GetName(module), funcname, sig, desc);
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
tmp.p = PyCObject_AsVoidPtr(cobj);}
|
||||||
|
#endif
|
||||||
|
*f = tmp.fp;
|
||||||
|
if (!(*f))
|
||||||
|
goto bad;
|
||||||
|
Py_DECREF(d);
|
||||||
|
return 0;
|
||||||
|
bad:
|
||||||
|
Py_XDECREF(d);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int import_cy_cxxtest(void) {
|
||||||
|
PyObject *module = 0;
|
||||||
|
module = __Pyx_ImportModule("cy_cxxtest");
|
||||||
|
if (!module) goto bad;
|
||||||
|
if (__Pyx_ImportFunction(module, "cy_hello", (void (**)(void))&__pyx_f_10cy_cxxtest_cy_hello, "void (void)") < 0) goto bad;
|
||||||
|
Py_DECREF(module); module = 0;
|
||||||
|
return 0;
|
||||||
|
bad:
|
||||||
|
Py_XDECREF(module);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* !__PYX_HAVE_API__cy_cxxtest */
|
|
@ -2,6 +2,8 @@
|
||||||
# encoding: ISO8859-1
|
# encoding: ISO8859-1
|
||||||
# Thomas Nagy, 2010
|
# Thomas Nagy, 2010
|
||||||
|
|
||||||
|
from waflib import Logs
|
||||||
|
|
||||||
top = '.'
|
top = '.'
|
||||||
out = 'build'
|
out = 'build'
|
||||||
|
|
||||||
|
@ -10,13 +12,17 @@ def options(ctx):
|
||||||
ctx.load('compiler_cxx')
|
ctx.load('compiler_cxx')
|
||||||
ctx.load('python')
|
ctx.load('python')
|
||||||
ctx.load('cython')
|
ctx.load('cython')
|
||||||
|
ctx.load('cython_cache', tooldir='.')
|
||||||
|
|
||||||
def configure(ctx):
|
def configure(ctx):
|
||||||
ctx.load('compiler_c')
|
ctx.load('compiler_c')
|
||||||
ctx.load('compiler_cxx')
|
ctx.load('compiler_cxx')
|
||||||
ctx.load('python')
|
ctx.load('python')
|
||||||
ctx.check_python_headers()
|
ctx.check_python_headers()
|
||||||
ctx.load('cython')
|
try:
|
||||||
|
ctx.load('cython')
|
||||||
|
except ctx.errors.ConfigurationError:
|
||||||
|
Logs.warn('Cython was not found, using the cache')
|
||||||
|
|
||||||
def build(ctx):
|
def build(ctx):
|
||||||
# a C library
|
# a C library
|
||||||
|
|
Loading…
Reference in New Issue