aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-10-19 13:10:18 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-10-19 17:22:51 +0000
commitc6fb7198d726d61d90a702aa66c89765c3f19e79 (patch)
treea6340d1cf46c03d1b74ed11f522a1f6034f15fc1 /sources/shiboken2
parentee4a3c9259258007e540eac505cdc9b5d38fdaac (diff)
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 <alexandru.croitor@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2')
-rw-r--r--sources/shiboken2/ApiExtractor/fileout.cpp16
-rw-r--r--sources/shiboken2/ApiExtractor/fileout.h6
-rw-r--r--sources/shiboken2/generator/generator.cpp21
-rw-r--r--sources/shiboken2/generator/generator.h2
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp25
5 files changed, 43 insertions, 27 deletions
diff --git a/sources/shiboken2/ApiExtractor/fileout.cpp b/sources/shiboken2/ApiExtractor/fileout.cpp
index 475eb386b..10a8f6be8 100644
--- a/sources/shiboken2/ApiExtractor/fileout.cpp
+++ b/sources/shiboken2/ApiExtractor/fileout.cpp
@@ -33,6 +33,7 @@
#include <QtCore/QTextCodec>
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
+#include <QtCore/QDebug>
#include <cstdio>
@@ -231,3 +232,18 @@ FileOut::State FileOut::done(QString *errorMessage)
return Success;
}
+
+void FileOut::touchFile(const QString &filePath)
+{
+ QFile toucher(filePath);
+ qint64 size = toucher.size();
+ if (!toucher.open(QIODevice::ReadWrite)) {
+ qCWarning(lcShiboken).noquote().nospace()
+ << QStringLiteral("Failed to touch file '%1'")
+ .arg(QDir::toNativeSeparators(filePath));
+ return;
+ }
+ toucher.resize(size+1);
+ toucher.resize(size);
+ toucher.close();
+}
diff --git a/sources/shiboken2/ApiExtractor/fileout.h b/sources/shiboken2/ApiExtractor/fileout.h
index 6c27b5b00..aace70131 100644
--- a/sources/shiboken2/ApiExtractor/fileout.h
+++ b/sources/shiboken2/ApiExtractor/fileout.h
@@ -46,9 +46,15 @@ public:
explicit FileOut(QString name);
~FileOut();
+ QString filePath() const { return name; }
+
State done();
State done(QString *errorMessage);
+ void touch() { touchFile(name); }
+
+ static void touchFile(const QString &filePath);
+
QTextStream stream;
static bool dummy;
diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp
index 456172ece..85a8c4769 100644
--- a/sources/shiboken2/generator/generator.cpp
+++ b/sources/shiboken2/generator/generator.cpp
@@ -376,21 +376,6 @@ void Generator::setOutputDirectory(const QString &outDir)
m_d->outDir = outDir;
}
-inline void touchFile(const QString &filePath)
-{
- QFile toucher(filePath);
- qint64 size = toucher.size();
- if (!toucher.open(QIODevice::ReadWrite)) {
- qCWarning(lcShiboken).noquote().nospace()
- << QStringLiteral("Failed to touch file '%1'")
- .arg(QDir::toNativeSeparators(filePath));
- return;
- }
- toucher.resize(size+1);
- toucher.resize(size);
- toucher.close();
-}
-
bool Generator::generateFileForContext(GeneratorContext &context)
{
AbstractMetaClass *cls = context.metaClass();
@@ -417,7 +402,7 @@ bool Generator::generateFileForContext(GeneratorContext &context)
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.
- touchFile(filePath);
+ fileOut.touch();
break;
case FileOut::Success:
break;
@@ -467,9 +452,9 @@ bool Generator::shouldGenerate(const AbstractMetaClass* metaClass) const
return shouldGenerateTypeEntry(metaClass->typeEntry());
}
-void verifyDirectoryFor(const QFile &file)
+void verifyDirectoryFor(const QString &file)
{
- QDir dir = QFileInfo(file).dir();
+ QDir dir = QFileInfo(file).absoluteDir();
if (!dir.exists()) {
if (!dir.mkpath(dir.absolutePath())) {
qCWarning(lcShiboken).noquote().nospace()
diff --git a/sources/shiboken2/generator/generator.h b/sources/shiboken2/generator/generator.h
index be9a789bd..225e7aec7 100644
--- a/sources/shiboken2/generator/generator.h
+++ b/sources/shiboken2/generator/generator.h
@@ -57,7 +57,7 @@ class ContainerTypeEntry;
class Indentor;
QTextStream& formatCode(QTextStream &s, const QString& code, Indentor &indentor);
-void verifyDirectoryFor(const QFile &file);
+void verifyDirectoryFor(const QString &file);
QString getClassTargetFullName(const AbstractMetaClass* metaClass, bool includePackageName = true);
QString getClassTargetFullName(const AbstractMetaEnum* metaEnum, bool includePackageName = true);
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 <memory>
#include "cppgenerator.h"
+#include "fileout.h"
#include "overloaddata.h"
#include <abstractmetalang.h>
#include <messages.h>
@@ -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;
}