Skip to content

Commit

Permalink
Relative paths to typemaps work from arbitrary locations now. As long…
Browse files Browse the repository at this point in the history
… as the classpath is correct.
  • Loading branch information
Jim Carroll committed Oct 31, 2012
1 parent 576318a commit 6c614ba
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
8 changes: 4 additions & 4 deletions tools/codegenerator/Generator.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 34 additions & 4 deletions tools/codegenerator/Helper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion xbmc/interfaces/python/PythonSwig.cpp.template
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6c614ba

Please sign in to comment.