[C++-sig] pyste problem with AllFromHeader when -I is used
scott snyder
snyder at fnal.gov
Fri Oct 3 21:42:29 CEST 2003
hi -
I ran into an annoyance with the way AllFromHeader interacts with include
search paths. Specifically, if the header in question is found through
an include path specified with -I then the header may not be processed.
Here's an example:
$ mkdir include
$ cat > include/x.h
void foo();
$ cat > test.pyste
AllFromHeader ("x.h")
$ python $PYSTE_DIR/pyste.py --module=test -I`pwd`/include test.pyste
Module test generated
0.06 seconds
$ cat test.cpp
// Includes ====================================================================
#include <boost/python.hpp>
// Using =======================================================================
using namespace boost::python;
// Module ======================================================================
BOOST_PYTHON_MODULE(test)
{
}
$
Here, the x.h header was not processed.
The difficulty comes here, in HeaderExporter.py:
# check if this declaration is in the header
location = os.path.normpath(decl.location[0])
if location == header and not self.IsInternalName(decl.name):
For this example, it ends up comparing the two paths:
/work/shoreham-clued0/snyder/pystuff/test2/include/x.h x.h
i.e., comparing an absolute one to a relative one. So the comparison
fails, and the header doesn't get processed.
This is a problem in practice: the headers i'm reading are part of another
product. The absolute path to the headers depends on which version
i'm using and where they're installed on the particular system;
thus, i don't want to put the full path into the pyste file.
Below is the change i made to pyste to work around this.
It works for me, though it's kind of clunky and may match in some
cases where it actually shouldn't.
sss
Index: HeaderExporter.py
===================================================================
RCS file: /cvsroot/boost/boost/libs/python/pyste/src/Pyste/HeaderExporter.py,v
retrieving revision 1.4
diff -u -p -r1.4 HeaderExporter.py
--- HeaderExporter.py 9 Aug 2003 21:18:12 -0000 1.4
+++ HeaderExporter.py 30 Sep 2003 01:37:17 -0000
@@ -34,7 +34,12 @@ class HeaderExporter(Exporter):
for decl in self.declarations:
# check if this declaration is in the header
location = os.path.normpath(decl.location[0])
- if location == header and not self.IsInternalName(decl.name):
+ l = len (header)
+ if (location[-l:] == header and
+ (l == len (location) or
+ location[-l-1] == '/' or
+ location[-l-1] == '\\')
+ and not self.IsInternalName (decl.name)):
# ok, check the type of the declaration and export it accordingly
self.HandleDeclaration(decl, codeunit, exported_names)
More information about the Cplusplus-sig
mailing list