layers: Handle bad filename in APIDump settings file
authorTobin Ehlis <tobin@lunarg.com>
Fri, 28 Aug 2015 15:57:53 +0000 (09:57 -0600)
committerTobin Ehlis <tobin@lunarg.com>
Fri, 28 Aug 2015 16:30:07 +0000 (10:30 -0600)
If APIDumpLogFilename requested in vk_layer_settings.txt file has a bad path or cannot be opened for some other reason, then APIDump will write out an ERROR message w/ the bad filename and notify user that STDOUT will be used instead.

vk-layer-generate.py

index 8c3d63c..018e3ab 100755 (executable)
@@ -701,6 +701,13 @@ class APIDumpSubcommand(Subcommand):
         header_txt.append('#include <string>')
         header_txt.append('#include <string.h>')
         header_txt.append('')
+        header_txt.append('#include "vk_loader_platform.h"')
+        header_txt.append('#include "vk_layer.h"')
+        header_txt.append('#include "vk_struct_string_helper_cpp.h"')
+        header_txt.append('#include "vk_layer_table.h"')
+        header_txt.append('#include "vk_layer_extension_utils.h"')
+        header_txt.append('#include <unordered_map>')
+        header_txt.append('')
         header_txt.append('static std::ofstream fileStream;')
         header_txt.append('static std::string fileName = "vk_apidump.txt";')
         header_txt.append('std::ostream* outputStream = NULL;')
@@ -709,7 +716,12 @@ class APIDumpSubcommand(Subcommand):
         header_txt.append('    if(writeToFile)')
         header_txt.append('    {')
         header_txt.append('        fileStream.open(fileName);')
-        header_txt.append('        outputStream = &fileStream;')
+        header_txt.append('        if ((fileStream.rdstate() & fileStream.failbit) != 0) {')
+        header_txt.append('            outputStream = &std::cout;')
+        header_txt.append('            (*outputStream) << endl << "APIDump ERROR: Bad output filename specified: " << fileName << ". Writing to STDOUT instead" << endl << endl;')
+        header_txt.append('        }')
+        header_txt.append('        else')
+        header_txt.append('            outputStream = &fileStream;')
         header_txt.append('    }')
         header_txt.append('    else')
         header_txt.append('    {')
@@ -727,13 +739,6 @@ class APIDumpSubcommand(Subcommand):
         header_txt.append('}')
         header_txt.append('')
         header_txt.append('%s' % self.lineinfo.get())
-        header_txt.append('#include "vk_loader_platform.h"')
-        header_txt.append('#include "vk_layer.h"')
-        header_txt.append('#include "vk_struct_string_helper_cpp.h"')
-        header_txt.append('#include "vk_layer_table.h"')
-        header_txt.append('#include "vk_layer_extension_utils.h"')
-        header_txt.append('#include <unordered_map>')
-        header_txt.append('')
         header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
         header_txt.append('#include "vk_loader_platform.h"')
         header_txt.append('')