Clang: Add lastModified to the precompiled header

It is important to know then the PCH generation started, so we can compare
the header file time stamps against it.

Change-Id: Id8ee91e886c153d9d4a37cc0438c682f2098f7fa
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2018-02-15 14:29:20 +01:00
parent f67df4f9ab
commit 1f0562742e
13 changed files with 48 additions and 44 deletions

View File

@@ -30,8 +30,8 @@ namespace ClangBackEnd {
QDebug operator<<(QDebug debug, const ProjectPartPch &projectPartPch) QDebug operator<<(QDebug debug, const ProjectPartPch &projectPartPch)
{ {
debug.nospace() << "FileContainer(" debug.nospace() << "FileContainer("
<< projectPartPch.id() << ", " << projectPartPch.projectPartId << ", "
<< projectPartPch.path() << ")"; << projectPartPch.pchPath << ")";
return debug; return debug;
} }

View File

@@ -35,33 +35,26 @@ class ProjectPartPch
{ {
public: public:
ProjectPartPch() = default; ProjectPartPch() = default;
ProjectPartPch(Utils::SmallString &&projectPartId, Utils::SmallString &&pchPath) ProjectPartPch(Utils::SmallString &&projectPartId,
: m_projectPartId(std::move(projectPartId)), Utils::SmallString &&pchPath,
m_pchPath(std::move(pchPath)) long long lastModified)
: projectPartId(std::move(projectPartId)),
pchPath(std::move(pchPath)),
lastModified(lastModified)
{} {}
const Utils::SmallString &id() const
{
return m_projectPartId;
}
const Utils::SmallString &path() const
{
return m_pchPath;
}
friend QDataStream &operator<<(QDataStream &out, const ProjectPartPch &container) friend QDataStream &operator<<(QDataStream &out, const ProjectPartPch &container)
{ {
out << container.m_projectPartId; out << container.projectPartId;
out << container.m_pchPath; out << container.pchPath;
return out; return out;
} }
friend QDataStream &operator>>(QDataStream &in, ProjectPartPch &container) friend QDataStream &operator>>(QDataStream &in, ProjectPartPch &container)
{ {
in >> container.m_projectPartId; in >> container.projectPartId;
in >> container.m_pchPath; in >> container.pchPath;
return in; return in;
} }
@@ -69,18 +62,19 @@ public:
friend bool operator==(const ProjectPartPch &first, friend bool operator==(const ProjectPartPch &first,
const ProjectPartPch &second) const ProjectPartPch &second)
{ {
return first.m_projectPartId == second.m_projectPartId return first.projectPartId == second.projectPartId
&& first.m_pchPath == second.m_pchPath; && first.pchPath == second.pchPath;
} }
ProjectPartPch clone() const ProjectPartPch clone() const
{ {
return ProjectPartPch(m_projectPartId.clone(), m_pchPath.clone()); return *this;
} }
private: public:
Utils::SmallString m_projectPartId; Utils::SmallString projectPartId;
Utils::SmallString m_pchPath; Utils::SmallString pchPath;
long long lastModified = -1;
}; };
CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const ProjectPartPch &projectPartPch); CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const ProjectPartPch &projectPartPch);

View File

@@ -42,8 +42,11 @@ void PchManagerClient::alive()
void PchManagerClient::precompiledHeadersUpdated(ClangBackEnd::PrecompiledHeadersUpdatedMessage &&message) void PchManagerClient::precompiledHeadersUpdated(ClangBackEnd::PrecompiledHeadersUpdatedMessage &&message)
{ {
for (const ClangBackEnd::ProjectPartPch &projectPartPch : message.projectPartPchs()) for (const ClangBackEnd::ProjectPartPch &projectPartPch : message.projectPartPchs()) {
precompiledHeaderUpdated(QString(projectPartPch.id()), QString(projectPartPch.path())); precompiledHeaderUpdated(QString(projectPartPch.projectPartId),
QString(projectPartPch.pchPath),
projectPartPch.lastModified);
}
} }
void PchManagerClient::precompiledHeaderRemoved(const QString &projectPartId) void PchManagerClient::precompiledHeaderRemoved(const QString &projectPartId)
@@ -78,10 +81,12 @@ const std::vector<PchManagerNotifierInterface *> &PchManagerClient::notifiers()
return m_notifiers; return m_notifiers;
} }
void PchManagerClient::precompiledHeaderUpdated(const QString &projectPartId, const QString &pchFilePath) void PchManagerClient::precompiledHeaderUpdated(const QString &projectPartId,
const QString &pchFilePath,
long long lastModified)
{ {
for (auto notifier : m_notifiers) for (auto notifier : m_notifiers)
notifier->precompiledHeaderUpdated(projectPartId, pchFilePath); notifier->precompiledHeaderUpdated(projectPartId, pchFilePath, lastModified);
} }
} // namespace ClangPchManager } // namespace ClangPchManager

View File

@@ -47,7 +47,9 @@ public:
unittest_public: unittest_public:
const std::vector<PchManagerNotifierInterface*> &notifiers() const; const std::vector<PchManagerNotifierInterface*> &notifiers() const;
void precompiledHeaderUpdated(const QString &projectPartId, const QString &pchFilePath); void precompiledHeaderUpdated(const QString &projectPartId,
const QString &pchFilePath,
long long lastModified);
void attach(PchManagerNotifierInterface *notifier); void attach(PchManagerNotifierInterface *notifier);
void detach(PchManagerNotifierInterface *notifier); void detach(PchManagerNotifierInterface *notifier);

View File

@@ -40,7 +40,8 @@ public:
virtual ~PchManagerNotifierInterface(); virtual ~PchManagerNotifierInterface();
virtual void precompiledHeaderUpdated(const QString &projectPartId, virtual void precompiledHeaderUpdated(const QString &projectPartId,
const QString &pchFilePath) = 0; const QString &pchFilePath,
long long lastModified) = 0;
virtual void precompiledHeaderRemoved(const QString &projectPartId) = 0; virtual void precompiledHeaderRemoved(const QString &projectPartId) = 0;
PchManagerClient &m_pchManagerClient; PchManagerClient &m_pchManagerClient;

View File

@@ -33,6 +33,7 @@
#include <projectpartpch.h> #include <projectpartpch.h>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QDateTime>
#include <QFile> #include <QFile>
#include <QTemporaryFile> #include <QTemporaryFile>
@@ -545,6 +546,7 @@ Utils::SmallStringVector PchCreator::generateProjectPartClangCompilerArguments(
IdPaths PchCreator::generateProjectPartPch(const V2::ProjectPartContainer &projectPart) IdPaths PchCreator::generateProjectPartPch(const V2::ProjectPartContainer &projectPart)
{ {
long long lastModified = QDateTime::currentSecsSinceEpoch();
auto includes = generateProjectPartPchIncludes(projectPart); auto includes = generateProjectPartPchIncludes(projectPart);
auto content = generatePchIncludeFileContent(includes); auto content = generatePchIncludeFileContent(includes);
auto pchIncludeFilePath = generateProjectPathPchHeaderFilePath(projectPart); auto pchIncludeFilePath = generateProjectPathPchHeaderFilePath(projectPart);
@@ -552,7 +554,7 @@ IdPaths PchCreator::generateProjectPartPch(const V2::ProjectPartContainer &proje
generateFileWithContent(pchIncludeFilePath, content); generateFileWithContent(pchIncludeFilePath, content);
generatePch(generateProjectPartClangCompilerArguments(projectPart), generatePch(generateProjectPartClangCompilerArguments(projectPart),
{projectPart.projectPartId().clone(), std::move(pchFilePath)}); {projectPart.projectPartId().clone(), std::move(pchFilePath), lastModified});
return {projectPart.projectPartId().clone(), std::move(includes)}; return {projectPart.projectPartId().clone(), std::move(includes)};
} }

View File

@@ -592,8 +592,8 @@ std::ostream &operator<<(std::ostream &os, const ProjectPartContainer &container
std::ostream &operator<<(std::ostream &out, const ProjectPartPch &projectPartPch) std::ostream &operator<<(std::ostream &out, const ProjectPartPch &projectPartPch)
{ {
out << "(" out << "("
<< projectPartPch.id() << ", " << projectPartPch.projectPartId << ", "
<< projectPartPch.path() << ")"; << projectPartPch.pchPath << ")";
return out; return out;
} }

View File

@@ -36,8 +36,8 @@ public:
: ClangPchManager::PchManagerNotifierInterface(pchManagerClient) : ClangPchManager::PchManagerNotifierInterface(pchManagerClient)
{} {}
MOCK_METHOD2(precompiledHeaderUpdated, MOCK_METHOD3(precompiledHeaderUpdated,
void (const QString &projectPartId, const QString &pchFilePath)); void (const QString &projectPartId, const QString &pchFilePath, long long lastModified));
MOCK_METHOD1(precompiledHeaderRemoved, MOCK_METHOD1(precompiledHeaderRemoved,
void (const QString &projectPartId)); void (const QString &projectPartId));
}; };

View File

@@ -312,10 +312,10 @@ TEST_F(PchCreatorVerySlowTest, ProjectPartPchsForCreatePchsForProjectParts)
{ {
EXPECT_CALL(mockPchGeneratorNotifier, EXPECT_CALL(mockPchGeneratorNotifier,
taskFinished(ClangBackEnd::TaskFinishStatus::Successfully, taskFinished(ClangBackEnd::TaskFinishStatus::Successfully,
Property(&ProjectPartPch::id, "project1"))); Field(&ProjectPartPch::projectPartId, "project1")));
EXPECT_CALL(mockPchGeneratorNotifier, EXPECT_CALL(mockPchGeneratorNotifier,
taskFinished(ClangBackEnd::TaskFinishStatus::Successfully, taskFinished(ClangBackEnd::TaskFinishStatus::Successfully,
Property(&ProjectPartPch::id, "project2"))); Field(&ProjectPartPch::projectPartId, "project2")));
creator.generatePchs(); creator.generatePchs();
} }

View File

@@ -61,7 +61,7 @@ protected:
NiceMock<MockPchGeneratorNotifier> mockNotifier; NiceMock<MockPchGeneratorNotifier> mockNotifier;
ClangBackEnd::PchGenerator<FakeProcess> generator{environment, &mockNotifier}; ClangBackEnd::PchGenerator<FakeProcess> generator{environment, &mockNotifier};
Utils::SmallStringVector compilerArguments = {"-DXXXX", "-Ifoo"}; Utils::SmallStringVector compilerArguments = {"-DXXXX", "-Ifoo"};
ClangBackEnd::ProjectPartPch projectPartPch{"projectPartId", "/path/to/pch"}; ClangBackEnd::ProjectPartPch projectPartPch{"projectPartId", "/path/to/pch", 1};
}; };
TEST_F(PchGenerator, ProcessFinished) TEST_F(PchGenerator, ProcessFinished)

View File

@@ -57,7 +57,7 @@ protected:
ClangPchManager::PchManagerProjectUpdater projectUpdater{mockPchManagerServer, client, filePathCache}; ClangPchManager::PchManagerProjectUpdater projectUpdater{mockPchManagerServer, client, filePathCache};
Utils::SmallString projectPartId{"projectPartId"}; Utils::SmallString projectPartId{"projectPartId"};
Utils::SmallString pchFilePath{"/path/to/pch"}; Utils::SmallString pchFilePath{"/path/to/pch"};
PrecompiledHeadersUpdatedMessage message{{{projectPartId.clone(), pchFilePath.clone()}}}; PrecompiledHeadersUpdatedMessage message{{{projectPartId.clone(), pchFilePath.clone(), 1}}};
}; };
TEST_F(PchManagerClient, NotifierAttached) TEST_F(PchManagerClient, NotifierAttached)
@@ -81,7 +81,7 @@ TEST_F(PchManagerClient, NotifierDetached)
TEST_F(PchManagerClient, Update) TEST_F(PchManagerClient, Update)
{ {
EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderUpdated(projectPartId.toQString(), pchFilePath.toQString())); EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderUpdated(projectPartId.toQString(), pchFilePath.toQString(), Eq(1)));
client.precompiledHeadersUpdated(message.clone()); client.precompiledHeadersUpdated(message.clone());
} }

View File

@@ -119,7 +119,7 @@ TEST_F(PchManagerClientServerInProcess, SendRemovePchProjectPartsMessage)
TEST_F(PchManagerClientServerInProcess, SendPrecompiledHeaderUpdatedMessage) TEST_F(PchManagerClientServerInProcess, SendPrecompiledHeaderUpdatedMessage)
{ {
PrecompiledHeadersUpdatedMessage message{{{"projectPartId", "/path/to/pch"}}}; PrecompiledHeadersUpdatedMessage message{{{"projectPartId", "/path/to/pch", 1}}};
EXPECT_CALL(mockPchManagerClient, precompiledHeadersUpdated(message)); EXPECT_CALL(mockPchManagerClient, precompiledHeadersUpdated(message));

View File

@@ -84,8 +84,8 @@ protected:
FileContainer generatedFile{{"/path/to/", "file"}, "content", {}}; FileContainer generatedFile{{"/path/to/", "file"}, "content", {}};
ClangBackEnd::UpdatePchProjectPartsMessage updatePchProjectPartsMessage{Utils::clone(projectParts), ClangBackEnd::UpdatePchProjectPartsMessage updatePchProjectPartsMessage{Utils::clone(projectParts),
{generatedFile}}; {generatedFile}};
ClangBackEnd::ProjectPartPch projectPartPch1{projectPart1.projectPartId().clone(), "/path1/to/pch"}; ClangBackEnd::ProjectPartPch projectPartPch1{projectPart1.projectPartId().clone(), "/path1/to/pch", 1};
ClangBackEnd::ProjectPartPch projectPartPch2{projectPart2.projectPartId().clone(), "/path2/to/pch"}; ClangBackEnd::ProjectPartPch projectPartPch2{projectPart2.projectPartId().clone(), "/path2/to/pch", 1};
std::vector<ClangBackEnd::ProjectPartPch> projectPartPchs{projectPartPch1, projectPartPch2}; std::vector<ClangBackEnd::ProjectPartPch> projectPartPchs{projectPartPch1, projectPartPch2};
ClangBackEnd::PrecompiledHeadersUpdatedMessage precompiledHeaderUpdatedMessage1{{projectPartPch1}}; ClangBackEnd::PrecompiledHeadersUpdatedMessage precompiledHeaderUpdatedMessage1{{projectPartPch1}};
ClangBackEnd::PrecompiledHeadersUpdatedMessage precompiledHeaderUpdatedMessage2{{projectPartPch2}}; ClangBackEnd::PrecompiledHeadersUpdatedMessage precompiledHeaderUpdatedMessage2{{projectPartPch2}};