aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/generator
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-06-26 10:43:52 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-06-27 09:47:47 +0000
commitd62278afd55c87101de7c7a9327f06cf5326af0b (patch)
tree2d3c20ceccff8220b860f84e8051890a4e79d4ed /sources/shiboken2/generator
parent4a32f9d00b043b7255b590b95e9b35e9de44c4ed (diff)
shiboken: No longer hard-code the C++ language level
The C++ language level was previously hard-coded in the default options. This is potentially problematic for projects using shiboken and also fell apart with Qt 5.12, where the experimental level "c++1z" used for MSVC2017/Clang 4 no longer works due to not being able to handle enumerator value deprecation attributes. Introduce an enumeration to represent the level and add functions to convert back to and forth to the respective Clang option. Add an option to shiboken. Add a function returning a default value for the emulated compiler, returning C++ 14 or C++1Z for the CMSVC2017/Clang 4 case. Task-number: PYSIDE-724 Change-Id: Ie7e19bf7f099a34e6cdaad4b462157a9a3ee8797 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/generator')
-rw-r--r--sources/shiboken2/generator/main.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/sources/shiboken2/generator/main.cpp b/sources/shiboken2/generator/main.cpp
index b0ce849a7..7ee43710e 100644
--- a/sources/shiboken2/generator/main.cpp
+++ b/sources/shiboken2/generator/main.cpp
@@ -46,6 +46,7 @@
#define PATH_SPLITTER ":"
#endif
+static inline QString languageLevelOption() { return QStringLiteral("language-level"); }
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"); }
@@ -175,6 +176,7 @@ static bool processProjectFile(QFile& projectFile, QMap<QString, QString>& args)
QStringList systemIncludePaths;
QStringList typesystemPaths;
QStringList apiVersions;
+ QString languageLevel;
while (!projectFile.atEnd()) {
line = projectFile.readLine().trimmed();
@@ -199,6 +201,8 @@ static bool processProjectFile(QFile& projectFile, QMap<QString, QString>& args)
systemIncludePaths << QDir::toNativeSeparators(value);
else if (key == "typesystem-path")
typesystemPaths << QDir::toNativeSeparators(value);
+ else if (key == "language-level")
+ languageLevel = value;
else if (key == "api-version")
apiVersions << value;
else if (key == "header-file")
@@ -224,6 +228,8 @@ static bool processProjectFile(QFile& projectFile, QMap<QString, QString>& args)
args.insert(typesystemPathOption(), typesystemPaths.join(QLatin1String(PATH_SPLITTER)));
if (!apiVersions.isEmpty())
args.insert(QLatin1String("api-version"), apiVersions.join(QLatin1Char('|')));
+ if (!languageLevel.isEmpty())
+ args.insert(languageLevelOption(), languageLevel);
return true;
}
@@ -311,6 +317,8 @@ static void getCommandLineArg(QString arg, int &argNum, QMap<QString, QString> &
addPathOptionValue(typesystemPathOption(), arg.mid(1), args);
else if (arg == QLatin1String("h"))
args.insert(helpOption(), QString());
+ else if (arg.startsWith(QLatin1String("std=")))
+ args.insert(languageLevelOption(), arg.mid(4));
else
args.insert(arg, QString());
return;
@@ -348,6 +356,13 @@ static inline Generators shibokenGenerators()
return result;
}
+static inline QString languageLevelDescription()
+{
+ return QLatin1String("C++ Language level (c++11..c++17, default=")
+ + QLatin1String(clang::languageLevelOption(clang::emulatedCompilerLanguageLevel()))
+ + QLatin1Char(')');
+}
+
void printUsage()
{
QTextStream s(stdout);
@@ -379,6 +394,8 @@ void printUsage()
<< qMakePair(QLatin1String("-I") + pathSyntax, QString())
<< qMakePair(QLatin1String("include-paths=") + pathSyntax,
QLatin1String("Include paths used by the C++ parser"))
+ << qMakePair(languageLevelOption() + QLatin1String("=, -std=<level>"),
+ languageLevelDescription())
<< qMakePair(QLatin1String("license-file=<license-file>"),
QLatin1String("File used for copyright headers of generated files"))
<< qMakePair(QLatin1String("no-suppress-warnings"),
@@ -588,6 +605,18 @@ int main(int argc, char *argv[])
argsHandler.removeArg(od.first);
}
+ const QString languageLevel = argsHandler.removeArg(languageLevelOption());
+ if (!languageLevel.isEmpty()) {
+ const QByteArray languageLevelBA = languageLevel.toLatin1();
+ const LanguageLevel level = clang::languageLevelFromOption(languageLevelBA.constData());
+ if (level == LanguageLevel::Default) {
+ std::cout << "Invalid argument for language level: \""
+ << languageLevelBA.constData() << "\"\n" << helpHint;
+ return EXIT_FAILURE;
+ }
+ extractor.setLanguageLevel(level);
+ }
+
if (!argsHandler.noArgs()) {
errorPrint(argsHandler.errorMessage());
std::cout << helpHint;
@@ -601,6 +630,7 @@ int main(int argc, char *argv[])
extractor.setCppFileName(cppFileNameFi.absoluteFilePath());
extractor.setTypeSystem(typeSystemFileName);
+
if (!extractor.run()) {
errorPrint(QLatin1String("Error running ApiExtractor."));
return EXIT_FAILURE;