2018-02-20 12:43:05 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2017 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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 The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-04-10 19:24:36 +02:00
|
|
|
#include "pchpaths.h"
|
2018-02-20 12:43:05 +01:00
|
|
|
#include "precompiledheaderstorageinterface.h"
|
|
|
|
|
|
|
|
|
|
#include <sqlitetransaction.h>
|
2018-03-28 16:25:01 +02:00
|
|
|
#include <sqliteexception.h>
|
2018-02-20 12:43:05 +01:00
|
|
|
|
|
|
|
|
#include <utils/smallstringview.h>
|
|
|
|
|
|
2018-09-11 17:02:45 +02:00
|
|
|
namespace ClangBackEnd {
|
2018-02-20 12:43:05 +01:00
|
|
|
|
|
|
|
|
template<typename Database=Sqlite::Database>
|
|
|
|
|
class PrecompiledHeaderStorage final : public PrecompiledHeaderStorageInterface
|
|
|
|
|
{
|
|
|
|
|
using ReadStatement = typename Database::ReadStatement;
|
|
|
|
|
using WriteStatement = typename Database::WriteStatement;
|
|
|
|
|
public:
|
|
|
|
|
PrecompiledHeaderStorage(Database &database)
|
2019-03-13 15:09:30 +01:00
|
|
|
: transaction(database)
|
|
|
|
|
, database(database)
|
2018-02-20 12:43:05 +01:00
|
|
|
{
|
2019-03-13 15:09:30 +01:00
|
|
|
transaction.commit();
|
2018-02-20 12:43:05 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-13 15:09:30 +01:00
|
|
|
void insertProjectPrecompiledHeader(ProjectPartId projectPartId,
|
2018-12-17 12:06:57 +01:00
|
|
|
Utils::SmallStringView pchPath,
|
2019-07-25 13:34:07 +02:00
|
|
|
TimeStamp pchBuildTime) override
|
2018-02-20 12:43:05 +01:00
|
|
|
{
|
2018-03-28 16:25:01 +02:00
|
|
|
try {
|
2019-03-13 15:09:30 +01:00
|
|
|
Sqlite::ImmediateTransaction transaction{database};
|
2018-03-28 16:25:01 +02:00
|
|
|
|
2019-03-13 15:09:30 +01:00
|
|
|
insertProjectPrecompiledHeaderStatement.write(projectPartId.projectPathId,
|
|
|
|
|
pchPath,
|
2019-07-25 13:34:07 +02:00
|
|
|
pchBuildTime.value);
|
2018-03-28 16:25:01 +02:00
|
|
|
|
|
|
|
|
transaction.commit();
|
2019-03-13 15:09:30 +01:00
|
|
|
} catch (const Sqlite::StatementIsBusy &) {
|
|
|
|
|
insertProjectPrecompiledHeader(projectPartId, pchPath, pchBuildTime);
|
2018-03-28 16:25:01 +02:00
|
|
|
}
|
2018-02-20 12:43:05 +01:00
|
|
|
}
|
|
|
|
|
|
2019-07-25 13:34:07 +02:00
|
|
|
void deleteProjectPrecompiledHeader(ProjectPartId projectPartId, TimeStamp pchBuildTime) override
|
2018-02-20 12:43:05 +01:00
|
|
|
{
|
2018-03-28 16:25:01 +02:00
|
|
|
try {
|
2019-03-13 15:09:30 +01:00
|
|
|
Sqlite::ImmediateTransaction transaction{database};
|
2018-03-28 16:25:01 +02:00
|
|
|
|
2019-07-24 16:23:08 +02:00
|
|
|
deleteProjectPrecompiledHeaderPathAndSetBuildTimeStatement.write(projectPartId.projectPathId,
|
2019-07-25 13:34:07 +02:00
|
|
|
pchBuildTime.value);
|
2018-03-28 16:25:01 +02:00
|
|
|
|
|
|
|
|
transaction.commit();
|
|
|
|
|
} catch (const Sqlite::StatementIsBusy) {
|
2019-07-24 16:23:08 +02:00
|
|
|
deleteProjectPrecompiledHeader(projectPartId, pchBuildTime);
|
2018-03-28 16:25:01 +02:00
|
|
|
}
|
2018-02-20 12:43:05 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-19 17:00:03 +01:00
|
|
|
void deleteProjectPrecompiledHeaders(const ProjectPartIds &projectPartIds) override
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
Sqlite::ImmediateTransaction transaction{database};
|
|
|
|
|
|
|
|
|
|
for (ProjectPartId projectPartId : projectPartIds)
|
|
|
|
|
deleteProjectPrecompiledHeaderStatement.write(projectPartId.projectPathId);
|
|
|
|
|
|
|
|
|
|
transaction.commit();
|
|
|
|
|
} catch (const Sqlite::StatementIsBusy) {
|
|
|
|
|
deleteProjectPrecompiledHeaders(projectPartIds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 15:09:30 +01:00
|
|
|
void insertSystemPrecompiledHeaders(const ProjectPartIds &projectPartIds,
|
2018-12-17 12:06:57 +01:00
|
|
|
Utils::SmallStringView pchPath,
|
2019-07-25 13:34:07 +02:00
|
|
|
TimeStamp pchBuildTime) override
|
2018-12-04 19:03:48 +01:00
|
|
|
{
|
|
|
|
|
try {
|
2019-03-13 15:09:30 +01:00
|
|
|
Sqlite::ImmediateTransaction transaction{database};
|
2018-12-04 19:03:48 +01:00
|
|
|
|
2019-03-13 15:09:30 +01:00
|
|
|
for (ProjectPartId projectPartId : projectPartIds) {
|
|
|
|
|
insertSystemPrecompiledHeaderStatement.write(projectPartId.projectPathId,
|
|
|
|
|
pchPath,
|
2019-07-25 13:34:07 +02:00
|
|
|
pchBuildTime.value);
|
2018-12-17 12:06:57 +01:00
|
|
|
}
|
2018-12-04 19:03:48 +01:00
|
|
|
transaction.commit();
|
|
|
|
|
} catch (const Sqlite::StatementIsBusy) {
|
2019-03-13 15:09:30 +01:00
|
|
|
insertSystemPrecompiledHeaders(projectPartIds, pchPath, pchBuildTime);
|
2018-12-04 19:03:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 15:09:30 +01:00
|
|
|
void deleteSystemPrecompiledHeaders(const ProjectPartIds &projectPartIds) override
|
2018-12-04 19:03:48 +01:00
|
|
|
{
|
|
|
|
|
try {
|
2019-03-13 15:09:30 +01:00
|
|
|
Sqlite::ImmediateTransaction transaction{database};
|
2018-12-04 19:03:48 +01:00
|
|
|
|
2019-03-13 15:09:30 +01:00
|
|
|
for (ProjectPartId projectPartId : projectPartIds)
|
|
|
|
|
deleteSystemPrecompiledHeaderStatement.write(projectPartId.projectPathId);
|
2018-12-04 19:03:48 +01:00
|
|
|
|
|
|
|
|
transaction.commit();
|
|
|
|
|
} catch (const Sqlite::StatementIsBusy) {
|
2019-03-13 15:09:30 +01:00
|
|
|
deleteSystemPrecompiledHeaders(projectPartIds);
|
2018-12-04 19:03:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 15:09:30 +01:00
|
|
|
FilePath fetchSystemPrecompiledHeaderPath(ProjectPartId projectPartId) override
|
2018-12-04 19:03:48 +01:00
|
|
|
{
|
|
|
|
|
try {
|
2019-03-13 15:09:30 +01:00
|
|
|
Sqlite::DeferredTransaction transaction{database};
|
2018-12-04 19:03:48 +01:00
|
|
|
|
2019-03-13 15:09:30 +01:00
|
|
|
auto value = fetchSystemPrecompiledHeaderPathStatement.template value<FilePath>(
|
|
|
|
|
projectPartId.projectPathId);
|
2018-12-04 19:03:48 +01:00
|
|
|
|
|
|
|
|
if (value)
|
2019-03-13 15:09:30 +01:00
|
|
|
return *value;
|
2018-12-04 19:03:48 +01:00
|
|
|
|
|
|
|
|
transaction.commit();
|
|
|
|
|
} catch (const Sqlite::StatementIsBusy) {
|
2019-03-13 15:09:30 +01:00
|
|
|
return fetchSystemPrecompiledHeaderPath(projectPartId);
|
2018-12-04 19:03:48 +01:00
|
|
|
}
|
|
|
|
|
|
2018-12-17 12:06:57 +01:00
|
|
|
return FilePath("");
|
2018-12-04 19:03:48 +01:00
|
|
|
}
|
2018-02-20 12:43:05 +01:00
|
|
|
|
2019-05-10 11:51:43 +02:00
|
|
|
FilePath fetchPrecompiledHeader(ProjectPartId projectPartId) const override
|
2019-02-22 16:44:40 +01:00
|
|
|
{
|
2019-04-10 18:21:22 +02:00
|
|
|
try {
|
|
|
|
|
Sqlite::DeferredTransaction transaction{database};
|
|
|
|
|
|
2019-04-10 19:24:36 +02:00
|
|
|
auto value = fetchPrecompiledHeaderStatement.template value<FilePath>(
|
|
|
|
|
projectPartId.projectPathId);
|
2019-04-10 17:44:34 +02:00
|
|
|
|
2019-04-10 18:21:22 +02:00
|
|
|
if (value)
|
|
|
|
|
return *value;
|
|
|
|
|
|
|
|
|
|
transaction.commit();
|
|
|
|
|
} catch (const Sqlite::StatementIsBusy) {
|
|
|
|
|
return fetchPrecompiledHeader(projectPartId);
|
|
|
|
|
}
|
2019-04-10 17:44:34 +02:00
|
|
|
|
|
|
|
|
return FilePath("");
|
2019-02-22 16:44:40 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-10 11:51:43 +02:00
|
|
|
PchPaths fetchPrecompiledHeaders(ProjectPartId projectPartId) const override
|
2019-04-10 19:24:36 +02:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
Sqlite::DeferredTransaction transaction{database};
|
|
|
|
|
|
|
|
|
|
auto value = fetchPrecompiledHeadersStatement.template value<PchPaths, 2>(
|
|
|
|
|
projectPartId.projectPathId);
|
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
return *value;
|
|
|
|
|
|
|
|
|
|
transaction.commit();
|
|
|
|
|
} catch (const Sqlite::StatementIsBusy) {
|
|
|
|
|
return fetchPrecompiledHeaders(projectPartId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
public:
|
2019-03-13 15:09:30 +01:00
|
|
|
Sqlite::ImmediateNonThrowingDestructorTransaction transaction;
|
|
|
|
|
Database &database;
|
|
|
|
|
WriteStatement insertProjectPrecompiledHeaderStatement{
|
2018-12-04 19:03:48 +01:00
|
|
|
"INSERT INTO precompiledHeaders(projectPartId, projectPchPath, projectPchBuildTime) "
|
2019-03-19 17:00:03 +01:00
|
|
|
"VALUES(?001,?002,?003) "
|
2018-12-04 19:03:48 +01:00
|
|
|
"ON CONFLICT (projectPartId) DO UPDATE SET projectPchPath=?002,projectPchBuildTime=?003",
|
2019-03-13 15:09:30 +01:00
|
|
|
database};
|
|
|
|
|
WriteStatement insertSystemPrecompiledHeaderStatement{
|
2018-12-04 19:03:48 +01:00
|
|
|
"INSERT INTO precompiledHeaders(projectPartId, systemPchPath, systemPchBuildTime) "
|
2019-03-13 15:09:30 +01:00
|
|
|
"VALUES(?001,?002,?003) "
|
2018-12-04 19:03:48 +01:00
|
|
|
"ON CONFLICT (projectPartId) DO UPDATE SET systemPchPath=?002,systemPchBuildTime=?003",
|
2019-03-13 15:09:30 +01:00
|
|
|
database};
|
|
|
|
|
WriteStatement deleteProjectPrecompiledHeaderStatement{
|
2018-12-04 19:03:48 +01:00
|
|
|
"UPDATE OR IGNORE precompiledHeaders SET projectPchPath=NULL,projectPchBuildTime=NULL "
|
2019-03-13 15:09:30 +01:00
|
|
|
"WHERE projectPartId = ?",
|
|
|
|
|
database};
|
2019-07-24 16:23:08 +02:00
|
|
|
WriteStatement deleteProjectPrecompiledHeaderPathAndSetBuildTimeStatement{
|
|
|
|
|
"UPDATE OR IGNORE precompiledHeaders SET projectPchPath=NULL,projectPchBuildTime=?002 "
|
|
|
|
|
"WHERE projectPartId = ?001",
|
|
|
|
|
database};
|
2019-03-13 15:09:30 +01:00
|
|
|
WriteStatement deleteSystemPrecompiledHeaderStatement{
|
2018-12-04 19:03:48 +01:00
|
|
|
"UPDATE OR IGNORE precompiledHeaders SET systemPchPath=NULL,systemPchBuildTime=NULL "
|
2019-03-13 15:09:30 +01:00
|
|
|
"WHERE projectPartId = ?",
|
|
|
|
|
database};
|
|
|
|
|
ReadStatement fetchSystemPrecompiledHeaderPathStatement{
|
|
|
|
|
"SELECT systemPchPath FROM precompiledHeaders WHERE projectPartId = ?", database};
|
2019-04-10 19:24:36 +02:00
|
|
|
mutable ReadStatement fetchPrecompiledHeaderStatement{
|
2019-04-10 17:44:34 +02:00
|
|
|
"SELECT ifnull(nullif(projectPchPath, ''), systemPchPath) "
|
|
|
|
|
"FROM precompiledHeaders WHERE projectPartId = ?",
|
2019-03-13 15:09:30 +01:00
|
|
|
database};
|
2019-04-10 19:24:36 +02:00
|
|
|
mutable ReadStatement fetchPrecompiledHeadersStatement{
|
|
|
|
|
"SELECT projectPchPath, systemPchPath FROM precompiledHeaders WHERE projectPartId = ?",
|
|
|
|
|
database};
|
2018-02-20 12:43:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|