| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 3 |
|
| 4 |
#ifndef QMAKEVFS_H |
| 5 |
#define QMAKEVFS_H |
| 6 |
|
| 7 |
#include "qmake_global.h" |
| 8 |
|
| 9 |
#include <qiodevice.h> |
| 10 |
#include <qhash.h> |
| 11 |
#include <qstring.h> |
| 12 |
#ifdef PROEVALUATOR_THREAD_SAFE |
| 13 |
# include <qmutex.h> |
| 14 |
#endif |
| 15 |
|
| 16 |
#ifdef PROEVALUATOR_DUAL_VFS |
| 17 |
# ifndef PROEVALUATOR_CUMULATIVE |
| 18 |
# error PROEVALUATOR_DUAL_VFS requires PROEVALUATOR_CUMULATIVE |
| 19 |
# endif |
| 20 |
#endif |
| 21 |
|
| 22 |
QT_BEGIN_NAMESPACE |
| 23 |
|
| 24 |
class QMAKE_EXPORT QMakeVfs |
| 25 |
{ |
| 26 |
public: |
| 27 |
enum ReadResult { |
| 28 |
ReadOk, |
| 29 |
ReadNotFound, |
| 30 |
ReadOtherError |
| 31 |
}; |
| 32 |
|
| 33 |
enum VfsFlag { |
| 34 |
VfsExecutable = 1, |
| 35 |
VfsExact = 0, |
| 36 |
#ifdef PROEVALUATOR_DUAL_VFS |
| 37 |
VfsCumulative = 2, |
| 38 |
VfsCreate = 4, |
| 39 |
VfsCreatedOnly = 8, |
| 40 |
#else |
| 41 |
VfsCumulative = 0, |
| 42 |
VfsCreate = 0, |
| 43 |
VfsCreatedOnly = 0, |
| 44 |
#endif |
| 45 |
VfsAccessedOnly = 16 |
| 46 |
}; |
| 47 |
Q_DECLARE_FLAGS(VfsFlags, VfsFlag) |
| 48 |
|
| 49 |
QMakeVfs(); |
| 50 |
~QMakeVfs(); |
| 51 |
|
| 52 |
static void ref(); |
| 53 |
static void deref(); |
| 54 |
|
| 55 |
int idForFileName(const QString &fn, VfsFlags flags); |
| 56 |
QString fileNameForId(int id); |
| 57 |
bool writeFile(int id, QIODevice::OpenMode mode, VfsFlags flags, const QString &contents, QString *errStr); |
| 58 |
ReadResult readFile(int id, QString *contents, QString *errStr); |
| 59 |
bool exists(const QString &fn, QMakeVfs::VfsFlags flags); |
| 60 |
|
| 61 |
#ifndef PROEVALUATOR_FULL |
| 62 |
void invalidateCache(); |
| 63 |
void invalidateContents(); |
| 64 |
#endif |
| 65 |
|
| 66 |
private: |
| 67 |
#ifdef PROEVALUATOR_THREAD_SAFE |
| 68 |
static QMutex s_mutex; |
| 69 |
#endif |
| 70 |
static int s_refCount; |
| 71 |
static QAtomicInt s_fileIdCounter; |
| 72 |
// Qt Creator's ProFile cache is a singleton to maximize its cross-project |
| 73 |
// effectiveness (shared prf files from QtVersions). |
| 74 |
// For this to actually work, real files need a global mapping. |
| 75 |
// This is fine, because the namespace of real files is indeed global. |
| 76 |
static QHash<QString, int> s_fileIdMap; |
| 77 |
static QHash<int, QString> s_idFileMap; |
| 78 |
#ifdef PROEVALUATOR_DUAL_VFS |
| 79 |
# ifdef PROEVALUATOR_THREAD_SAFE |
| 80 |
// The simple way to avoid recursing m_mutex. |
| 81 |
QMutex m_vmutex; |
| 82 |
# endif |
| 83 |
// Virtual files are bound to the project context they were created in, |
| 84 |
// so their ids need to be local as well. |
| 85 |
// We violate that rule in lupdate (which has a non-dual VFS), but that |
| 86 |
// does not matter, because it has only one project context anyway. |
| 87 |
QHash<QString, int> m_virtualFileIdMap[2]; // Exact and cumulative |
| 88 |
QHash<int, QString> m_virtualIdFileMap; // Only one map, as ids are unique across realms. |
| 89 |
#endif |
| 90 |
|
| 91 |
#ifndef PROEVALUATOR_FULL |
| 92 |
# ifdef PROEVALUATOR_THREAD_SAFE |
| 93 |
QMutex m_mutex; |
| 94 |
# endif |
| 95 |
QHash<int, QString> m_files; |
| 96 |
QString m_magicMissing; |
| 97 |
QString m_magicExisting; |
| 98 |
#endif |
| 99 |
}; |
| 100 |
|
| 101 |
Q_DECLARE_OPERATORS_FOR_FLAGS(QMakeVfs::VfsFlags) |
| 102 |
|
| 103 |
QT_END_NAMESPACE |
| 104 |
|
| 105 |
#endif // QMAKEVFS_H |