From c6fb7198d726d61d90a702aa66c89765c3f19e79 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 19 Oct 2018 13:10:18 +0200 Subject: shiboken: Use class FileOut for the module source file as well Ensure the diff/dry-run options work for this file as well. Move the touchFile() utility around and adapt the verifyDirectoryFor() helper to take a string. Task-number: PYSIDE-834 Change-Id: Ic34b5f8eff304d9de85f60082f582f0537805cd4 Reviewed-by: Alexandru Croitor Reviewed-by: Cristian Maureira-Fredes --- .../shiboken2/generator/shiboken2/cppgenerator.cpp | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'sources/shiboken2/generator/shiboken2') diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index f0d6c9082..6d16e1bfb 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -29,6 +29,7 @@ #include #include "cppgenerator.h" +#include "fileout.h" #include "overloaddata.h" #include #include @@ -5402,15 +5403,11 @@ bool CppGenerator::finishGeneration() QString moduleFileName(outputDirectory() + QLatin1Char('/') + subDirectoryForPackage(packageName())); moduleFileName += QLatin1Char('/') + moduleName().toLower() + QLatin1String("_module_wrapper.cpp"); - QFile file(moduleFileName); - verifyDirectoryFor(file); - if (!file.open(QFile::WriteOnly)) { - qCWarning(lcShiboken).noquote().nospace() - << "Error writing file: " << QDir::toNativeSeparators(moduleFileName); - return false; - } - QTextStream s(&file); + verifyDirectoryFor(moduleFileName); + FileOut file(moduleFileName); + + QTextStream &s = file.stream; // write license comment s << licenseComment() << endl; @@ -5735,6 +5732,18 @@ bool CppGenerator::finishGeneration() s << "SBK_MODULE_INIT_FUNCTION_END" << endl; + switch (file.done()) { + case FileOut::Failure: + return false; + case FileOut::Unchanged: + // Even if contents is unchanged, the last file modification time should be updated, + // so that the build system can rely on the fact the generated file is up-to-date. + file.touch(); + break; + case FileOut::Success: + break; + } + return true; } -- cgit v1.2.3