1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/*
* KDevelop C++ Language Support
*
* Copyright 2007 David Nolden <david.nolden.kdevelop@art-master.de>
* Copyright 2014 Kevin Funk <kfunk@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef MAKEFILERESOLVER_H
#define MAKEFILERESOLVER_H
#include <QString>
#include <language/editor/modificationrevisionset.h>
#include <util/path.h>
struct PathResolutionResult
{
explicit PathResolutionResult(bool success = false, const QString& errorMessage = QString(), const QString& longErrorMessage = QString());
bool success;
QString errorMessage;
QString longErrorMessage;
KDevelop::ModificationRevisionSet includePathDependency;
KDevelop::Path::List paths;
// the list of framework directories specified with explicit -iframework and/or -F arguments.
// Mainly for OS X, but available everywhere to avoid #ifdefs and
// because clang is an out-of-the-box cross-compiler.
KDevelop::Path::List frameworkDirectories;
QHash<QString, QString> defines;
void mergeWith(const PathResolutionResult& rhs);
operator bool() const;
};
class SourcePathInformation;
// reuse cached instances of strings, to share memory where possible
class StringInterner
{
public:
QString internString(const QString& string);
private:
QSet<QString> m_stringCache;
};
// reuse cached instances of paths, to share memory where possible
class PathInterner
{
public:
PathInterner(const KDevelop::Path& base = {});
KDevelop::Path internPath(const QString& path);
private:
const KDevelop::Path m_base;
QHash<QString, KDevelop::Path> m_pathCache;
};
///One resolution-try can issue up to 4 make-calls in worst case
class MakeFileResolver
{
public:
MakeFileResolver();
///Same as below, but uses the directory of the file as working-directory. The argument must be absolute.
PathResolutionResult resolveIncludePath( const QString& file );
///The include-path is only computed once for a whole directory, then it is cached using the modification-time of the Makefile.
///source and build must be absolute paths
void setOutOfSourceBuildSystem( const QString& source, const QString& build );
///resets to in-source build system
void resetOutOfSourceBuild();
static void clearCache();
KDevelop::ModificationRevisionSet findIncludePathDependency(const QString& file);
void enableMakeResolution(bool enable);
PathResolutionResult processOutput(const QString& fullOutput, const QString& workingDirectory) const;
static QRegularExpression defineRegularExpression();
static QHash<QString, QString> extractDefinesFromCompileFlags(const QString& compileFlags, StringInterner& stringInterner, QHash<QString, QString> defines);
private:
PathResolutionResult resolveIncludePath( const QString& file, const QString& workingDirectory, int maxStepsUp = 20 );
bool m_isResolving = false;
bool m_outOfSource = false;
QString mapToBuild(const QString &path) const;
///Executes the command using KProcess
bool executeCommand( const QString& command, const QString& workingDirectory, QString& result ) const;
///file should be the name of the target, without extension(because that may be different)
PathResolutionResult resolveIncludePathInternal( const QString& file, const QString& workingDirectory,
const QString& makeParameters, const SourcePathInformation& source, int maxDepth );
QString m_source;
QString m_build;
mutable StringInterner m_stringInterner;
mutable PathInterner m_pathInterner;
};
#endif
|