Relative paths to typemaps work from arbitrary locations now. As long as the classpat...
authorJim Carroll <thecarrolls@jiminger.com>
Wed, 31 Oct 2012 19:17:57 +0000 (15:17 -0400)
committerJim Carroll <thecarrolls@jiminger.com>
Wed, 31 Oct 2012 19:19:04 +0000 (15:19 -0400)
tools/codegenerator/Generator.groovy
tools/codegenerator/Helper.groovy
xbmc/interfaces/python/PythonSwig.cpp.template

index c7dc88a..057e814 100644 (file)
@@ -55,14 +55,14 @@ if (newargs.size() > 3)
 File moduleSpec = new File(newargs[0])
 assert moduleSpec.exists() && moduleSpec.isFile(), 'Cannot locate the spec file "' + moduleSpec.getCanonicalPath() + '."'
 
-spec = [ 'module' : Helper.transformSwigXml(new XmlParser().parse(moduleSpec)) ]
+File templateFile = new File(newargs[1])
+assert templateFile.exists() && templateFile.isFile(), 'Cannot locate the template file "' + templateFile.getCanonicalPath() + '."'
+
+spec = [ 'module' : Helper.transformSwigXml(new XmlParser().parse(moduleSpec)), 'templateFile' : templateFile ]
 
 if (verbose)
    println XmlUtil.serialize(spec['module'])
 
-File templateFile = new File(newargs[1])
-assert templateFile.exists() && templateFile.isFile(), 'Cannot locate the template file "' + templateFile.getCanonicalPath() + '."'
-
 te = new SimpleTemplateEngine()
 println 'Processing "' + templateFile + '" using the module specification for module "' + moduleSpec + '"'
 if (verbose) te.setVerbose(true)
index 737eeee..1a9c96e 100644 (file)
@@ -42,6 +42,9 @@ public class Helper
    private static def defaultInTypeConversion = null
    private static def doxygenXmlDir = null
    public static String newline = System.getProperty("line.separator");
+   public static File curTemplateFile = null;
+
+   public static void setTempateFile(File templateFile) { curTemplateFile = templateFile }
 
    /**
     * In order to use any of the typemap helper features, the Helper class needs to be initialized with
@@ -52,15 +55,16 @@ public class Helper
     * @param pinTypemap is the typemap table for input parameters from the scripting language
     * @param defaultInTypemap is the default typemap for the input parameters from the scripting language
     */
-   public static void setup(List pclasses, Map poutTypemap, def defaultOutTypemap,
-   Map pinTypemap, def defaultInTypemap)
-   {
+    public static void setup(def template,List pclasses, Map poutTypemap, def defaultOutTypemap,
+                             Map pinTypemap, def defaultInTypemap)
+    {
+      setTempateFile(template.binding.templateFile)
       classes = pclasses ? pclasses : []
       if (poutTypemap) outTypemap.putAll(poutTypemap)
       if (defaultOutTypemap) defaultOutTypeConversion = defaultOutTypemap
       if (pinTypemap) inTypemap.putAll(pinTypemap)
       if (defaultInTypemap) defaultInTypeConversion = defaultInTypemap
-   }
+    }
 
    public static class Sequence
    {
@@ -242,6 +246,19 @@ public class Helper
         convertTemplate = convertTemplate[0]
       }
 
+      if (File.class.isAssignableFrom(convertTemplate.getClass()))
+      {
+        File cur = (File)convertTemplate
+        if (!cur.exists()) // see if the file is relative to the template file
+        { 
+          File parent = curTemplateFile.getParentFile()
+          // find the relative path to the convertTemplate
+          File cwd = new File('.').getCanonicalFile()
+          String relative = cwd.toURI().relativize(convertTemplate.toURI()).getPath();
+          convertTemplate = new File(parent,relative)
+        }
+      }
+
       if (seqSetHere) curSequence.set(null)
       return new SimpleTemplateEngine().createTemplate(convertTemplate).make(bindings).toString()
    }
@@ -348,6 +365,19 @@ public class Helper
             convertTemplate = convertTemplate[0]
          }
 
+         if (File.class.isAssignableFrom(convertTemplate.getClass()))
+         {
+           File cur = (File)convertTemplate
+           if (!cur.exists()) // see if the file is relative to the template file
+           { 
+             File parent = curTemplateFile.getParentFile()
+             // find the relative path to the convertTemplate
+             File cwd = new File('.').getCanonicalFile()
+             String relative = cwd.toURI().relativize(convertTemplate.toURI()).getPath();
+             convertTemplate = new File(parent,relative)
+           }
+         }
+
          if (seqSetHere) curSequence.set(null);
          return new SimpleTemplateEngine().createTemplate(convertTemplate).make(bindings).toString()
       }
index e73eba1..ecdd2de 100644 (file)
@@ -41,7 +41,7 @@ module.findAll( { it.name() == 'typetab' } ).each {  SwigTypeParser.appendTypeTa
 methods = module.depthFirst().findAll { it.name() == 'function' || it.name() == 'constructor' || it.name() == 'destructor' }
 classes = module.depthFirst().findAll { it.name() == 'class' }
 
-Helper.setup(classes,
+Helper.setup(this,classes,
     /**
      * This is meant to contain mini-templates for converting the return type
      * of the native call to be returned to the python caller.