1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the qmake application of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef QMAKEVFS_H
30#define QMAKEVFS_H
31
32#include "qmake_global.h"
33
34#include <qiodevice.h>
35#include <qhash.h>
36#include <qstring.h>
37#ifdef PROEVALUATOR_THREAD_SAFE
38# include <qmutex.h>
39#endif
40
41#if QT_CONFIG(textcodec)
42QT_FORWARD_DECLARE_CLASS(QTextCodec)
43#endif
44
45#ifdef PROEVALUATOR_DUAL_VFS
46# ifndef PROEVALUATOR_CUMULATIVE
47# error PROEVALUATOR_DUAL_VFS requires PROEVALUATOR_CUMULATIVE
48# endif
49#endif
50
51QT_BEGIN_NAMESPACE
52
53class QMAKE_EXPORT QMakeVfs
54{
55public:
56 enum ReadResult {
57 ReadOk,
58 ReadNotFound,
59 ReadOtherError
60 };
61
62 enum VfsFlag {
63 VfsExecutable = 1,
64 VfsExact = 0,
65#ifdef PROEVALUATOR_DUAL_VFS
66 VfsCumulative = 2,
67 VfsCreate = 4,
68 VfsCreatedOnly = 8,
69#else
70 VfsCumulative = 0,
71 VfsCreate = 0,
72 VfsCreatedOnly = 0,
73#endif
74 VfsAccessedOnly = 16
75 };
76 Q_DECLARE_FLAGS(VfsFlags, VfsFlag)
77
78 QMakeVfs();
79 ~QMakeVfs();
80
81 static void ref();
82 static void deref();
83
84 int idForFileName(const QString &fn, VfsFlags flags);
85 QString fileNameForId(int id);
86 bool writeFile(int id, QIODevice::OpenMode mode, VfsFlags flags, const QString &contents, QString *errStr);
87 ReadResult readFile(int id, QString *contents, QString *errStr);
88 bool exists(const QString &fn, QMakeVfs::VfsFlags flags);
89
90#ifndef PROEVALUATOR_FULL
91 void invalidateCache();
92 void invalidateContents();
93#endif
94
95#if QT_CONFIG(textcodec)
96 void setTextCodec(const QTextCodec *textCodec);
97#endif
98
99private:
100#ifdef PROEVALUATOR_THREAD_SAFE
101 static QMutex s_mutex;
102#endif
103 static int s_refCount;
104 static QAtomicInt s_fileIdCounter;
105 // Qt Creator's ProFile cache is a singleton to maximize its cross-project
106 // effectiveness (shared prf files from QtVersions).
107 // For this to actually work, real files need a global mapping.
108 // This is fine, because the namespace of real files is indeed global.
109 static QHash<QString, int> s_fileIdMap;
110 static QHash<int, QString> s_idFileMap;
111#ifdef PROEVALUATOR_DUAL_VFS
112# ifdef PROEVALUATOR_THREAD_SAFE
113 // The simple way to avoid recursing m_mutex.
114 QMutex m_vmutex;
115# endif
116 // Virtual files are bound to the project context they were created in,
117 // so their ids need to be local as well.
118 // We violate that rule in lupdate (which has a non-dual VFS), but that
119 // does not matter, because it has only one project context anyway.
120 QHash<QString, int> m_virtualFileIdMap[2]; // Exact and cumulative
121 QHash<int, QString> m_virtualIdFileMap; // Only one map, as ids are unique across realms.
122#endif
123
124#ifndef PROEVALUATOR_FULL
125# ifdef PROEVALUATOR_THREAD_SAFE
126 QMutex m_mutex;
127# endif
128 QHash<int, QString> m_files;
129 QString m_magicMissing;
130 QString m_magicExisting;
131#endif
132#if QT_CONFIG(textcodec)
133 const QTextCodec *m_textCodec;
134#endif
135};
136
137Q_DECLARE_OPERATORS_FOR_FLAGS(QMakeVfs::VfsFlags)
138
139QT_END_NAMESPACE
140
141#endif // QMAKEVFS_H
142

source code of qtbase/qmake/library/qmakevfs.h