[kdevelop] languages/cpp: Do not guess include paths when we any where returned by the manager.
Milian Wolff
mail at milianw.de
Tue Dec 17 13:51:48 UTC 2013
Git commit adb36605967c345e69c63ed63686e47bd01be53e by Milian Wolff.
Committed on 17/12/2013 at 13:47.
Pushed by mwolff into branch 'master'.
Do not guess include paths when we any where returned by the manager.
The IncludePathComputer was run quite frequently and is very costly.
Especially for cmake projects, the build manager does a good job at
finding the include paths already.
Thus the up to 16s (for my KDev* session) spent in running make and
interpreting its result can be saved when we instead rely on the
result given by the builder.
If you suddenly encounter issues with include paths that used to work,
please report that on bugs.kde.org.
CCMAIL: kdevelop-devel at kde.org
M +25 -50 languages/cpp/includepathcomputer.cpp
M +4 -7 languages/cpp/tests/test_cppcodegen.cpp
M +0 -4 languages/cpp/tests/test_specialcompletion.cpp
http://commits.kde.org/kdevelop/adb36605967c345e69c63ed63686e47bd01be53e
diff --git a/languages/cpp/includepathcomputer.cpp b/languages/cpp/includepathcomputer.cpp
index cc26784..de40bca 100644
--- a/languages/cpp/includepathcomputer.cpp
+++ b/languages/cpp/includepathcomputer.cpp
@@ -97,7 +97,7 @@ void IncludePathComputer::computeForeground() {
m_defines = buildManager->defines(file);
- m_gotPathsFromManager = true;
+ m_gotPathsFromManager = !dirs.isEmpty();
kDebug(9007) << "Got " << dirs.count() << " include-paths from build-manager";
@@ -110,7 +110,7 @@ void IncludePathComputer::computeForeground() {
}
if(!m_gotPathsFromManager)
- kDebug(9007) << "Did not find a build-manager for" << m_source;
+ kDebug(9007) << "Did not find any include paths from project manager for" << m_source;
}
@@ -119,11 +119,24 @@ void IncludePathComputer::computeBackground() {
if(m_ready)
return;
+ const QList<QString>& standardPaths = CppUtils::standardIncludePaths();
+
+ //Insert standard-paths
+ foreach( const QString& path, standardPaths) {
+ KUrl u(path);
+ if(!m_hasPath.contains(u))
+ m_ret << KUrl(path);
+ m_hasPath.insert(u);
+ }
+
+ if (m_gotPathsFromManager) {
+ // return early and trust the include paths returned by the project manager
+ return;
+ }
+
if(!m_effectiveBuildDirectory.isEmpty())
m_includeResolver.setOutOfSourceBuildSystem(m_projectDirectory.toLocalFile(), m_effectiveBuildDirectory.toLocalFile());
-
- QList<QString> standardPaths = CppUtils::standardIncludePaths();
-
+
m_includePathDependency = m_includeResolver.findIncludePathDependency(m_source.toLocalFile());
kDebug() << "current include path dependency state:" << m_includePathDependency.toString();
@@ -189,45 +202,15 @@ void IncludePathComputer::computeBackground() {
CppTools::PathResolutionResult result = m_includeResolver.resolveIncludePath(m_source.toLocalFile());
m_includePathDependency = result.includePathDependency;
kDebug() << "new include path dependency:" << m_includePathDependency.toString();
-
-// if (result) {
- bool hadMissingPath = false;
- if( !m_gotPathsFromManager ) {
- foreach( const QString &res, result.paths ) {
- KUrl r(res);
- r.adjustPath(KUrl::AddTrailingSlash);
- if(!m_hasPath.contains(r))
- m_ret << r;
- m_hasPath.insert(r);
- }
- } else {
- //Compare the includes found by the includepathresolver to the ones returned by the project-manager, and complain eaach missing path.
- foreach( const QString& res, result.paths ) {
- KUrl r(res);
- r.adjustPath(KUrl::AddTrailingSlash);
-
- KUrl r2(res);
- r2.adjustPath(KUrl::RemoveTrailingSlash);
-
- if( !m_hasPath.contains(r) && !m_hasPath.contains(r2) ) {
- hadMissingPath = true;
- if(!m_hasPath.contains(r))
- m_ret << r;
- m_hasPath.insert(r);
-
- kDebug(9007) << "Include-path was missing in list returned by build-manager, adding it now. file was:" << m_source << "missing path:" << r.pathOrUrl();
- }
- }
-
- if( hadMissingPath ) {
- QString paths;
- foreach( const KUrl& u, m_ret )
- paths += u.pathOrUrl() + "\n";
+ foreach( const QString &res, result.paths ) {
+ KUrl r(res);
+ r.adjustPath(KUrl::AddTrailingSlash);
+ if(!m_hasPath.contains(r))
+ m_ret << r;
+ m_hasPath.insert(r);
+ }
- kDebug(9007) << "Total list of include-paths:\n" << paths << "\nEnd of list";
- }
- }
if(!result) {
kDebug(9007) << "Failed to resolve include-path for \"" << m_source << "\":" << result.errorMessage << "\n" << result.longErrorMessage << "\n";
problem->setSource(KDevelop::ProblemData::Preprocessor);
@@ -259,13 +242,5 @@ void IncludePathComputer::computeBackground() {
}
}
- //Insert the standard-paths at the end
- foreach( const QString& path, standardPaths) {
- KUrl u(path);
- if(!m_hasPath.contains(u))
- m_ret << KUrl(path);
- m_hasPath.insert(u);
- }
-
m_ready = true;
}
diff --git a/languages/cpp/tests/test_cppcodegen.cpp b/languages/cpp/tests/test_cppcodegen.cpp
index 5075b72..a4caf05 100644
--- a/languages/cpp/tests/test_cppcodegen.cpp
+++ b/languages/cpp/tests/test_cppcodegen.cpp
@@ -116,13 +116,10 @@ void TestCppCodegen::testAssistants()
DUChainReadLocker lock;
- // There is one problem from the include-path resolver as it couldn't
- // resolve include paths for the artificial code
- // The second problem is the missing-declaration assistant problem
- QCOMPARE(code->problems().size(), 2);
- QVERIFY(code->problems()[1]->solutionAssistant());
- QCOMPARE(code->problems()[1]->solutionAssistant()->actions().size(), numAssistants);
- code->problems()[1]->solutionAssistant()->actions()[executeAssistant]->execute();
+ QCOMPARE(code->problems().size(), 1);
+ QVERIFY(code->problems().first()->solutionAssistant());
+ QCOMPARE(code->problems().first()->solutionAssistant()->actions().size(), numAssistants);
+ code->problems().first()->solutionAssistant()->actions()[executeAssistant]->execute();
//Make sure the assistant has inserted the correct solution
QVERIFY(code.m_insertedCode.text().contains(insertionText));
diff --git a/languages/cpp/tests/test_specialcompletion.cpp b/languages/cpp/tests/test_specialcompletion.cpp
index 5db1bb3..76c85aa 100644
--- a/languages/cpp/tests/test_specialcompletion.cpp
+++ b/languages/cpp/tests/test_specialcompletion.cpp
@@ -95,7 +95,6 @@ void TestSpecialCompletion::testMissingInclude()
QVERIFY(include.topContext());
TopDUContext* includeTop = DUChainUtils::contentContextFromProxyContext(include.topContext().data());
QVERIFY(includeTop);
- QEXPECT_FAIL("", "include path resolver complains", Continue);
QVERIFY(includeTop->problems().isEmpty());
QCOMPARE(includeTop->localDeclarations().size(), 1);
QCOMPARE(includeTop->childContexts().size(), 1);
@@ -103,7 +102,6 @@ void TestSpecialCompletion::testMissingInclude()
QVERIFY(workingFile.topContext());
TopDUContext* top = DUChainUtils::contentContextFromProxyContext(workingFile.topContext());
QVERIFY(top);
- QEXPECT_FAIL("", "include path resolver complains", Continue);
QVERIFY(top->problems().isEmpty());
QCOMPARE(top->childContexts().size(), 2);
@@ -141,7 +139,6 @@ void TestSpecialCompletion::testIncludeDefine()
QVERIFY(include.topContext());
TopDUContext* includeTop = DUChainUtils::contentContextFromProxyContext(include.topContext().data());
QVERIFY(includeTop);
- QEXPECT_FAIL("", "include path resolver complains", Continue);
QVERIFY(includeTop->problems().isEmpty());
QCOMPARE(includeTop->localDeclarations().size(), 1);
QCOMPARE(includeTop->childContexts().size(), 1);
@@ -283,7 +280,6 @@ void TestSpecialCompletion::testIncludeComment()
QVERIFY(include.topContext());
TopDUContext* includeTop = DUChainUtils::contentContextFromProxyContext(include.topContext().data());
QVERIFY(includeTop);
- QEXPECT_FAIL("", "include path resolver complains", Continue);
QVERIFY(includeTop->problems().isEmpty());
QCOMPARE(includeTop->localDeclarations().size(), 1);
QCOMPARE(includeTop->childContexts().size(), 1);
More information about the KDevelop-devel
mailing list