#include "translator.h"
+#include <qmakevfs.h>
#include <qmakeparser.h>
#include <profileevaluator.h>
option.qmake_abslocation = app.applicationDirPath() + QLatin1String("/qmake");
#endif
option.initProperties();
- QMakeParser parser(0, &evalHandler);
- ProFileEvaluator visitor(&option, &parser, &evalHandler);
+ QMakeVfs vfs;
+ QMakeParser parser(0, &vfs, &evalHandler);
+ ProFileEvaluator visitor(&option, &parser, &vfs, &evalHandler);
visitor.setCumulative(true);
visitor.setOutputDir(QDir::currentPath());
#include "lupdate.h"
#include <translator.h>
+#include <qmakevfs.h>
#include <qmakeparser.h>
#include <profileevaluator.h>
}
static void processProjects(bool topLevel, bool nestComplain, const QStringList &proFiles,
- const QHash<QString, QString> &outDirMap, ProFileGlobals *option, QMakeParser *parser,
+ const QHash<QString, QString> &outDirMap,
+ ProFileGlobals *option, QMakeVfs *vfs, QMakeParser *parser,
UpdateOptions options,
const QString &targetLanguage, const QString &sourceLanguage,
Translator *parentTor, bool *fail);
static void processProject(
bool nestComplain, const QString &proFile,
- ProFileGlobals *option, QMakeParser *parser, ProFileEvaluator &visitor,
+ ProFileGlobals *option, QMakeVfs *vfs, QMakeParser *parser, ProFileEvaluator &visitor,
UpdateOptions options,
const QString &targetLanguage, const QString &sourceLanguage,
Translator *fetchedTor, bool *fail)
subProFiles << subPro;
}
processProjects(false, nestComplain, subProFiles, QHash<QString, QString>(),
- option, parser, options,
+ option, vfs, parser, options,
targetLanguage, sourceLanguage, fetchedTor, fail);
} else {
ConversionData cd;
}
static void processProjects(bool topLevel, bool nestComplain, const QStringList &proFiles,
- const QHash<QString, QString> &outDirMap, ProFileGlobals *option, QMakeParser *parser,
+ const QHash<QString, QString> &outDirMap,
+ ProFileGlobals *option, QMakeVfs *vfs, QMakeParser *parser,
UpdateOptions options,
const QString &targetLanguage, const QString &sourceLanguage,
Translator *parentTor, bool *fail)
if (!outDirMap.isEmpty())
option->setDirectories(QFileInfo(proFile).path(), outDirMap[proFile]);
- ProFileEvaluator visitor(option, parser, &evalHandler);
+ ProFileEvaluator visitor(option, parser, vfs, &evalHandler);
visitor.setCumulative(true);
visitor.setOutputDir(option->shadowedPath(proFile));
ProFile *pro;
continue;
}
Translator tor;
- processProject(false, proFile, option, parser, visitor, options,
+ processProject(false, proFile, option, vfs, parser, visitor, options,
targetLanguage, sourceLanguage, &tor, fail);
updateTsFiles(tor, tsFiles, QStringList(),
sourceLanguage, targetLanguage, options, fail);
printErr(LU::tr("lupdate warning: no TS files specified. Only diagnostics "
"will be produced for '%1'.\n").arg(proFile));
Translator tor;
- processProject(nestComplain, proFile, option, parser, visitor, options,
+ processProject(nestComplain, proFile, option, vfs, parser, visitor, options,
targetLanguage, sourceLanguage, &tor, fail);
} else {
- processProject(nestComplain, proFile, option, parser, visitor, options,
+ processProject(nestComplain, proFile, option, vfs, parser, visitor, options,
targetLanguage, sourceLanguage, parentTor, fail);
}
pro->deref();
option.initProperties();
option.setCommandLineArguments(QDir::currentPath(),
QStringList() << QLatin1String("CONFIG+=lupdate_run"));
- QMakeParser parser(0, &evalHandler);
+ QMakeVfs vfs;
+ QMakeParser parser(0, &vfs, &evalHandler);
if (!tsFileNames.isEmpty()) {
Translator fetchedTor;
- processProjects(true, true, proFiles, outDirMap, &option, &parser, options,
+ processProjects(true, true, proFiles, outDirMap, &option, &vfs, &parser, options,
targetLanguage, sourceLanguage, &fetchedTor, &fail);
updateTsFiles(fetchedTor, tsFileNames, alienFiles,
sourceLanguage, targetLanguage, options, &fail);
} else {
- processProjects(true, false, proFiles, outDirMap, &option, &parser, options,
+ processProjects(true, false, proFiles, outDirMap, &option, &vfs, &parser, options,
targetLanguage, sourceLanguage, 0, &fail);
}
}
QMakeEvaluator::initStatics();
}
-ProFileEvaluator::ProFileEvaluator(ProFileGlobals *option, QMakeParser *parser,
+ProFileEvaluator::ProFileEvaluator(ProFileGlobals *option, QMakeParser *parser, QMakeVfs *vfs,
QMakeHandler *handler)
- : d(new QMakeEvaluator(option, parser, handler))
+ : d(new QMakeEvaluator(option, parser, vfs, handler))
{
}
QT_BEGIN_NAMESPACE
+class QMakeVfs;
class QMakeParser;
class QMakeEvaluator;
class QMakeHandler;
// Call this from a concurrency-free context
static void initialize();
- ProFileEvaluator(ProFileGlobals *option, QMakeParser *parser, QMakeHandler *handler);
+ ProFileEvaluator(ProFileGlobals *option, QMakeParser *parser, QMakeVfs *vfs,
+ QMakeHandler *handler);
~ProFileEvaluator();
ProFileEvaluator::TemplateType templateType() const;
HEADERS += \
$$PWD/qmake_global.h \
$$PWD/ioutils.h \
+ $$PWD/qmakevfs.h \
$$PWD/proitems.h \
$$PWD/qmakeglobals.h \
$$PWD/qmakeparser.h \
SOURCES += \
$$PWD/ioutils.cpp \
+ $$PWD/qmakevfs.cpp \
$$PWD/proitems.cpp \
$$PWD/qmakeglobals.cpp \
$$PWD/qmakeparser.cpp \
#include "qmakeevaluator_p.h"
#include "qmakeglobals.h"
#include "qmakeparser.h"
+#include "qmakevfs.h"
#include "ioutils.h"
#include <qbytearray.h>
return ret;
}
-static bool
-doWriteFile(const QString &name, QIODevice::OpenMode mode, const QString &contents, QString *errStr)
-{
- QByteArray bytes = contents.toLocal8Bit();
- QFile cfile(name);
- if (!(mode & QIODevice::Append) && cfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
- if (cfile.readAll() == bytes)
- return true;
- cfile.close();
- }
- if (!cfile.open(mode | QIODevice::WriteOnly | QIODevice::Text)) {
- *errStr = cfile.errorString();
- return false;
- }
- cfile.write(bytes);
- cfile.close();
- if (cfile.error() != QFile::NoError) {
- *errStr = cfile.errorString();
- return false;
- }
- return true;
-}
-
QMakeEvaluator::VisitReturn
QMakeEvaluator::writeFile(const QString &ctx, const QString &fn, QIODevice::OpenMode mode,
const QString &contents)
{
- QFileInfo qfi(fn);
- if (!QDir::current().mkpath(qfi.path())) {
- evalError(fL1S("Cannot create %1directory %2.")
- .arg(ctx, QDir::toNativeSeparators(qfi.path())));
- return ReturnFalse;
- }
QString errStr;
- if (!doWriteFile(fn, mode, contents, &errStr)) {
+ if (!m_vfs->writeFile(fn, mode, contents, &errStr)) {
evalError(fL1S("Cannot write %1file %2: %3.")
.arg(ctx, QDir::toNativeSeparators(fn), errStr));
return ReturnFalse;
}
const QString &file = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1)));
+ // Don't use VFS here:
+ // - it supports neither listing nor even directories
+ // - it's unlikely that somebody would test for files they created themselves
if (IoUtils::exists(file))
return ReturnTrue;
int slsh = file.lastIndexOf(QLatin1Char('/'));
evalError(fL1S("write_file(name, [content var, [append]]) requires one to three arguments."));
return ReturnFalse;
}
-#ifdef PROEVALUATOR_FULL
QIODevice::OpenMode mode = QIODevice::Truncate;
QString contents;
if (args.count() >= 2) {
mode = QIODevice::Append;
}
return writeFile(QString(), resolvePath(args.at(0).toQString(m_tmp1)), mode, contents);
-#else
- return ReturnTrue;
-#endif
}
case T_TOUCH: {
if (args.count() != 2) {
evalError(fL1S("cache(var, [set|add|sub] [transient] [super], [srcvar]) requires one to three arguments."));
return ReturnFalse;
}
-#ifdef PROEVALUATOR_FULL
bool persist = true;
bool super = false;
enum { CacheSet, CacheAdd, CacheSub } mode = CacheSet;
fn = m_cachefile;
}
return writeFile(fL1S("cache "), fn, QIODevice::Append, varstr);
-#else
- return ReturnTrue;
-#endif
}
default:
evalError(fL1S("Function '%1' is not implemented.").arg(function.toQString(m_tmp1)));
#include "qmakeglobals.h"
#include "qmakeparser.h"
+#include "qmakevfs.h"
#include "ioutils.h"
#include <qbytearray.h>
}
-QMakeEvaluator::QMakeEvaluator(QMakeGlobals *option,
- QMakeParser *parser, QMakeHandler *handler)
+QMakeEvaluator::QMakeEvaluator(QMakeGlobals *option, QMakeParser *parser, QMakeVfs *vfs,
+ QMakeHandler *handler)
:
#ifdef PROEVALUATOR_DEBUG
m_debugLevel(option->debugLevel),
#endif
- m_option(option), m_parser(parser), m_handler(handler)
+ m_option(option), m_parser(parser), m_handler(handler), m_vfs(vfs)
{
// So that single-threaded apps don't have to call initialize() for now.
initStatics();
superdir = m_outputDir;
forever {
QString superfile = superdir + QLatin1String("/.qmake.super");
- if (IoUtils::exists(superfile)) {
+ if (m_vfs->exists(superfile)) {
m_superfile = QDir::cleanPath(superfile);
break;
}
QString dir = m_outputDir;
forever {
conffile = sdir + QLatin1String("/.qmake.conf");
- if (!IoUtils::exists(conffile))
+ if (!m_vfs->exists(conffile))
conffile.clear();
cachefile = dir + QLatin1String("/.qmake.cache");
- if (!IoUtils::exists(cachefile))
+ if (!m_vfs->exists(cachefile))
cachefile.clear();
if (!conffile.isEmpty() || !cachefile.isEmpty()) {
if (dir != sdir)
m_hostBuild ? m_option->qmakespec : m_option->xqmakespec);
{
- QMakeEvaluator evaluator(m_option, m_parser, m_handler);
+ QMakeEvaluator evaluator(m_option, m_parser, m_vfs, m_handler);
if (!m_superfile.isEmpty()) {
valuesRef(ProKey("_QMAKE_SUPER_CACHE_")) << ProString(m_superfile);
if (evaluator.evaluateFile(
locker.unlock();
#endif
- QMakeEvaluator *baseEval = new QMakeEvaluator(m_option, m_parser, m_handler);
+ QMakeEvaluator *baseEval = new QMakeEvaluator(m_option, m_parser, m_vfs, m_handler);
baseEnv->evaluator = baseEval;
baseEval->m_superfile = m_superfile;
baseEval->m_conffile = m_conffile;
QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateFileInto(
const QString &fileName, ProValueMap *values, LoadFlags flags)
{
- QMakeEvaluator visitor(m_option, m_parser, m_handler);
+ QMakeEvaluator visitor(m_option, m_parser, m_vfs, m_handler);
visitor.m_caller = this;
visitor.m_outputDir = m_outputDir;
visitor.m_featureRoots = m_featureRoots;
static void initStatics();
static void initFunctionStatics();
- QMakeEvaluator(QMakeGlobals *option, QMakeParser *parser,
+ QMakeEvaluator(QMakeGlobals *option, QMakeParser *parser, QMakeVfs *vfs,
QMakeHandler *handler);
~QMakeEvaluator();
QMakeGlobals *m_option;
QMakeParser *m_parser;
QMakeHandler *m_handler;
+ QMakeVfs *m_vfs;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QMakeEvaluator::LoadFlags)
#include "qmakeparser.h"
+#include "qmakevfs.h"
#include "ioutils.h"
using namespace QMakeInternal;
statics.strLITERAL_WHITESPACE = QLatin1String("LITERAL_WHITESPACE");
}
-QMakeParser::QMakeParser(ProFileCache *cache, QMakeParserHandler *handler)
+QMakeParser::QMakeParser(ProFileCache *cache, QMakeVfs *vfs, QMakeParserHandler *handler)
: m_cache(cache)
, m_handler(handler)
+ , m_vfs(vfs)
{
// So that single-threaded apps don't have to call initialize() for now.
initialize();
bool QMakeParser::read(ProFile *pro, ParseFlags flags)
{
- QFile file(pro->fileName());
- if (!file.open(QIODevice::ReadOnly)) {
- if (m_handler && ((flags & ParseReportMissing) || IoUtils::exists(pro->fileName())))
+ QString content;
+ QString errStr;
+ if (!m_vfs->readFile(pro->fileName(), &content, &errStr)) {
+ if (m_handler && ((flags & ParseReportMissing) || m_vfs->exists(pro->fileName())))
m_handler->message(QMakeParserHandler::ParserIoError,
- fL1S("Cannot read %1: %2").arg(pro->fileName(), file.errorString()));
+ fL1S("Cannot read %1: %2").arg(pro->fileName(), errStr));
return false;
}
-
- QByteArray bcont = file.readAll();
- if (bcont.startsWith("\xef\xbb\xbf")) {
- // UTF-8 BOM will cause subtle errors
- m_handler->message(QMakeParserHandler::ParserIoError,
- fL1S("Unexpected UTF-8 BOM in %1").arg(pro->fileName()));
- return false;
- }
- QString content(QString::fromLocal8Bit(bcont));
- bcont.clear();
- file.close();
return read(pro, content, 1, FullGrammar);
}
};
class ProFileCache;
+class QMakeVfs;
class QMAKE_EXPORT QMakeParser
{
};
Q_DECLARE_FLAGS(ParseFlags, ParseFlag)
- QMakeParser(ProFileCache *cache, QMakeParserHandler *handler);
+ QMakeParser(ProFileCache *cache, QMakeVfs *vfs, QMakeParserHandler *handler);
enum SubGrammar { FullGrammar, TestGrammar, ValueGrammar };
// fileName is expected to be absolute and cleanPath()ed.
ProFileCache *m_cache;
QMakeParserHandler *m_handler;
+ QMakeVfs *m_vfs;
// This doesn't help gcc 3.3 ...
template<typename T> friend class QTypeInfo;
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Linguist of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmakevfs.h"
+
+#include "ioutils.h"
+using namespace QMakeInternal;
+
+#include <qdir.h>
+#include <qfile.h>
+#include <qfileinfo.h>
+
+#define fL1S(s) QString::fromLatin1(s)
+
+QT_BEGIN_NAMESPACE
+
+QMakeVfs::QMakeVfs()
+#ifndef PROEVALUATOR_FULL
+ : m_magicMissing(fL1S("missing"))
+ , m_magicExisting(fL1S("existing"))
+#endif
+{
+}
+
+bool QMakeVfs::writeFile(const QString &fn, QIODevice::OpenMode mode, const QString &contents,
+ QString *errStr)
+{
+#ifndef PROEVALUATOR_FULL
+# ifdef PROEVALUATOR_THREAD_SAFE
+ QMutexLocker locker(&m_mutex);
+# endif
+ QString *cont = &m_files[fn];
+ if (mode & QIODevice::Append)
+ *cont += contents;
+ else
+ *cont = contents;
+ Q_UNUSED(errStr)
+ return true;
+#else
+ QFileInfo qfi(fn);
+ if (!QDir::current().mkpath(qfi.path())) {
+ *errStr = fL1S("Cannot create parent directory");
+ return false;
+ }
+ QByteArray bytes = contents.toLocal8Bit();
+ QFile cfile(fn);
+ if (!(mode & QIODevice::Append) && cfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ if (cfile.readAll() == bytes)
+ return true;
+ cfile.close();
+ }
+ if (!cfile.open(mode | QIODevice::WriteOnly | QIODevice::Text)) {
+ *errStr = cfile.errorString();
+ return false;
+ }
+ cfile.write(bytes);
+ cfile.close();
+ if (cfile.error() != QFile::NoError) {
+ *errStr = cfile.errorString();
+ return false;
+ }
+ return true;
+#endif
+}
+
+bool QMakeVfs::readFile(const QString &fn, QString *contents, QString *errStr)
+{
+#ifndef PROEVALUATOR_FULL
+# ifdef PROEVALUATOR_THREAD_SAFE
+ QMutexLocker locker(&m_mutex);
+# endif
+ QHash<QString, QString>::ConstIterator it = m_files.constFind(fn);
+ if (it != m_files.constEnd()) {
+ if (it->constData() == m_magicMissing.constData()) {
+ *errStr = fL1S("No such file or directory");
+ return false;
+ }
+ if (it->constData() != m_magicExisting.constData()) {
+ *contents = *it;
+ return true;
+ }
+ }
+#endif
+
+ QFile file(fn);
+ if (!file.open(QIODevice::ReadOnly)) {
+#ifndef PROEVALUATOR_FULL
+ if (!IoUtils::exists(fn)) {
+ m_files[fn] = m_magicMissing;
+ *errStr = fL1S("No such file or directory");
+ } else
+#endif
+ *errStr = file.errorString();
+ return false;
+ }
+#ifndef PROEVALUATOR_FULL
+ m_files[fn] = m_magicExisting;
+#endif
+
+ QByteArray bcont = file.readAll();
+ if (bcont.startsWith("\xef\xbb\xbf")) {
+ // UTF-8 BOM will cause subtle errors
+ *errStr = fL1S("Unexpected UTF-8 BOM");
+ return false;
+ }
+ *contents = QString::fromLocal8Bit(bcont);
+ return true;
+}
+
+bool QMakeVfs::exists(const QString &fn)
+{
+#ifndef PROEVALUATOR_FULL
+# ifdef PROEVALUATOR_THREAD_SAFE
+ QMutexLocker locker(&m_mutex);
+# endif
+ QHash<QString, QString>::ConstIterator it = m_files.constFind(fn);
+ if (it != m_files.constEnd())
+ return it->constData() != m_magicMissing.constData();
+#endif
+ bool ex = IoUtils::exists(fn);
+#ifndef PROEVALUATOR_FULL
+ m_files[fn] = ex ? m_magicExisting : m_magicMissing;
+#endif
+ return ex;
+}
+
+#ifndef PROEVALUATOR_FULL
+// This should be called when the sources may have changed (e.g., VCS update).
+void QMakeVfs::invalidateCache()
+{
+# ifdef PROEVALUATOR_THREAD_SAFE
+ QMutexLocker locker(&m_mutex);
+# endif
+ QHash<QString, QString>::Iterator it = m_files.begin(), eit = m_files.end();
+ while (it != eit) {
+ if (it->constData() == m_magicMissing.constData()
+ ||it->constData() == m_magicExisting.constData())
+ it = m_files.erase(it);
+ else
+ ++it;
+ }
+}
+
+// This should be called when generated files may have changed (e.g., actual build).
+void QMakeVfs::invalidateContents()
+{
+# ifdef PROEVALUATOR_THREAD_SAFE
+ QMutexLocker locker(&m_mutex);
+# endif
+ m_files.clear();
+}
+#endif
+
+QT_END_NAMESPACE
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Linguist of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMAKEVFS_H
+#define QMAKEVFS_H
+
+#include "qmake_global.h"
+
+# include <qiodevice.h>
+#ifndef PROEVALUATOR_FULL
+# include <qhash.h>
+# include <qstring.h>
+# ifdef PROEVALUATOR_THREAD_SAFE
+# include <qmutex.h>
+# endif
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class QMAKE_EXPORT QMakeVfs
+{
+public:
+ QMakeVfs();
+
+ bool writeFile(const QString &fn, QIODevice::OpenMode mode, const QString &contents, QString *errStr);
+ bool readFile(const QString &fn, QString *contents, QString *errStr);
+ bool exists(const QString &fn);
+
+#ifndef PROEVALUATOR_FULL
+ void invalidateCache();
+ void invalidateContents();
+#endif
+
+private:
+#ifndef PROEVALUATOR_FULL
+# ifdef PROEVALUATOR_THREAD_SAFE
+ QMutex m_mutex;
+# endif
+ QHash<QString, QString> m_files;
+ QString m_magicMissing;
+ QString m_magicExisting;
+#endif
+};
+
+QT_END_NAMESPACE
+
+#endif // QMAKEVFS_H