Commit d8119c13 authored by Milian Wolff's avatar Milian Wolff

Simplify setting custom parser args for unit tests

Make it possible to add parser args from a background provider and
share the test provider implementation.
parent bbb42a2f
......@@ -237,6 +237,7 @@ void ClangParseJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread*
m_environment.addIncludes(IDefinesAndIncludesManager::manager()->includesInBackground(tuUrlStr));
m_environment.addFrameworkDirectories(IDefinesAndIncludesManager::manager()->frameworkDirectoriesInBackground(tuUrlStr));
m_environment.addDefines(IDefinesAndIncludesManager::manager()->definesInBackground(tuUrlStr));
m_environment.addParserArguments(IDefinesAndIncludesManager::manager()->parserArgumentsInBackground(tuUrlStr));
m_environment.setPchInclude(userDefinedPchIncludeForFile(tuUrlStr));
}
......
......@@ -167,3 +167,9 @@ ParserSettings ClangParsingEnvironment::parserSettings() const
{
return m_parserSettings;
}
void ClangParsingEnvironment::addParserArguments(const QString& parserArguments)
{
m_parserSettings.parserOptions += QLatin1Char(' ') + parserArguments;
}
......@@ -100,6 +100,7 @@ public:
void setParserSettings(const ParserSettings& arguments);
ParserSettings parserSettings() const;
void addParserArguments(const QString &parserArguments);
/**
* Hash all contents of this environment and return the result.
......
......@@ -99,6 +99,7 @@ LINK_LIBRARIES
Qt5::Core
KDev::Language
KDev::Tests
KDev::DefinesAndIncludesManager
)
if(NOT COMPILER_OPTIMIZATIONS_DISABLED)
......
......@@ -52,7 +52,7 @@
#include "duchain/clangparsingenvironment.h"
#include "duchain/parsesession.h"
#include <custom-definesandincludes/idefinesandincludesmanager.h>
#include "testprovider.h"
#include <KConfigGroup>
......@@ -65,34 +65,6 @@ QTEST_MAIN(TestDUChain)
using namespace KDevelop;
class TestEnvironmentProvider final : public IDefinesAndIncludesManager::BackgroundProvider
{
public:
~TestEnvironmentProvider() override = default;
QHash< QString, QString > definesInBackground(const QString& /*path*/) const override
{
return defines;
}
Path::List includesInBackground(const QString& /*path*/) const override
{
return includes;
}
Path::List frameworkDirectoriesInBackground(const QString&) const override
{
return {};
}
IDefinesAndIncludesManager::Type type() const override
{
return IDefinesAndIncludesManager::UserDefined;
}
QHash<QString, QString> defines;
Path::List includes;
};
TestDUChain::~TestDUChain() = default;
void TestDUChain::initTestCase()
......
#ifndef KDEV_CLANG_TEST_PROVIDER_H
#define KDEV_CLANG_TEST_PROVIDER_H
#include <custom-definesandincludes/idefinesandincludesmanager.h>
#include <QHash>
class TestEnvironmentProvider final : public KDevelop::IDefinesAndIncludesManager::BackgroundProvider
{
public:
~TestEnvironmentProvider() override = default;
QHash<QString, QString> definesInBackground(const QString& /*path*/) const override
{
return defines;
}
KDevelop::Path::List includesInBackground(const QString& /*path*/) const override
{
return includes;
}
KDevelop::Path::List frameworkDirectoriesInBackground(const QString&) const override
{
return {};
}
KDevelop::IDefinesAndIncludesManager::Type type() const override
{
return KDevelop::IDefinesAndIncludesManager::UserDefined;
}
QString parserArgumentsInBackground(const QString&) const override
{
return parserArguments;
}
void clear()
{
defines.clear();
includes.clear();
parserArguments.clear();
}
QHash<QString, QString> defines;
KDevelop::Path::List includes;
QString parserArguments;
};
#endif // KDEV_CLANG_TEST_PROVIDER_H
......@@ -374,6 +374,16 @@ QString DefinesAndIncludesManager::parserArguments(const QString& path) const
return argumentsForPath(path, args);
}
QString DefinesAndIncludesManager::parserArgumentsInBackground(const QString& path) const
{
QString ret;
for (auto provider: m_backgroundProviders) {
ret += provider->parserArgumentsInBackground(path) + QLatin1Char(' ');
}
return ret;
}
int DefinesAndIncludesManager::perProjectConfigPages() const
{
return 1;
......
......@@ -68,6 +68,7 @@ public:
QString parserArguments(KDevelop::ProjectBaseItem* item) const override;
QString parserArguments(const QString& path) const override;
QString parserArgumentsInBackground(const QString& path) const override;
void openConfigurationDialog( const QString& pathToFile ) override;
int perProjectConfigPages() const override;
......
......@@ -96,6 +96,8 @@ public:
virtual Defines definesInBackground( const QString& path ) const = 0;
virtual QString parserArgumentsInBackground(const QString& path) const = 0;
/// @return the type of i/d this provider provides
virtual Type type() const = 0;
};
......@@ -168,6 +170,7 @@ public:
virtual QString parserArguments(ProjectBaseItem* item) const = 0;
virtual QString parserArguments(const QString& path) const = 0;
virtual QString parserArgumentsInBackground(const QString& path) const = 0;
///@return the instance of the plugin.
inline static IDefinesAndIncludesManager* manager();
......
......@@ -84,6 +84,11 @@ public:
return resolvePathInBackground(path, true);
}
QString parserArgumentsInBackground(const QString& /*path*/) const override
{
return {};
}
IDefinesAndIncludesManager::Type type() const override
{
return IDefinesAndIncludesManager::ProjectSpecific;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment