diff options
author | Topi Reinio <topi.reinio@qt.io> | 2021-10-02 00:01:58 +0200 |
---|---|---|
committer | Topi Reinio <topi.reinio@qt.io> | 2021-10-08 10:35:03 +0200 |
commit | 6ee3cad531e782cf82777a4eca2f93f0469b2791 (patch) | |
tree | 81594a836466d3d41fe7cb067c2bc518c30e94ed /src/qdoc/clangcodeparser.cpp | |
parent | 3cee558b50ef87d08f34dc9d8ef0a1eab1a8fb2a (diff) | |
download | qttools-6ee3cad531e782cf82777a4eca2f93f0469b2791.tar.gz |
qdoc: Teach Config::getCanonicalPathList() to read include paths
Include paths must be canonicalized for them to be correct. Previously,
the ClangCodeParser did this step, but it was done in relation to the
current working directory (cwd), and at that point cwd is the directory
of the main (top-level) qdocconf file - if includepaths variable was
used in another included config file and contained relative paths,
this produced incorrect results.
As Config already knowns how to canonicalize paths, teach it to
consider the common prefixes associated with include paths. As config
variables store their location, we can produce absolute paths
reliably in all situations.
Document the includepaths and the associated moduleheader variables.
Fixes: QTBUG-97034
Pick-to: 6.2
Change-Id: Iecf68e3cb09ced732f7a05270441da046e8df8d8
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/qdoc/clangcodeparser.cpp')
-rw-r--r-- | src/qdoc/clangcodeparser.cpp | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index b8feca108..d61b24270 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -1096,38 +1096,18 @@ void ClangCodeParser::initializeParser() { Config &config = Config::instance(); m_version = config.getString(CONFIG_VERSION); - auto args = config.getStringList(CONFIG_INCLUDEPATHS); - QSet<QString> seen; - m_includePaths.clear(); - + auto args = config.getCanonicalPathList(CONFIG_INCLUDEPATHS, + Config::IncludePaths); #ifdef Q_OS_MACOS args.append(Utilities::getInternalIncludePaths(QStringLiteral("clang++"))); #endif - - // Remove empty paths and duplicates and add -I and canonicalize if necessary - for (const auto &p : args) { - QByteArray option; - QString rawpath; - if (p.startsWith(QLatin1String("-I")) || p.startsWith(QLatin1String("-F"))) { - rawpath = p.mid(2).trimmed(); - option = p.left(2).toUtf8(); - } else if (p.startsWith(QLatin1String("-isystem"))) { - rawpath = p.mid(8).trimmed(); - option = "-isystem"; - } else { - rawpath = p; - option = "-I"; - } - if (rawpath.isEmpty() || seen.contains(rawpath)) - continue; - seen.insert(rawpath); - QByteArray path(rawpath.toUtf8()); - QFileInfo fi(QDir::current(), rawpath); - if (fi.exists()) - path = fi.canonicalFilePath().toUtf8(); - path.prepend(option); - m_includePaths.append(path); + m_includePaths.clear(); + for (const auto &path : qAsConst(args)) { + if (!path.isEmpty()) + m_includePaths.append(path.toUtf8()); } + m_includePaths.erase(std::unique(m_includePaths.begin(), m_includePaths.end()), + m_includePaths.end()); CppCodeParser::initializeParser(); m_pchFileDir.reset(nullptr); m_allHeaders.clear(); |