Commit ad7ea392 authored by Ben Wagner's avatar Ben Wagner Committed by Aaron Puchert
Browse files

Add working directory to clang parser.

Summary:
This sets the working directory of the clang parser similarly to the way
the build directory is passed to the builder. This allows the parser to
correctly resolve any relative paths in the extra build arguments. This
means relative paths are resolved relative to the build directory (as
they would be resolved by a builder).

Test Plan: In the current test setup it doesn't seem the TestProject allows a TestBuildSystemManager, so it seems like quite a bit of work to create a test for this. (As a result I assume IBuildSystemManager integration isn't well tested in general right now.) If this needs a test, let me know if adding a TestBuildSystemManager is the right way to go.

Reviewers: #kdevelop, aaronpuchert

Reviewed By: aaronpuchert

Subscribers: aaronpuchert, kdevelop-devel

Tags: #kdevelop

Differential Revision: https://phabricator.kde.org/D22197
parent 5f9fcc13
......@@ -172,6 +172,10 @@ ClangParseJob::ClangParseJob(const IndexedString& url, ILanguageSupport* languag
m_environment.addFrameworkDirectories(IDefinesAndIncludesManager::manager()->frameworkDirectories(file));
m_environment.addDefines(IDefinesAndIncludesManager::manager()->defines(file));
m_environment.setParserSettings(ClangSettingsManager::self()->parserSettings(file));
if (hasBuildSystemInfo) {
// Assume the builder invokes the compiler in the build directory.
m_environment.setWorkingDirectory(file->project()->buildSystemManager()->buildDirectory(file));
}
} else {
m_environment.addIncludes(IDefinesAndIncludesManager::manager()->includes(tuUrl.str()));
m_environment.addFrameworkDirectories(IDefinesAndIncludesManager::manager()->frameworkDirectories(tuUrl.str()));
......
......@@ -103,6 +103,16 @@ Path ClangParsingEnvironment::pchInclude() const
return m_pchInclude;
}
void ClangParsingEnvironment::setWorkingDirectory(const Path& path)
{
m_workingDirectory = path;
}
Path ClangParsingEnvironment::workingDirectory() const
{
return m_workingDirectory;
}
void ClangParsingEnvironment::setTranslationUnitUrl(const IndexedString& url)
{
m_tuUrl = url;
......
......@@ -84,6 +84,9 @@ public:
void setPchInclude(const KDevelop::Path& path);
KDevelop::Path pchInclude() const;
void setWorkingDirectory(const KDevelop::Path& path);
KDevelop::Path workingDirectory() const;
void setTranslationUnitUrl(const KDevelop::IndexedString& url);
KDevelop::IndexedString translationUnitUrl() const;
......@@ -123,6 +126,7 @@ private:
// NOTE: As elements in QHash stored in an unordered sequence, we're using QMap instead
QMap<QString, QString> m_defines;
KDevelop::Path m_pchInclude;
KDevelop::Path m_workingDirectory;
KDevelop::IndexedString m_tuUrl;
Quality m_quality = Unknown;
ParserSettings m_parserSettings;
......
......@@ -283,6 +283,13 @@ ParseSessionData::ParseSessionData(const QVector<UnsavedFile>& unsavedFiles, Cla
smartArgs << writeDefinesFile(environment.defines());
clangArguments << "-imacros" << smartArgs.last().constData();
if (!environment.workingDirectory().isEmpty()) {
QByteArray workingDirectory = environment.workingDirectory().toLocalFile().toUtf8();
workingDirectory.prepend("-working-directory");
smartArgs << workingDirectory;
clangArguments << workingDirectory.constData();
}
// append extra args from environment variable
static const auto extraArgs = ::extraArgs();
for (const QByteArray& arg : extraArgs) {
......
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