diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-04-28 12:08:18 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-04-28 13:47:17 +0000 |
commit | 12e84c9208f09db1c6eb88470bd9efb8a1a2a3f5 (patch) | |
tree | e75127d62365492ef9c2d905a5566b9d895c3097 | |
parent | 54cc52d16ccd0c6350823a1cfcc0154c1a1f543b (diff) |
Fix clang parser to work with Qt framework builds
Change-Id: I46f957168ed3d24183d0102a687a3b693f2782c9
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r-- | ApiExtractor/apiextractor.cpp | 8 | ||||
-rw-r--r-- | ApiExtractor/apiextractor.h | 9 | ||||
-rw-r--r-- | ApiExtractor/clangparser/compilersupport.cpp | 22 | ||||
-rw-r--r-- | ApiExtractor/header_paths.h | 62 | ||||
-rw-r--r-- | generator/main.cpp | 27 |
5 files changed, 101 insertions, 27 deletions
diff --git a/ApiExtractor/apiextractor.cpp b/ApiExtractor/apiextractor.cpp index a83136e..abb7c08 100644 --- a/ApiExtractor/apiextractor.cpp +++ b/ApiExtractor/apiextractor.cpp @@ -79,12 +79,12 @@ void ApiExtractor::addTypesystemSearchPath(const QStringList& paths) addTypesystemSearchPath(path); } -void ApiExtractor::addIncludePath(const QString& path) +void ApiExtractor::addIncludePath(const HeaderPath& path) { m_includePaths << path; } -void ApiExtractor::addIncludePath(const QStringList& paths) +void ApiExtractor::addIncludePath(const HeaderPaths& paths) { m_includePaths << paths; } @@ -271,8 +271,8 @@ bool ApiExtractor::run() m_builder->setGlobalHeader(m_cppFileName); QByteArrayList arguments; arguments.reserve(m_includePaths.size() + 1); - for (const QString &i : qAsConst(m_includePaths)) - arguments.append(QByteArrayLiteral("-I") + QFile::encodeName(i)); + for (const HeaderPath &headerPath : qAsConst(m_includePaths)) + arguments.append(HeaderPath::includeOption(headerPath)); arguments.append(QFile::encodeName(preprocessedCppFileName)); qCDebug(lcShiboken) << __FUNCTION__ << arguments; const bool result = m_builder->build(arguments); diff --git a/ApiExtractor/apiextractor.h b/ApiExtractor/apiextractor.h index ea46e1b..ac90f5b 100644 --- a/ApiExtractor/apiextractor.h +++ b/ApiExtractor/apiextractor.h @@ -33,6 +33,7 @@ #include "dependency.h" #include "abstractmetalang_typedefs.h" #include "apiextractormacros.h" +#include "header_paths.h" #include "typedatabase_typedefs.h" #include "typesystem_typedefs.h" #include <QStringList> @@ -68,9 +69,9 @@ public: void setSilent(bool value); void addTypesystemSearchPath(const QString& path); void addTypesystemSearchPath(const QStringList& paths); - void addIncludePath(const QString& path); - void addIncludePath(const QStringList& paths); - QStringList includePaths() const { return m_includePaths; } + void addIncludePath(const HeaderPath& path); + void addIncludePath(const HeaderPaths& paths); + HeaderPaths includePaths() const { return m_includePaths; } void setLogDirectory(const QString& logDir); bool setApiVersion(const QString& package, const QString& version); void setDropTypeEntries(QString dropEntries); @@ -95,7 +96,7 @@ public: private: QString m_typeSystemFileName; QString m_cppFileName; - QStringList m_includePaths; + HeaderPaths m_includePaths; AbstractMetaBuilder* m_builder; QString m_logDirectory; diff --git a/ApiExtractor/clangparser/compilersupport.cpp b/ApiExtractor/clangparser/compilersupport.cpp index 0346b0a..df82f90 100644 --- a/ApiExtractor/clangparser/compilersupport.cpp +++ b/ApiExtractor/clangparser/compilersupport.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include "compilersupport.h" +#include "header_paths.h" #include <QtCore/QDebug> #include <QtCore/QProcess> @@ -76,21 +77,6 @@ static bool runProcess(const QString &program, const QStringList &arguments, return true; } -class HeaderPath { -public: - explicit HeaderPath(const QByteArray &p = QByteArray()) : path(p), isFramework(false) {} - - QByteArray path; - bool isFramework; // macOS framework path -}; - -static QByteArray includeOption(const HeaderPath &p) -{ - return (p.isFramework ? QByteArrayLiteral("-F") : QByteArrayLiteral("-I")) + p.path; -} - -typedef QList<HeaderPath> HeaderPaths; - #if defined(Q_CC_GNU) static QByteArray frameworkPath() { return QByteArrayLiteral(" (framework directory)"); } @@ -121,7 +107,7 @@ static HeaderPaths gppInternalIncludePaths(const QString &compiler) } else { HeaderPath headerPath(line.trimmed()); if (headerPath.path.endsWith(frameworkPath())) { - headerPath.isFramework = true; + headerPath.m_isFramework = true; headerPath.path.truncate(headerPath.path.size() - frameworkPath().size()); } result.append(headerPath); @@ -160,7 +146,9 @@ QByteArrayList emulatedCompilerOptions() const HeaderPaths headerPaths; #endif std::transform(headerPaths.cbegin(), headerPaths.cend(), - std::back_inserter(result), includeOption); + std::back_inserter(result), [](const HeaderPath &p) { + return HeaderPath::includeOption(p, true); + }); return result; } diff --git a/ApiExtractor/header_paths.h b/ApiExtractor/header_paths.h new file mode 100644 index 0000000..3bc26ef --- /dev/null +++ b/ApiExtractor/header_paths.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of PySide2. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef HEADER_PATHS_H +#define HEADER_PATHS_H + +#include <QByteArray> +#include <QList> +#include <QString> + +class HeaderPath { +public: + explicit HeaderPath(const QByteArray &p = QByteArray()) : path(p), m_isFramework(false) {} + explicit HeaderPath(const QString &s = QString(), bool isFramework = false) : + path(s.toLatin1()), m_isFramework(isFramework) {} + + QByteArray path; + bool m_isFramework; // macOS framework path + + static QByteArray includeOption(const HeaderPath &p, bool systemInclude = false) + { + QByteArray option; + + if (p.m_isFramework) + option = QByteArrayLiteral("-F"); + else if (systemInclude) + option = QByteArrayLiteral("-isystem"); + else + option = QByteArrayLiteral("-I"); + + return option + p.path; + } +}; + +typedef QList<HeaderPath> HeaderPaths; + +#endif // HEADER_PATHS_H diff --git a/generator/main.cpp b/generator/main.cpp index f0e334d..25b50b0 100644 --- a/generator/main.cpp +++ b/generator/main.cpp @@ -156,6 +156,7 @@ static bool processProjectFile(QFile& projectFile, QMap<QString, QString>& args) return false; QStringList includePaths; + QStringList frameworkIncludePaths; QStringList typesystemPaths; QStringList apiVersions; @@ -176,6 +177,8 @@ static bool processProjectFile(QFile& projectFile, QMap<QString, QString>& args) if (key == "include-path") includePaths << QDir::toNativeSeparators(value); + else if (key == "framework-include-path") + frameworkIncludePaths << QDir::toNativeSeparators(value); else if (key == "typesystem-path") typesystemPaths << QDir::toNativeSeparators(value); else if (key == "api-version") @@ -191,6 +194,10 @@ static bool processProjectFile(QFile& projectFile, QMap<QString, QString>& args) if (!includePaths.isEmpty()) args.insert(QLatin1String("include-paths"), includePaths.join(QLatin1String(PATH_SPLITTER))); + if (!frameworkIncludePaths.isEmpty()) + args.insert(QLatin1String("framework-include-paths"), + frameworkIncludePaths.join(QLatin1String(PATH_SPLITTER))); + if (!typesystemPaths.isEmpty()) args.insert(QLatin1String("typesystem-paths"), typesystemPaths.join(QLatin1String(PATH_SPLITTER))); if (!apiVersions.isEmpty()) @@ -301,6 +308,8 @@ void printUsage() QLatin1String("The directory where the generated files will be written")); generalOptions.insert(QLatin1String("include-paths=<path>[" PATH_SPLITTER "<path>" PATH_SPLITTER "...]"), QLatin1String("Include paths used by the C++ parser")); + generalOptions.insert(QLatin1String("framework-include-paths=<path>[" PATH_SPLITTER "<path>" PATH_SPLITTER "...]"), + QLatin1String("Framework include paths used by the C++ parser")); generalOptions.insert(QLatin1String("typesystem-paths=<path>[" PATH_SPLITTER "<path>" PATH_SPLITTER "...]"), QLatin1String("Paths used when searching for typesystems")); generalOptions.insert(QLatin1String("documentation-only"), @@ -460,8 +469,22 @@ int main(int argc, char *argv[]) extractor.addTypesystemSearchPath(path.split(QLatin1String(PATH_SPLITTER))); path = argsHandler.removeArg(QLatin1String("include-paths")); - if (!path.isEmpty()) - extractor.addIncludePath(path.split(QLatin1String(PATH_SPLITTER))); + if (!path.isEmpty()) { + const QStringList includePathListList = path.split(QLatin1String(PATH_SPLITTER)); + for (const QString &s : qAsConst(includePathListList)) { + const bool isFramework = false; + extractor.addIncludePath(HeaderPath(s, isFramework)); + } + } + + path = argsHandler.removeArg(QLatin1String("framework-include-paths")); + if (!path.isEmpty()) { + const QStringList frameworkPathList = path.split(QLatin1String(PATH_SPLITTER)); + const bool isFramework = true; + for (const QString &s : qAsConst(frameworkPathList)) { + extractor.addIncludePath(HeaderPath(s, isFramework)); + } + } QString cppFileName = argsHandler.removeArg(QLatin1String("arg-1")); QString typeSystemFileName = argsHandler.removeArg(QLatin1String("arg-2")); |