diff options
author | Jim Carroll <thecarrolls@jiminger.com> | 2012-10-31 15:17:57 -0400 |
---|---|---|
committer | Jim Carroll <thecarrolls@jiminger.com> | 2012-10-31 15:19:04 -0400 |
commit | 6c614ba702ffd8682b753cf223da3c41b3b574d3 (patch) | |
tree | 6976dce31b182333ce7638641c0739cf38550127 /tools | |
parent | 576318a33c9c5c31ff9213536eb98a4d956b08c7 (diff) |
Relative paths to typemaps work from arbitrary locations now. As long as the classpath is correct.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/codegenerator/Generator.groovy | 8 | ||||
-rw-r--r-- | tools/codegenerator/Helper.groovy | 38 |
2 files changed, 38 insertions, 8 deletions
diff --git a/tools/codegenerator/Generator.groovy b/tools/codegenerator/Generator.groovy index c7dc88a642..057e81414b 100644 --- a/tools/codegenerator/Generator.groovy +++ b/tools/codegenerator/Generator.groovy @@ -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) diff --git a/tools/codegenerator/Helper.groovy b/tools/codegenerator/Helper.groovy index 737eeee597..1a9c96ea1a 100644 --- a/tools/codegenerator/Helper.groovy +++ b/tools/codegenerator/Helper.groovy @@ -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() } |