Add an output directory option to genvk.py.
authorJamie Madill <jmadill@chromium.org>
Wed, 4 May 2016 15:17:33 +0000 (08:17 -0700)
committerDustin Graves <dustin@lunarg.com>
Thu, 5 May 2016 17:30:31 +0000 (11:30 -0600)
Currently for the threading utils and parameter checker generator,
the script is hard-coded to write to the current directory. Add
an option to add a custom output directory.

Change-Id: Id1b72a934ead74d2f6c01ad4e581af83067d3f49

generator.py
genvk.py

index 16d5243..d44bc62 100644 (file)
@@ -322,7 +322,8 @@ class ThreadGeneratorOptions(GeneratorOptions):
                  apientryp = '',
                  indentFuncProto = True,
                  indentFuncPointer = False,
-                 alignFuncParam = 0):
+                 alignFuncParam = 0,
+                 genDirectory = None):
         GeneratorOptions.__init__(self, filename, apiname, profile,
                                   versions, emitversions, defaultExtensions,
                                   addExtensions, removeExtensions, sortProcedure)
@@ -338,6 +339,7 @@ class ThreadGeneratorOptions(GeneratorOptions):
         self.indentFuncProto = indentFuncProto
         self.indentFuncPointer = indentFuncPointer
         self.alignFuncParam  = alignFuncParam
+        self.genDirectory    = genDirectory
 
 
 # ParamCheckerGeneratorOptions - subclass of GeneratorOptions.
@@ -396,7 +398,8 @@ class ParamCheckerGeneratorOptions(GeneratorOptions):
                  apientryp = '',
                  indentFuncProto = True,
                  indentFuncPointer = False,
-                 alignFuncParam = 0):
+                 alignFuncParam = 0,
+                 genDirectory = None):
         GeneratorOptions.__init__(self, filename, apiname, profile,
                                   versions, emitversions, defaultExtensions,
                                   addExtensions, removeExtensions, sortProcedure)
@@ -412,6 +415,7 @@ class ParamCheckerGeneratorOptions(GeneratorOptions):
         self.indentFuncProto = indentFuncProto
         self.indentFuncPointer = indentFuncPointer
         self.alignFuncParam  = alignFuncParam
+        self.genDirectory    = genDirectory
 
 
 # OutputGenerator - base class for generating API interfaces.
@@ -561,7 +565,10 @@ class OutputGenerator:
         # Open specified output file. Not done in constructor since a
         # Generator can be used without writing to a file.
         if (self.genOpts.filename != None):
-            self.outFile = open(self.genOpts.filename, 'w')
+            if (self.genOpts.genDirectory != None):
+                self.outFile = open(os.path.join(self.genOpts.genDirectory, self.genOpts.filename), 'w')
+            else:
+                self.outFile = open(self.genOpts.filename, 'w')
         else:
             self.outFile = sys.stdout
     def endFile(self):
index 5ffd5e4..ad1ff55 100755 (executable)
--- a/genvk.py
+++ b/genvk.py
@@ -38,6 +38,7 @@ validate= False
 errFilename = None
 diagFilename = 'diag.txt'
 regFilename = 'vk.xml'
+outDir = '.'
 
 if __name__ == '__main__':
     i = 1
@@ -66,6 +67,10 @@ if __name__ == '__main__':
         elif (arg == '-validate'):
             write('Enabling group validation (-validate)', file=sys.stderr)
             validate = True
+        elif (arg == '-outdir'):
+            outDir = sys.argv[i]
+            i = i+1
+            write('Using output directory ', outDir, file=sys.stderr)
         elif (arg[0:1] == '-'):
             write('Unrecognized argument:', arg, file=sys.stderr)
             exit(1)
@@ -278,7 +283,8 @@ buildList = [
         apicall           = '',
         apientry          = 'VKAPI_CALL ',
         apientryp         = 'VKAPI_PTR *',
-        alignFuncParam    = 48)
+        alignFuncParam    = 48,
+        genDirectory      = outDir)
     ],
     [ ParamCheckerOutputGenerator,
       ParamCheckerGeneratorOptions(
@@ -299,7 +305,8 @@ buildList = [
         apicall           = 'VKAPI_ATTR ',
         apientry          = 'VKAPI_CALL ',
         apientryp         = 'VKAPI_PTR *',
-        alignFuncParam    = 48)
+        alignFuncParam    = 48,
+        genDirectory      = outDir)
     ],
     None
 ]
@@ -311,6 +318,11 @@ else:
     errWarn = sys.stderr
 diag = open(diagFilename, 'w')
 
+# check that output directory exists
+if (not os.path.isdir(outDir)):
+    write('Output directory does not exist: ', outDir)
+    raise
+
 def genHeaders():
     # Loop over targets, building each
     generated = 0