lucene-pylucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From va...@apache.org
Subject svn commit: r944934 - in /lucene/pylucene/branches/branch_3x/jcc: CHANGES jcc/cpp.py jcc/python.py jcc/sources/jcc.cpp
Date Sun, 16 May 2010 22:53:30 GMT
Author: vajda
Date: Sun May 16 22:53:30 2010
New Revision: 944934

URL: http://svn.apache.org/viewvc?rev=944934&view=rev
Log:
   - added support for --import

Modified:
    lucene/pylucene/branches/branch_3x/jcc/CHANGES
    lucene/pylucene/branches/branch_3x/jcc/jcc/cpp.py
    lucene/pylucene/branches/branch_3x/jcc/jcc/python.py
    lucene/pylucene/branches/branch_3x/jcc/jcc/sources/jcc.cpp

Modified: lucene/pylucene/branches/branch_3x/jcc/CHANGES
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/CHANGES?rev=944934&r1=944933&r2=944934&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/CHANGES (original)
+++ lucene/pylucene/branches/branch_3x/jcc/CHANGES Sun May 16 22:53:30 2010
@@ -17,6 +17,7 @@ Version 2.5 ->
  - added 'asm' to list of reserved words
  - added JCC_VERSION string to modules using JCC
  - added support for --resources
+ - added support for --import
  - 
 
 Version 2.4 -> 2.5

Modified: lucene/pylucene/branches/branch_3x/jcc/jcc/cpp.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/jcc/cpp.py?rev=944934&r1=944933&r2=944934&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/jcc/cpp.py (original)
+++ lucene/pylucene/branches/branch_3x/jcc/jcc/cpp.py Sun May 16 22:53:30 2010
@@ -318,6 +318,7 @@ def jcc(args):
     generics = hasattr(_jcc, "Type")
     arch = []
     resources = []
+    imports = {}
 
     i = 1
     while i < len(args):
@@ -425,6 +426,9 @@ def jcc(args):
             elif arg == '--resources':
                 i += 1
                 resources.append(args[i])
+            elif arg == '--import':
+                i += 1
+                imports[args[i]] = ()
             else:
                 raise ValueError, "Invalid argument: %s" %(arg)
         else:
@@ -440,6 +444,12 @@ def jcc(args):
     typeset = set()
     excludes = set(excludes)
 
+    if imports:
+        if shared:
+            imports = dict((__import__(import_), set()) for import_ in imports)
+        else:
+            raise ValueError, "--shared must be used when using --import"
+
     if recompile or not build and (install or dist):
         if moduleName is None:
             raise ValueError, 'module name not specified (use --python)'
@@ -448,8 +458,23 @@ def jcc(args):
                     install, dist, debug, jars, version,
                     prefix, root, install_dir, home_dir, use_distutils,
                     shared, compiler, modules, wininst, find_jvm_dll,
-                    arch, generics, resources)
+                    arch, generics, resources, imports)
     else:
+        if imports:
+            def walk((include, importset), dirname, names):
+                for name in names:
+                    if name.endswith('.h'):
+                        className = os.path.join(dirname[len(include) + 1:],
+                                                 name[:-2])
+                        if os.path.sep != '/':
+                            className = className.replace(os.path.sep, '/')
+                        importset.add(findClass(className))
+            for import_, importset in imports.iteritems():
+                env._addClassPath(import_.CLASSPATH)
+                include = os.path.join(import_.__dir__, 'include')
+                os.path.walk(include, walk, (include, importset))
+                typeset.update(importset)
+
         for className in classNames:
             if className in excludes:
                 continue
@@ -501,6 +526,9 @@ def jcc(args):
                 out_cpp = file(os.path.join(cppdir, fileName), 'w')
 
         done = set()
+        for importset in imports.itervalues():
+            done.update(importset)
+
         todo = typeset - done
 	if allInOne and wrapperFiles > 1:
             classesPerFile = max(1, len(todo) / wrapperFiles)
@@ -562,14 +590,15 @@ def jcc(args):
 
         if moduleName:
             out = file(os.path.join(cppdir, moduleName) + '.cpp', 'w')
-            module(out, allInOne, done, cppdir, moduleName, shared, generics)
+            module(out, allInOne, done, imports, cppdir, moduleName,
+                   shared, generics)
             out.close()
             if build or install or dist:
                 compile(env, os.path.dirname(args[0]), output, moduleName,
                         install, dist, debug, jars, version,
                         prefix, root, install_dir, home_dir, use_distutils,
                         shared, compiler, modules, wininst, find_jvm_dll,
-                        arch, generics, resources)
+                        arch, generics, resources, imports)
 
 
 def header(env, out, cls, typeset, packages, excludes, generics):

