From ed1a6d48c61b33c94c51fb92619ae173fa5c22c5 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 3 Jun 2020 09:33:13 +0200 Subject: shiboken: Allow for multiple header files on command line Change ApiExtractor and MetaBuilder to use QFileInfoList. Refactor the options handling to work on a struct separating options from positional arguments to make handling multiple file names easier. Refactor and streamline the options parsing code a bit, avoid duplicated parsing of project files. Print the usage when positional arguments are missing. [ChangeLog][shiboken] shiboken now accepts multiple headers on the command line. Change-Id: I221ab5a71232af1323408f77295137dc92e3d582 Reviewed-by: Christian Tismer --- .../shiboken2/ApiExtractor/abstractmetabuilder.cpp | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp') diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index b54dc70ef..dedf0db50 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -3106,9 +3106,9 @@ AbstractMetaArgumentList AbstractMetaBuilderPrivate::reverseList(const AbstractM return ret; } -void AbstractMetaBuilder::setGlobalHeader(const QString& globalHeader) +void AbstractMetaBuilder::setGlobalHeaders(const QFileInfoList &globalHeaders) { - d->m_globalHeader = QFileInfo(globalHeader); + d->m_globalHeaders = globalHeaders; } void AbstractMetaBuilder::setHeaderPaths(const HeaderPaths &hp) @@ -3146,23 +3146,26 @@ static bool matchHeader(const QString &headerPath, const QString &fileName) && fileName.startsWith(headerPath, caseSensitivity); } -void AbstractMetaBuilderPrivate::setInclude(TypeEntry *te, const QString &fileName) const +void AbstractMetaBuilderPrivate::setInclude(TypeEntry *te, const QString &path) const { - auto it = m_resolveIncludeHash.find(fileName); + auto it = m_resolveIncludeHash.find(path); if (it == m_resolveIncludeHash.end()) { - QFileInfo info(fileName); - if (m_globalHeader.fileName() == info.fileName()) + QFileInfo info(path); + const QString fileName = info.fileName(); + if (std::any_of(m_globalHeaders.cbegin(), m_globalHeaders.cend(), + [fileName] (const QFileInfo &fi) { + return fi.fileName() == fileName; })) { return; + } int bestMatchLength = 0; for (const auto &headerPath : m_headerPaths) { - if (headerPath.size() > bestMatchLength && matchHeader(headerPath, fileName)) + if (headerPath.size() > bestMatchLength && matchHeader(headerPath, path)) bestMatchLength = headerPath.size(); } const QString include = bestMatchLength > 0 - ? fileName.right(fileName.size() - bestMatchLength - 1) - : info.fileName(); - it = m_resolveIncludeHash.insert(fileName, {Include::IncludePath, include}); + ? path.right(path.size() - bestMatchLength - 1) : fileName; + it = m_resolveIncludeHash.insert(path, {Include::IncludePath, include}); } te->setInclude(it.value()); } @@ -3187,7 +3190,7 @@ static void debugFormatSequence(QDebug &d, const char *key, const Container& c, void AbstractMetaBuilder::formatDebug(QDebug &debug) const { - debug << "m_globalHeader=" << d->m_globalHeader.absoluteFilePath(); + debug << "m_globalHeader=" << d->m_globalHeaders; debugFormatSequence(debug, "globalEnums", d->m_globalEnums, "\n"); debugFormatSequence(debug, "globalFunctions", d->m_globalFunctions, "\n"); if (const int scopeCount = d->m_scopes.size()) { -- cgit v1.2.3