Subject: [Instant-dev] Patch with include_dirs

From: Johan Hake <[email-masked]>
Date: Tue, 13 Jan 2009 11:47:10 +0100

Here comes the announced patch.

Johan
# HG changeset patch
# User "Johan Hake <[email-masked]>"
# Date 1231842658 -3600
# Node ID f0f7afb90573f9043de73f064503ad13473235ec
# Parent  da24a909c44d76d1011628e410947f31641b230b
Added swig_include_dirs to the arguments in build_module()

diff -r da24a909c44d -r f0f7afb90573 src/instant/build.py
--- a/src/instant/build.py	Mon Nov 17 11:38:00 2008 +0100
+++ b/src/instant/build.py	Tue Jan 13 11:30:58 2009 +0100
@@ -152,6 +152,7 @@
                  local_headers=[], system_headers=[],
                  include_dirs=['.'], library_dirs=[], libraries=[],
                  swigargs=['-c++', '-fcompact', '-O', '-I.', '-small'],
+                 swig_include_dirs = [],
                  cppargs=['-O2'], lddargs=[],
                  object_files=[], arrays=[],
                  generate_interface=True, generate_setup=True,
@@ -194,6 +195,8 @@
       - B{swigargs}:
         - List of arguments to swig, e.g. C{["-lpointers.i"]}
           to include the SWIG pointers.i library.
+      - B{swig_include_dirs}:
+        - A list of directories to include in the 'swig' command.
       - B{cppargs}:
         - List of arguments to the compiler, e.g. C{["-D", "-U"]}.
       - B{lddargs}:
@@ -229,18 +232,19 @@
     assert_is_str(init_code)
     assert_is_str(additional_definitions)
     assert_is_str(additional_declarations)
-    sources        = strip_strings(sources)
-    wrap_headers   = strip_strings(wrap_headers)
-    local_headers  = strip_strings(local_headers)
-    system_headers = strip_strings(system_headers)
-    include_dirs   = strip_strings(include_dirs)
-    library_dirs   = strip_strings(library_dirs)
-    libraries      = strip_strings(libraries)
-    swigargs       = arg_strings(swigargs)
-    cppargs        = arg_strings(cppargs)
-    lddargs        = arg_strings(lddargs)
-    object_files   = strip_strings(object_files)
-    arrays         = [strip_strings(a) for a in arrays]
+    sources           = strip_strings(sources)
+    wrap_headers      = strip_strings(wrap_headers)
+    local_headers     = strip_strings(local_headers)
+    system_headers    = strip_strings(system_headers)
+    include_dirs      = strip_strings(include_dirs)
+    library_dirs      = strip_strings(library_dirs)
+    libraries         = strip_strings(libraries)
+    swigargs          = arg_strings(swigargs)
+    swig_include_dirs = strip_strings(swig_include_dirs)
+    cppargs           = arg_strings(cppargs)
+    lddargs           = arg_strings(lddargs)
+    object_files      = strip_strings(object_files)
+    arrays            = [strip_strings(a) for a in arrays]
     assert_is_bool(generate_interface)
     assert_is_bool(generate_setup)
     instant_assert(   signature is None \
@@ -280,6 +284,7 @@
     instant_debug('    library_dirs: %r' % library_dirs)
     instant_debug('    libraries: %r' % libraries)
     instant_debug('    swigargs: %r' % swigargs)
+    instant_debug('    swig_include_dirs: %r' % swig_include_dirs)
     instant_debug('    cppargs: %r' % cppargs)
     instant_debug('    lddargs: %r' % lddargs)
     instant_debug('    object_files: %r' % object_files)
@@ -313,7 +318,7 @@
                 #local_headers,
                 system_headers,
                 include_dirs, library_dirs, libraries,
-                swigargs, cppargs, lddargs,
+                swig_include_dirs, swigargs, cppargs, lddargs,
                 object_files, arrays,
                 generate_interface, generate_setup,
                 # The signature isn't defined, and the cache_dir doesn't affect the module:
@@ -381,8 +386,9 @@
         # Generate setup.py if wanted
         setup_name = "setup.py"
         if generate_setup:
-            write_setup(setup_name, modulename, csrcs, cppsrcs, local_headers,
-                include_dirs, library_dirs, libraries, swigargs, cppargs, lddargs)
+            write_setup(setup_name, modulename, csrcs, cppsrcs, local_headers, \
+                        include_dirs, library_dirs, libraries, swig_include_dirs, \
+                        swigargs, cppargs, lddargs)
         
         # --- Build module
         
@@ -408,7 +414,7 @@
                          #local_headers,
                          system_headers,
                          include_dirs, library_dirs, libraries,
-                         swigargs, cppargs, lddargs,
+                         swigargs, swig_include_dirs, cppargs, lddargs,
                          object_files, #arrays,
                          #generate_interface, generate_setup,
                          # The signature isn't defined, and the
diff -r da24a909c44d -r f0f7afb90573 src/instant/codegeneration.py
--- a/src/instant/codegeneration.py	Mon Nov 17 11:38:00 2008 +0100
+++ b/src/instant/codegeneration.py	Tue Jan 13 11:30:58 2009 +0100
@@ -141,7 +141,7 @@
     instant_debug("Done generating interface file.")

-def write_setup(filename, modulename, csrcs, cppsrcs, local_headers, include_dirs, library_dirs, libraries, swigargs, cppargs, lddargs):
+def write_setup(filename, modulename, csrcs, cppsrcs, local_headers, include_dirs, library_dirs, libraries, swig_include_dirs, swigargs, cppargs, lddargs):
     """Generate a setup.py file. Intended for internal library use."""
     instant_debug("Generating %s." % filename)
     #instant_warning("FIXME: Not using csrcs in write_setupfile().")
@@ -155,7 +155,7 @@
     swig_args = ""
     if swigargs:
         swig_args = " ".join(swigargs)
-    
+
     compile_args = ""
     if cppargs:  
         compile_args = ", extra_compile_args=%r" % cppargs 
@@ -164,9 +164,9 @@
     if lddargs:  
         link_args = ", extra_link_args=%r" % lddargs 
 
-    inc_dir = ""
+    swig_include_dirs = " ".join("-I%s"%d for d in swig_include_dirs)
     if len(local_headers) > 0:
-        inc_dir = "-I.."
+        swig_include_dirs += " -I.."
     
     # Generate code
     code = reindent("""
@@ -182,7 +182,7 @@
                              include_dirs=%s,
                              library_dirs=%s,
                              libraries=%s %s %s)])  
-        """ % (modulename, inc_dir, swig_args, swigfilename, cppsrcs, 
+        """ % (modulename, swig_include_dirs, swig_args, swigfilename, cppsrcs, 
                modulename, modulename, include_dirs, library_dirs, libraries, compile_args, link_args))
     
     write_file(filename, code)