aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-09-15 14:59:17 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-09-16 10:30:27 +0200
commitb20d6f6906f91f9df608d7800f4e27f7a7160abe (patch)
tree8deceb4b89eb5c608699fd80bf6a4f6f13c35cb0
parentf41af9d876d265fbb7febac191d9ba15887252e7 (diff)
shiboken6: Add command line options for compiler, path and platform
Task-number: PYSIDE-2057 Task-number: PYSIDE-1812 Change-Id: I3b43e7f747df87174c7feec0b29c292d3bddb23c Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp42
-rw-r--r--sources/shiboken6/ApiExtractor/clangparser/compilersupport.h7
-rw-r--r--sources/shiboken6/doc/shibokengenerator.rst9
-rw-r--r--sources/shiboken6/generator/main.cpp40
4 files changed, 97 insertions, 1 deletions
diff --git a/sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp b/sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp
index 2e342fefb..9f28402cd 100644
--- a/sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp
+++ b/sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp
@@ -43,6 +43,32 @@ static Compiler _compiler =
Compiler compiler() { return _compiler; }
+bool setCompiler(const QString &name)
+{
+ bool result = true;
+ if (name == u"msvc")
+ _compiler = Compiler::Msvc;
+ else if (name == u"g++")
+ _compiler = Compiler::Gpp;
+ else if (name == u"clang")
+ _compiler = Compiler::Clang;
+ else
+ result = false;
+ return result;
+}
+
+QString _compilerPath; // Pre-defined compiler path (from command line)
+
+const QString &compilerPath()
+{
+ return _compilerPath;
+}
+
+void setCompilerPath(const QString &name)
+{
+ _compilerPath = name;
+}
+
static Platform _platform =
#if defined (Q_OS_DARWIN)
Platform::macOS;
@@ -54,6 +80,20 @@ static Platform _platform =
Platform platform() { return _platform; }
+bool setPlatform(const QString &name)
+{
+ bool result = true;
+ if (name == u"windows")
+ _platform = Platform::Windows;
+ else if (name == u"darwin")
+ _platform = Platform::macOS;
+ else if (name == u"unix")
+ _platform = Platform::Unix;
+ else
+ result = false;
+ return result;
+}
+
static bool runProcess(const QString &program, const QStringList &arguments,
QByteArray *stdOutIn = nullptr, QByteArray *stdErrIn = nullptr)
{
@@ -255,6 +295,8 @@ static QString findClangBuiltInIncludesDir()
static QString compilerFromCMake(const QString &defaultCompiler)
{
+ if (!compilerPath().isEmpty())
+ return compilerPath();
// Added !defined(Q_OS_DARWIN) due to PYSIDE-1032
QString result = defaultCompiler;
if (platform() != Platform::macOS)
diff --git a/sources/shiboken6/ApiExtractor/clangparser/compilersupport.h b/sources/shiboken6/ApiExtractor/clangparser/compilersupport.h
index 24d109cac..18e87c495 100644
--- a/sources/shiboken6/ApiExtractor/clangparser/compilersupport.h
+++ b/sources/shiboken6/ApiExtractor/clangparser/compilersupport.h
@@ -7,6 +7,7 @@
#include <QtCore/QByteArrayList>
QT_FORWARD_DECLARE_CLASS(QVersionNumber)
+QT_FORWARD_DECLARE_CLASS(QString)
enum class LanguageLevel {
Default,
@@ -41,7 +42,13 @@ LanguageLevel languageLevelFromOption(const char *);
QByteArrayList detectVulkan();
Compiler compiler();
+bool setCompiler(const QString &name);
+
+const QString &compilerPath();
+void setCompilerPath(const QString &name);
+
Platform platform();
+bool setPlatform(const QString &name);
} // namespace clang
#endif // COMPILERSUPPORT_H
diff --git a/sources/shiboken6/doc/shibokengenerator.rst b/sources/shiboken6/doc/shibokengenerator.rst
index a0ca06b42..ddb95feec 100644
--- a/sources/shiboken6/doc/shibokengenerator.rst
+++ b/sources/shiboken6/doc/shibokengenerator.rst
@@ -194,6 +194,15 @@ Options
When '-' is passed as the first option in the list, none of the options
built into shiboken will be added, allowing for a complete replacement.
+``--compiler=<type>``
+ Emulated compiler type (g++, msvc, clang)
+
+``--compiler-path=<file>``
+ Path to the compiler for determining builtin include paths
+
+``--platform=<file>``
+ Emulated platform (windows, darwin, unix)
+
.. _include-paths:
``-I<path>, --include-paths=<path>[:<path>:...]``
diff --git a/sources/shiboken6/generator/main.cpp b/sources/shiboken6/generator/main.cpp
index 60540dc03..e9fcd0571 100644
--- a/sources/shiboken6/generator/main.cpp
+++ b/sources/shiboken6/generator/main.cpp
@@ -35,6 +35,9 @@ static const QChar apiVersionSplitter = u'|';
static inline QString keywordsOption() { return QStringLiteral("keywords"); }
static inline QString clangOptionOption() { return QStringLiteral("clang-option"); }
static inline QString clangOptionsOption() { return QStringLiteral("clang-options"); }
+static inline QString compilerOption() { return QStringLiteral("compiler"); }
+static inline QString compilerPathOption() { return QStringLiteral("compiler-path"); }
+static inline QString platformOption() { return QStringLiteral("platform"); }
static inline QString apiVersionOption() { return QStringLiteral("api-version"); }
static inline QString dropTypeEntriesOption() { return QStringLiteral("drop-type-entries"); }
static inline QString languageLevelOption() { return QStringLiteral("language-level"); }
@@ -112,7 +115,10 @@ bool CommandLineArguments::addCommonOption(const QString &option,
const QString &value)
{
bool result = true;
- if (option == clangOptionOption()) {
+ if (option == compilerOption() || option == compilerPathOption()
+ || option == platformOption()) {
+ options.insert(option, value);
+ } else if (option == clangOptionOption()) {
options.insert(option, QStringList(value));
} else if (option == clangOptionsOption()) {
addToOptionsList(option, value, clangOptionsSplitter);
@@ -344,6 +350,12 @@ void printUsage()
u"Option to be passed to clang"_s},
{clangOptionsOption(),
u"A comma-separated list of options to be passed to clang"_s},
+ {compilerOption() + u"=<type>"_s,
+ u"Emulated compiler type (g++, msvc, clang)"_s},
+ {platformOption() + u"=<name>"_s,
+ u"Emulated platform (windows, darwin, unix)"_s},
+ {compilerPathOption() + u"=<file>"_s,
+ u"Path to the compiler for determining builtin include paths"_s},
{u"-F<path>"_s, {} },
{u"framework-include-paths="_s + pathSyntax,
u"Framework include paths used by the C++ parser"_s},
@@ -598,6 +610,32 @@ int shibokenMain(int argc, char *argv[])
args.options.erase(ait);
}
+ ait = args.options.find(compilerOption());
+ if (ait != args.options.end()) {
+ const QString name = ait.value().toString();
+ if (!clang::setCompiler(name)) {
+ errorPrint(u"Invalid value \""_s + name + u"\" passed to --compiler"_s);
+ return EXIT_FAILURE;
+ }
+ args.options.erase(ait);
+ }
+
+ ait = args.options.find(compilerPathOption());
+ if (ait != args.options.end()) {
+ clang::setCompilerPath(ait.value().toString());
+ args.options.erase(ait);
+ }
+
+ ait = args.options.find(platformOption());
+ if (ait != args.options.end()) {
+ const QString name = ait.value().toString();
+ if (!clang::setPlatform(name)) {
+ errorPrint(u"Invalid value \""_s + name + u"\" passed to --platform"_s);
+ return EXIT_FAILURE;
+ }
+ args.options.erase(ait);
+ }
+
parseIncludePathOption(includePathOption(), HeaderType::Standard,
args, extractor);
parseIncludePathOption(frameworkIncludePathOption(), HeaderType::Framework,