diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-06-21 17:04:40 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-06-22 20:20:44 +0000 |
commit | cf4dc77a973fa488594a818381cc9f0941a4f940 (patch) | |
tree | f12f030f58291adb43d17837784194add1fb1890 | |
parent | 5cf419c973ac367ab36e47abf4bde953ae533706 (diff) |
shiboken: Add command line options for system include paths
Refactor class HeaderPath to contain an enumeration for the type
instead of the boolean framework flag and add handling.
Task-number: PYSIDE-693
Change-Id: I60a62b831ddd5ce7519a066135854ff723db2fc6
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r-- | sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp | 11 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/header_paths.h | 38 | ||||
-rw-r--r-- | sources/shiboken2/generator/main.cpp | 50 |
3 files changed, 59 insertions, 40 deletions
diff --git a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp index 655454898..e7de8fdb3 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp @@ -106,9 +106,9 @@ static HeaderPaths gppInternalIncludePaths(const QString &compiler) if (line.startsWith(QByteArrayLiteral("End of search list"))) { isIncludeDir = false; } else { - HeaderPath headerPath(line.trimmed()); + HeaderPath headerPath{line.trimmed(), HeaderType::System}; if (headerPath.path.endsWith(frameworkPath())) { - headerPath.m_isFramework = true; + headerPath.type = HeaderType::FrameworkSystem; headerPath.path.truncate(headerPath.path.size() - frameworkPath().size()); } result.append(headerPath); @@ -127,7 +127,8 @@ static void detectVulkan(HeaderPaths *headerPaths) static const char *vulkanVariables[] = {"VULKAN_SDK", "VK_SDK_PATH"}; for (const char *vulkanVariable : vulkanVariables) { if (qEnvironmentVariableIsSet(vulkanVariable)) { - headerPaths->append(HeaderPath(qgetenv(vulkanVariable) + QByteArrayLiteral("/include"))); + const QByteArray path = qgetenv(vulkanVariable) + QByteArrayLiteral("/include"); + headerPaths->append(HeaderPath{path, HeaderType::System}); break; } } @@ -193,9 +194,7 @@ QByteArrayList emulatedCompilerOptions() #endif detectVulkan(&headerPaths); std::transform(headerPaths.cbegin(), headerPaths.cend(), - std::back_inserter(result), [](const HeaderPath &p) { - return HeaderPath::includeOption(p, true); - }); + std::back_inserter(result), HeaderPath::includeOption); return result; } diff --git a/sources/shiboken2/ApiExtractor/header_paths.h b/sources/shiboken2/ApiExtractor/header_paths.h index 4681f14de..01d830921 100644 --- a/sources/shiboken2/ApiExtractor/header_paths.h +++ b/sources/shiboken2/ApiExtractor/header_paths.h @@ -33,30 +33,36 @@ #include <QList> #include <QString> +enum class HeaderType +{ + Standard, + System, // -isystem + Framework, // macOS framework path + FrameworkSystem // macOS framework system path +}; + 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 + HeaderType type; - static QByteArray includeOption(const HeaderPath &p, bool systemInclude = false) + static QByteArray includeOption(const HeaderPath &p) { QByteArray option; - - if (p.m_isFramework) { - if (systemInclude) - option = QByteArrayLiteral("-iframework"); - else - option = QByteArrayLiteral("-F"); - } else if (systemInclude) { - option = QByteArrayLiteral("-isystem"); - } else { + switch (p.type) { + case HeaderType::Standard: option = QByteArrayLiteral("-I"); + break; + case HeaderType::System: + option = QByteArrayLiteral("-isystem"); + break; + case HeaderType::Framework: + option = QByteArrayLiteral("-F"); + break; + case HeaderType::FrameworkSystem: + option = QByteArrayLiteral("-iframework"); + break; } - return option + p.path; } }; diff --git a/sources/shiboken2/generator/main.cpp b/sources/shiboken2/generator/main.cpp index 69f59a1b4..b0ce849a7 100644 --- a/sources/shiboken2/generator/main.cpp +++ b/sources/shiboken2/generator/main.cpp @@ -48,6 +48,7 @@ static inline QString includePathOption() { return QStringLiteral("include-paths"); } static inline QString frameworkIncludePathOption() { return QStringLiteral("framework-include-paths"); } +static inline QString systemIncludePathOption() { return QStringLiteral("system-include-paths"); } static inline QString typesystemPathOption() { return QStringLiteral("typesystem-paths"); } static inline QString helpOption() { return QStringLiteral("help"); } static const char helpHint[] = "Note: use --help or -h for more information.\n"; @@ -171,6 +172,7 @@ static bool processProjectFile(QFile& projectFile, QMap<QString, QString>& args) QStringList includePaths; QStringList frameworkIncludePaths; + QStringList systemIncludePaths; QStringList typesystemPaths; QStringList apiVersions; @@ -193,6 +195,8 @@ static bool processProjectFile(QFile& projectFile, QMap<QString, QString>& args) includePaths << QDir::toNativeSeparators(value); else if (key == "framework-include-path") frameworkIncludePaths << QDir::toNativeSeparators(value); + else if (key == "system-include-paths") + systemIncludePaths << QDir::toNativeSeparators(value); else if (key == "typesystem-path") typesystemPaths << QDir::toNativeSeparators(value); else if (key == "api-version") @@ -211,6 +215,10 @@ static bool processProjectFile(QFile& projectFile, QMap<QString, QString>& args) if (!frameworkIncludePaths.isEmpty()) args.insert(frameworkIncludePathOption(), frameworkIncludePaths.join(QLatin1String(PATH_SPLITTER))); + if (!systemIncludePaths.isEmpty()) { + args.insert(systemIncludePathOption(), + systemIncludePaths.join(QLatin1String(PATH_SPLITTER))); + } if (!typesystemPaths.isEmpty()) args.insert(typesystemPathOption(), typesystemPaths.join(QLatin1String(PATH_SPLITTER))); @@ -284,7 +292,7 @@ static void getCommandLineArg(QString arg, int &argNum, QMap<QString, QString> & const QString option = arg.left(split); const QString value = arg.mid(split + 1).trimmed(); if (option == includePathOption() || option == frameworkIncludePathOption() - || option == typesystemPathOption()) { + || option == systemIncludePathOption() || option == typesystemPathOption()) { addPathOptionValue(option, value, args); } else { args.insert(option, value); @@ -297,6 +305,8 @@ static void getCommandLineArg(QString arg, int &argNum, QMap<QString, QString> & addPathOptionValue(includePathOption(), arg.mid(1), args); else if (arg.startsWith(QLatin1Char('F'))) addPathOptionValue(frameworkIncludePathOption(), arg.mid(1), args); + else if (arg.startsWith(QLatin1String("isystem"))) + addPathOptionValue(systemIncludePathOption(), arg.mid(7), args); else if (arg.startsWith(QLatin1Char('T'))) addPathOptionValue(typesystemPathOption(), arg.mid(1), args); else if (arg == QLatin1String("h")) @@ -358,6 +368,9 @@ void printUsage() << qMakePair(QLatin1String("-F") + pathSyntax, QString()) << qMakePair(QLatin1String("framework-include-paths=") + pathSyntax, QLatin1String("Framework include paths used by the C++ parser")) + << qMakePair(QLatin1String("-isystem") + pathSyntax, QString()) + << qMakePair(QLatin1String("system-include-paths=") + pathSyntax, + QLatin1String("System include paths used by the C++ parser")) << qMakePair(QLatin1String("generator-set=<\"generator module\">"), QLatin1String("generator-set to be used. e.g. qtdoc")) << qMakePair(QLatin1String("-h"), QString()) @@ -414,6 +427,18 @@ static QString msgInvalidVersion(const QString &package, const QString &version) + QLatin1String("\" specified for package ") + package + QLatin1Char('.'); } +static void parseIncludePathOption(const QString &option, HeaderType headerType, + ArgsHandler &args, + ApiExtractor &extractor) +{ + const QString path = args.removeArg(option); + if (!path.isEmpty()) { + const QStringList includePathListList = path.split(QLatin1String(PATH_SPLITTER)); + for (const QString &s : includePathListList) + extractor.addIncludePath(HeaderPath{QFile::encodeName(s), headerType}); + } +} + int main(int argc, char *argv[]) { QElapsedTimer timer; @@ -525,23 +550,12 @@ int main(int argc, char *argv[]) if (!path.isEmpty()) extractor.addTypesystemSearchPath(path.split(QLatin1String(PATH_SPLITTER))); - path = argsHandler.removeArg(QLatin1String("include-paths")); - 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)); - } - } + parseIncludePathOption(includePathOption(), HeaderType::Standard, + argsHandler, extractor); + parseIncludePathOption(frameworkIncludePathOption(), HeaderType::Framework, + argsHandler, extractor); + parseIncludePathOption(systemIncludePathOption(), HeaderType::System, + argsHandler, extractor); QString cppFileName = argsHandler.removeArg(QLatin1String("arg-1")); const QFileInfo cppFileNameFi(cppFileName); |