MoltenVKShaderConverter tool returns failure exit code when any file in directory fails.
diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md
index 22887a7..0c2955b 100644
--- a/Docs/Whats_New.md
+++ b/Docs/Whats_New.md
@@ -16,7 +16,7 @@
MoltenVK 1.0.31
---------------
-Released 2019/01/15
+Released 2019/01/16
- Support runtime config via runtime environment variables
- Add full ImageView swizzling to config, and disable it by default.
@@ -31,6 +31,7 @@
- Update copyright to 2019.
- Advertise the `VK_AMD_gpu_shader_half_float` extension.
- Support the `VK_KHR_variable_pointers` extension.
+- MoltenVKShaderConverter tool exit with fail code on any file conversion fail.
- Update to latest SPIRV-Cross version:
- MSL: Support SPV_KHR_variable_pointers.
- MSL: Workaround missing gradient2d() on macOS for typical cascaded shadow mapping.
diff --git a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/DirectorySupport.h b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/DirectorySupport.h
index f2509d8..eb7cb1b 100644
--- a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/DirectorySupport.h
+++ b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/DirectorySupport.h
@@ -29,10 +29,12 @@
* or absolute path, and calls the processFile(std::string filePath) member function
* on the fileProcessor for each file in the directory. If the isRecursive parameter
* is true, the iteration will include all files in all sub-directories as well.
+ *
* The processFile(std::string filePath) member function on the fileProcessor should
- * return true to cause the processing of any further files to halt, and this function
- * to return, or should return false to allow further files to be iterated.
- * Returns false if the directory could not be found or iterated. Returns true otherwise.
+ * return whether that file was successfully processed.
+ *
+ * Returns false if the directory could not be found or iterated, or if an error
+ * occurs with the conversion of any file. Returns true otherwise.
*/
template <typename FileProcessor>
bool iterateDirectory(const std::string& dirPath,
diff --git a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/DirectorySupport.mm b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/DirectorySupport.mm
index 695d6a1..a3aff3b 100644
--- a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/DirectorySupport.mm
+++ b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/DirectorySupport.mm
@@ -27,9 +27,9 @@
template <typename FileProcessor>
bool mvk::iterateDirectory(const string& dirPath,
- FileProcessor& fileProcessor,
- bool isRecursive,
- string& errMsg) {
+ FileProcessor& fileProcessor,
+ bool isRecursive,
+ string& errMsg) {
NSString* nsAbsDirPath = @(absolutePath(dirPath).data());
NSFileManager* fileMgr = NSFileManager.defaultManager;
BOOL isDir = false;
@@ -43,14 +43,15 @@
return false;
}
+ bool success = true;
NSDirectoryEnumerator* dirEnum = [fileMgr enumeratorAtPath: nsAbsDirPath];
NSString* filePath;
while ((filePath = dirEnum.nextObject)) {
if ( !isRecursive ) { [dirEnum skipDescendants]; }
NSString* absFilePath = [nsAbsDirPath stringByAppendingPathComponent: filePath];
- if(fileProcessor.processFile(absFilePath.UTF8String)) { return true; }
+ if( !fileProcessor.processFile(absFilePath.UTF8String) ) { success = false; }
}
- return true;
+ return success;
}
/** Concrete template implementation to allow MoltenVKShaderConverterTool to iterate the files in a directory. */
diff --git a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.cpp b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.cpp
index 15307ce..61287ab 100644
--- a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.cpp
+++ b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.cpp
@@ -67,12 +67,12 @@
string pathExtn = pathExtension(absPath);
if (_shouldReadGLSL && isGLSLFileExtension(pathExtn)) {
- convertGLSL(absPath, emptyPath, emptyPath, kMVKShaderStageAuto);
+ return convertGLSL(absPath, emptyPath, emptyPath, kMVKShaderStageAuto);
} else if (_shouldReadSPIRV && isSPIRVFileExtension(pathExtn)) {
- convertSPIRV(absPath, emptyPath);
+ return convertSPIRV(absPath, emptyPath);
}
- return false;
+ return true;
}
// Read GLSL code from a GLSL file, convert to SPIR-V, and optionally MSL,
diff --git a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.h b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.h
index 5a80cd7..424a277 100644
--- a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.h
+++ b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.h
@@ -38,7 +38,9 @@
/**
* Called automatically during the conversion of all the files in a directory.
* Processes the specified file (which can contain either GLSL or SPIR-V code.
- * Always returns false.
+ *
+ * Returns false if the file is of the right type to be converted, but failed
+ * to be converted correctly. Returns true otherwise.
*/
bool processFile(std::string filePath);