Modified: lucene/pylucene/branches/branch_3x/jcc/jcc/python.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/jcc/python.py?rev=944934&r1=944933&r2=944934&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/jcc/python.py (original)
+++ lucene/pylucene/branches/branch_3x/jcc/jcc/python.py Sun May 16 22:53:30 2010
@@ -1462,7 +1462,8 @@ def package(out, allInOne, cppdir, names
         package(out, allInOne, cppdir, entries, names + (name,))
 
 
-def module(out, allInOne, classes, cppdir, moduleName, shared, generics):
+def module(out, allInOne, classes, imports, cppdir, moduleName,
+           shared, generics):
 
     extname = '_%s' %(moduleName)
     line(out, 0, '#include <Python.h>')
@@ -1473,11 +1474,15 @@ def module(out, allInOne, classes, cppdi
         out_init = file(os.path.join(cppdir, '__init__.cpp'), 'w')
     namespaces = {}
     for cls in classes:
-        namespace = namespaces
-        classNames = cls.getName().split('.')
-        for className in classNames[:-1]:
-            namespace = namespace.setdefault(className, {})
-        namespace[classNames[-1]] = True
+        for importset in imports.itervalues():
+            if cls in importset:
+                break
+        else:
+            namespace = namespaces
+            classNames = cls.getName().split('.')
+            for className in classNames[:-1]:
+                namespace = namespace.setdefault(className, {})
+            namespace[classNames[-1]] = True
     if allInOne:
         package(out_init, True, cppdir, namespaces, ())
         out_init.close()
@@ -1513,7 +1518,7 @@ def module(out, allInOne, classes, cppdi
 def compile(env, jccPath, output, moduleName, install, dist, debug, jars,
             version, prefix, root, install_dir, home_dir, use_distutils,
             shared, compiler, modules, wininst, find_jvm_dll, arch, generics,
-            resources):
+            resources, imports):
 
     try:
         if use_distutils:
@@ -1611,8 +1616,8 @@ def compile(env, jccPath, output, module
     line(out, 1, 'def getJavaException(self):')
     line(out, 2, 'return self.args[0]')
     line(out, 1, 'def __str__(self):')
-    line(out, 2, 'writer = %s.StringWriter()', extname)
-    line(out, 2, 'self.getJavaException().printStackTrace(%s.PrintWriter(writer))', extname)
+    line(out, 2, 'writer = StringWriter()')
+    line(out, 2, 'self.getJavaException().printStackTrace(PrintWriter(writer))')
     line(out, 2, 'return "\\n".join((super(JavaError, self).__str__(), "    Java stacktrace:",
str(writer)))')
     line(out)
     line(out, 0, 'class InvalidArgsError(Exception):')
@@ -1632,11 +1637,15 @@ def compile(env, jccPath, output, module
          extname, extname, extname)
 
     line(out)
+    for import_ in imports:
+        line(out, 0, 'from %s._%s import *', import_.__name__, import_.__name__)
     line(out, 0, 'from %s import *', extname)
     out.close()
 
     includes = [os.path.join(output, extname),
                 os.path.join(jccPath, 'sources')]
+    for import_ in imports:
+        includes.append(os.path.join(import_.__dir__, 'include'))
 
     sources = ['JObject.cpp', 'JArray.cpp', 'functions.cpp', 'types.cpp']
     if not shared:
@@ -1646,6 +1655,25 @@ def compile(env, jccPath, output, module
 	shutil.copy2(os.path.join(jccPath, 'sources', source),
                      os.path.join(output, extname))
 
+    if shared:
+        def copytree(src, dst):
+            _dst = os.path.join(modulePath, dst)
+            if not os.path.exists(_dst):
+                os.mkdir(_dst)
+            for name in os.listdir(src):
+                if name.startswith('.'):
+                    continue
+                _src = os.path.join(src, name)
+                if os.path.islink(_src):
+                    continue
+                _dst = os.path.join(dst, name)
+                if os.path.isdir(_src):
+                    copytree(_src, _dst)
+                elif name.endswith('.h'):
+                    shutil.copy2(_src, os.path.join(modulePath, _dst))
+                    package_data.append(_dst)
+        copytree(os.path.join(output, extname), 'include')
+
     sources = []
     for path, dirs, names in os.walk(os.path.join(output, extname)):
         for name in names:

Modified: lucene/pylucene/branches/branch_3x/jcc/jcc/sources/jcc.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/jcc/jcc/sources/jcc.cpp?rev=944934&r1=944933&r2=944934&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/jcc/jcc/sources/jcc.cpp (original)
+++ lucene/pylucene/branches/branch_3x/jcc/jcc/sources/jcc.cpp Sun May 16 22:53:30 2010
@@ -45,6 +45,8 @@ static PyObject *t_jccenv_isCurrentThrea
 static PyObject *t_jccenv_strhash(PyObject *self, PyObject *arg);
 static PyObject *t_jccenv__dumpRefs(PyObject *self,
                                     PyObject *args, PyObject *kwds);
+static PyObject *t_jccenv__addClassPath(PyObject *self, PyObject *args);
+
 static PyObject *t_jccenv__get_jni_version(PyObject *self, void *data);
 static PyObject *t_jccenv__get_java_version(PyObject *self, void *data);
 
@@ -69,6 +71,8 @@ static PyMethodDef t_jccenv_methods[] = 
       METH_O, NULL },
     { "_dumpRefs", (PyCFunction) t_jccenv__dumpRefs,
       METH_VARARGS | METH_KEYWORDS, NULL },
+    { "_addClassPath", (PyCFunction) t_jccenv__addClassPath,
+      METH_VARARGS, NULL },
     { NULL, NULL, 0, NULL }
 };
 
@@ -267,6 +271,17 @@ static PyObject *t_jccenv__dumpRefs(PyOb
     return result;
 }
 
+static PyObject *t_jccenv__addClassPath(PyObject *self, PyObject *args)
+{
+    const char *classpath;
+
+    if (!PyArg_ParseTuple(args, "s", &classpath))
+        return NULL;
+
+    env->setClassPath(classpath);
+
+    Py_RETURN_NONE;
+}
 
 static PyObject *t_jccenv__get_jni_version(PyObject *self, void *data)
 {



Mime
View raw message