makefileresolver.h 3.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
* 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.
*/
Kris Wong's avatar
Kris Wong committed
22
23
24
25
26
27

#ifndef INCLUDEPATHRESOLVER_H
#define INCLUDEPATHRESOLVER_H

#include <QString>

28
#include <language/editor/modificationrevisionset.h>
29

30
#include <util/path.h>
Milian Wolff's avatar
Milian Wolff committed
31
32
33

struct PathResolutionResult
{
34
35
  PathResolutionResult(bool success = false, const QString& errorMessage = QString(), const QString& longErrorMessage = QString());

Milian Wolff's avatar
Milian Wolff committed
36
37
38
39
40
41
  bool success;
  QString errorMessage;
  QString longErrorMessage;

  KDevelop::ModificationRevisionSet includePathDependency;

42
  KDevelop::Path::List paths;
43
  QHash<QString, QString> defines;
44

45
  void mergeWith(const PathResolutionResult& rhs);
46
47

  operator bool() const;
Milian Wolff's avatar
Milian Wolff committed
48
49
50
51
52
};

class SourcePathInformation;

///One resolution-try can issue up to 4 make-calls in worst case
53
class MakeFileResolver
Milian Wolff's avatar
Milian Wolff committed
54
55
{
  public:
56
    MakeFileResolver();
Milian Wolff's avatar
Milian Wolff committed
57
58
59
60
61
62
63
64
65
66
67
68
    ///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);

69
70
71
    void enableMakeResolution(bool enable);
    PathResolutionResult processOutput(const QString& fullOutput, const QString& workingDirectory) const;

Milian Wolff's avatar
Milian Wolff committed
72
  private:
73
74
    PathResolutionResult resolveIncludePath( const QString& file, const QString& workingDirectory, int maxStepsUp = 20 );

Milian Wolff's avatar
Milian Wolff committed
75
76
77
    bool m_isResolving;
    bool m_outOfSource;

Milian Wolff's avatar
Milian Wolff committed
78
    QString mapToBuild(const QString &path) const;
Milian Wolff's avatar
Milian Wolff committed
79
80
81
82
83

    ///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,
84
                                                      const QString& makeParameters, const SourcePathInformation& source, int maxDepth );
Milian Wolff's avatar
Milian Wolff committed
85
86
    QString m_source;
    QString m_build;
Milian Wolff's avatar
f    
Milian Wolff committed
87
88
89
90
91
92
93

    // reuse cached instances of Paths and strings, to share memory where possible
    mutable QHash<QString, KDevelop::Path> m_pathCache;
    mutable QSet<QString> m_stringCache;

    KDevelop::Path internPath(const QString& path) const;
    QString internString(const QString& string) const;
Milian Wolff's avatar
Milian Wolff committed
94
95
};

Kris Wong's avatar
Kris Wong committed
96
#endif