aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-06-07 15:56:37 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2017-06-09 13:49:18 +0000
commita3e4e367cf462e2dd9d7b08fe8d3f0007c33e1fa (patch)
treea2c8d3fc3719656a18aaf2b3734fc73466efca06
parent798d3edb8ff260e7a6cf56640121146bc6e62593 (diff)
shiboken: Further refactor command line arguments and help
Replace the QMap of options returned by the generators by a vector of pairs to allow for specifying the order. This allows for better formatting -I/-F/-T in multiple lines. Add -h for help. Move the missing typelib file handling into main and print a help hint there. Change-Id: I5a95bd8d193be012aaa7ce3934945b25e21d3f79 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--sources/shiboken2/ApiExtractor/apiextractor.cpp5
-rw-r--r--sources/shiboken2/generator/generator.cpp4
-rw-r--r--sources/shiboken2/generator/generator.h5
-rw-r--r--sources/shiboken2/generator/main.cpp102
-rw-r--r--sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp25
-rw-r--r--sources/shiboken2/generator/qtdoc/qtdocgenerator.h2
-rw-r--r--sources/shiboken2/generator/shiboken2/headergenerator.h2
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.cpp31
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.h2
9 files changed, 95 insertions, 83 deletions
diff --git a/sources/shiboken2/ApiExtractor/apiextractor.cpp b/sources/shiboken2/ApiExtractor/apiextractor.cpp
index abb7c08b9..bce3a6e3f 100644
--- a/sources/shiboken2/ApiExtractor/apiextractor.cpp
+++ b/sources/shiboken2/ApiExtractor/apiextractor.cpp
@@ -243,10 +243,7 @@ bool ApiExtractor::run()
if (m_builder)
return false;
- if (m_typeSystemFileName.isEmpty()) {
- std::cerr << "You must specify a Type System file." << std::endl;
- return false;
- } else if (!TypeDatabase::instance()->parseFile(m_typeSystemFileName)) {
+ if (!TypeDatabase::instance()->parseFile(m_typeSystemFileName)) {
std::cerr << "Cannot parse file: " << qPrintable(m_typeSystemFileName);
return false;
}
diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp
index 76d104c12..f60b195f2 100644
--- a/sources/shiboken2/generator/generator.cpp
+++ b/sources/shiboken2/generator/generator.cpp
@@ -194,9 +194,9 @@ QVector<const AbstractMetaType*> Generator::instantiatedSmartPointers() const
return m_d->instantiatedSmartPointers;
}
-QMap< QString, QString > Generator::options() const
+Generator::OptionDescriptions Generator::options() const
{
- return QMap<QString, QString>();
+ return OptionDescriptions();
}
AbstractMetaClassList Generator::classes() const
diff --git a/sources/shiboken2/generator/generator.h b/sources/shiboken2/generator/generator.h
index 5ff5d6ae5..f0b2a5e41 100644
--- a/sources/shiboken2/generator/generator.h
+++ b/sources/shiboken2/generator/generator.h
@@ -137,6 +137,9 @@ private:
class Generator
{
public:
+ typedef QPair<QString, QString> OptionDescription;
+ typedef QVector<OptionDescription> OptionDescriptions;
+
/// Optiosn used around the generator code
enum Option {
NoOption = 0x00000000,
@@ -181,7 +184,7 @@ public:
bool setup(const ApiExtractor& extractor, const QMap<QString, QString> args);
- virtual QMap<QString, QString> options() const;
+ virtual OptionDescriptions options() const;
/// Returns the classes used to generate the binding code.
AbstractMetaClassList classes() const;
diff --git a/sources/shiboken2/generator/main.cpp b/sources/shiboken2/generator/main.cpp
index 23c345b5d..22bd3fa65 100644
--- a/sources/shiboken2/generator/main.cpp
+++ b/sources/shiboken2/generator/main.cpp
@@ -49,6 +49,8 @@
static inline QString includePathOption() { return QStringLiteral("include-paths"); }
static inline QString frameworkIncludePathOption() { return QStringLiteral("framework-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";
namespace {
@@ -138,14 +140,17 @@ QString ArgsHandler::errorMessage() const
}
}
-static void printOptions(QTextStream& s, const QMap<QString, QString>& options)
+typedef Generator::OptionDescriptions OptionDescriptions;
+
+static void printOptions(QTextStream& s, const OptionDescriptions& options)
{
- QMap<QString, QString>::const_iterator it = options.constBegin();
s.setFieldAlignment(QTextStream::AlignLeft);
- for (; it != options.constEnd(); ++it) {
- s << " --";
+ for (const auto &od : options) {
+ s << ' ';
+ if (!od.first.startsWith(QLatin1Char('-')))
+ s << "--";
s.setFieldWidth(38);
- s << it.key() << it.value();
+ s << od.first << od.second;
s.setFieldWidth(0);
s << endl;
}
@@ -289,6 +294,8 @@ static void getCommandLineArg(QString arg, int &argNum, QMap<QString, QString> &
addPathOptionValue(frameworkIncludePathOption(), arg.mid(1), args);
else if (arg.startsWith(QLatin1Char('T')))
addPathOptionValue(typesystemPathOption(), arg.mid(1), args);
+ else if (arg == QLatin1String("h"))
+ args.insert(helpOption(), QString());
else
args.insert(arg, QString());
return;
@@ -332,42 +339,47 @@ void printUsage()
s << "Usage:\n "
<< "shiboken [options] header-file typesystem-file\n\n"
<< "General options:\n";
- QMap<QString, QString> generalOptions;
- generalOptions.insert(QLatin1String("project-file=<file>"),
- QLatin1String("text file containing a description of the binding project. Replaces and overrides command line arguments"));
- generalOptions.insert(QLatin1String("debug-level=[sparse|medium|full]"),
- QLatin1String("Set the debug level"));
- generalOptions.insert(QLatin1String("silent"),
- QLatin1String("Avoid printing any message"));
- generalOptions.insert(QLatin1String("help"),
- QLatin1String("Display this help and exit"));
- generalOptions.insert(QLatin1String("no-suppress-warnings"),
- QLatin1String("Show all warnings"));
- generalOptions.insert(QLatin1String("output-directory=<path>"),
- QLatin1String("The directory where the generated files will be written"));
- generalOptions.insert(QLatin1String("include-paths=/-I<path>[" PATH_SPLITTER "<path>" PATH_SPLITTER "...]"),
- QLatin1String("Include paths used by the C++ parser"));
- generalOptions.insert(QLatin1String("framework-include-paths=/-F<path>[" PATH_SPLITTER "<path>" PATH_SPLITTER "...]"),
- QLatin1String("Framework include paths used by the C++ parser"));
- generalOptions.insert(QLatin1String("typesystem-paths=/-T<path>[" PATH_SPLITTER "<path>" PATH_SPLITTER "...]"),
- QLatin1String("Paths used when searching for typesystems"));
- generalOptions.insert(QLatin1String("documentation-only"),
- QLatin1String("Do not generates any code, just the documentation"));
- generalOptions.insert(QLatin1String("license-file=<license-file>"),
- QLatin1String("File used for copyright headers of generated files"));
- generalOptions.insert(QLatin1String("version"),
- QLatin1String("Output version information and exit"));
- generalOptions.insert(QLatin1String("generator-set=<\"generator module\">"),
- QLatin1String("generator-set to be used. e.g. qtdoc"));
- generalOptions.insert(QLatin1String("api-version=<\"package mask\">,<\"version\">"),
- QLatin1String("Specify the supported api version used to generate the bindings"));
- generalOptions.insert(QLatin1String("drop-type-entries=\"<TypeEntry0>[;TypeEntry1;...]\""),
- QLatin1String("Semicolon separated list of type system entries (classes, namespaces, global functions and enums) to be dropped from generation."));
+ const QString pathSyntax = QLatin1String("<path>[" PATH_SPLITTER "<path>" PATH_SPLITTER "...]");
+ OptionDescriptions generalOptions = OptionDescriptions()
+ << qMakePair(QLatin1String("api-version=<\"package mask\">,<\"version\">"),
+ QLatin1String("Specify the supported api version used to generate the bindings"))
+ << qMakePair(QLatin1String("debug-level=[sparse|medium|full]"),
+ QLatin1String("Set the debug level"))
+ << qMakePair(QLatin1String("documentation-only"),
+ QLatin1String("Do not generates any code, just the documentation"))
+ << qMakePair(QLatin1String("drop-type-entries=\"<TypeEntry0>[;TypeEntry1;...]\""),
+ QLatin1String("Semicolon separated list of type system entries (classes, namespaces, global functions and enums) to be dropped from generation."))
+ << qMakePair(QLatin1String("-F") + pathSyntax, QString())
+ << qMakePair(QLatin1String("framework-include-paths=") + pathSyntax,
+ QLatin1String("Framework 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())
+ << qMakePair(helpOption(),
+ QLatin1String("Display this help and exit"))
+ << qMakePair(QLatin1String("-I") + pathSyntax, QString())
+ << qMakePair(QLatin1String("include-paths=") + pathSyntax,
+ QLatin1String("Include paths used by the C++ parser"))
+ << qMakePair(QLatin1String("license-file=<license-file>"),
+ QLatin1String("File used for copyright headers of generated files"))
+ << qMakePair(QLatin1String("no-suppress-warnings"),
+ QLatin1String("Show all warnings"))
+ << qMakePair(QLatin1String("output-directory=<path>"),
+ QLatin1String("The directory where the generated files will be written"))
+ << qMakePair(QLatin1String("project-file=<file>"),
+ QLatin1String("text file containing a description of the binding project. Replaces and overrides command line arguments"))
+ << qMakePair(QLatin1String("silent"),
+ QLatin1String("Avoid printing any message"))
+ << qMakePair(QLatin1String("-T") + pathSyntax, QString())
+ << qMakePair(QLatin1String("typesystem-paths=") + pathSyntax,
+ QLatin1String("Paths used when searching for typesystems"))
+ << qMakePair(QLatin1String("version"),
+ QLatin1String("Output version information and exit"));
printOptions(s, generalOptions);
const Generators generators = shibokenGenerators() + docGenerators();
for (const GeneratorPtr &generator : generators) {
- QMap<QString, QString> options = generator->options();
+ const OptionDescriptions options = generator->options();
if (!options.isEmpty()) {
s << endl << generator->name() << " options:\n";
printOptions(s, generator->options());
@@ -541,17 +553,19 @@ int main(int argc, char *argv[])
argsHandler.removeArg(it.key());
}
for (const GeneratorPtr &generator : qAsConst(generators)) {
- QMap<QString, QString> options = generator->options();
- if (!options.isEmpty()) {
- QMap<QString, QString>::const_iterator it = options.constBegin();
- for ( ; it != options.constEnd(); ++it)
- argsHandler.removeArg(it.key());
- }
+ const OptionDescriptions &options = generator->options();
+ for (const auto &od : options)
+ argsHandler.removeArg(od.first);
}
if (!argsHandler.noArgs()) {
errorPrint(argsHandler.errorMessage());
- std::cout << "Note: use --help option for more information." << std::endl;
+ std::cout << helpHint;
+ return EXIT_FAILURE;
+ }
+
+ if (typeSystemFileName.isEmpty()) {
+ std::cout << "You must specify a Type System file." << std::endl << helpHint;
return EXIT_FAILURE;
}
diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
index 02fd40354..014b44476 100644
--- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
+++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
@@ -1697,19 +1697,18 @@ bool QtDocGenerator::doSetup(const QMap<QString, QString>& args)
}
-QMap<QString, QString> QtDocGenerator::options() const
+Generator::OptionDescriptions QtDocGenerator::options() const
{
- QMap<QString, QString> options;
- options.insert(QLatin1String("doc-parser"),
- QLatin1String("The documentation parser used to interpret the documentation input files (qdoc3|doxygen)"));
- options.insert(QLatin1String("library-source-dir"),
- QLatin1String("Directory where library source code is located"));
- options.insert(QLatin1String("documentation-data-dir"),
- QLatin1String("Directory with XML files generated by documentation tool (qdoc3 or Doxygen)"));
- options.insert(QLatin1String("documentation-code-snippets-dir"),
- QLatin1String("Directory used to search code snippets used by the documentation"));
- options.insert(QLatin1String("documentation-extra-sections-dir"),
- QLatin1String("Directory used to search for extra documentation sections"));
- return options;
+ return OptionDescriptions()
+ << qMakePair(QLatin1String("doc-parser"),
+ QLatin1String("The documentation parser used to interpret the documentation input files (qdoc3|doxygen)"))
+ << qMakePair(QLatin1String("documentation-code-snippets-dir"),
+ QLatin1String("Directory used to search code snippets used by the documentation"))
+ << qMakePair(QLatin1String("documentation-data-dir"),
+ QLatin1String("Directory with XML files generated by documentation tool (qdoc3 or Doxygen)"))
+ << qMakePair(QLatin1String("documentation-extra-sections-dir"),
+ QLatin1String("Directory used to search for extra documentation sections"))
+ << qMakePair(QLatin1String("library-source-dir"),
+ QLatin1String("Directory where library source code is located"));
}
diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.h b/sources/shiboken2/generator/qtdoc/qtdocgenerator.h
index fa8524b21..6ba9e7907 100644
--- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.h
+++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.h
@@ -186,7 +186,7 @@ public:
return "QtDocGenerator";
}
- QMap<QString, QString> options() const;
+ OptionDescriptions options() const;
QStringList codeSnippetDirs() const
{
diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.h b/sources/shiboken2/generator/shiboken2/headergenerator.h
index 5c1ffec35..d9dc8ffe8 100644
--- a/sources/shiboken2/generator/shiboken2/headergenerator.h
+++ b/sources/shiboken2/generator/shiboken2/headergenerator.h
@@ -41,7 +41,7 @@ class AbstractMetaFunction;
class HeaderGenerator : public ShibokenGenerator
{
public:
- QMap<QString, QString> options() const override { return QMap<QString, QString>(); }
+ OptionDescriptions options() const override { return OptionDescriptions(); }
protected:
QString fileNamePrefix() const override;
QString fileNameForContext(GeneratorContext &context) const override;
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
index fb9946be1..2693ecf40 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
@@ -2446,22 +2446,21 @@ QPair< int, int > ShibokenGenerator::getMinMaxArguments(const AbstractMetaFuncti
return qMakePair(minArgs, maxArgs);
}
-QMap<QString, QString> ShibokenGenerator::options() const
-{
- QMap<QString, QString> opts(Generator::options());
- opts.insert(QLatin1String(AVOID_PROTECTED_HACK),
- QLatin1String("Avoid the use of the '#define protected public' hack."));
- opts.insert(QLatin1String(PARENT_CTOR_HEURISTIC),
- QLatin1String("Enable heuristics to detect parent relationship on constructors."));
- opts.insert(QLatin1String(RETURN_VALUE_HEURISTIC),
- QLatin1String("Enable heuristics to detect parent relationship on return values (USE WITH CAUTION!)"));
- opts.insert(QLatin1String(ENABLE_PYSIDE_EXTENSIONS),
- QLatin1String("Enable PySide extensions, such as support for signal/slots, use this if you are creating a binding for a Qt-based library."));
- opts.insert(QLatin1String(DISABLE_VERBOSE_ERROR_MESSAGES),
- QLatin1String("Disable verbose error messages. Turn the python code hard to debug but safe few kB on the generated bindings."));
- opts.insert(QLatin1String(USE_ISNULL_AS_NB_NONZERO),
- QLatin1String("If a class have an isNull()const method, it will be used to compute the value of boolean casts"));
- return opts;
+Generator::OptionDescriptions ShibokenGenerator::options() const
+{
+ return OptionDescriptions()
+ << qMakePair(QLatin1String(AVOID_PROTECTED_HACK),
+ QLatin1String("Avoid the use of the '#define protected public' hack."))
+ << qMakePair(QLatin1String(DISABLE_VERBOSE_ERROR_MESSAGES),
+ QLatin1String("Disable verbose error messages. Turn the python code hard to debug but safe few kB on the generated bindings."))
+ << qMakePair(QLatin1String(PARENT_CTOR_HEURISTIC),
+ QLatin1String("Enable heuristics to detect parent relationship on constructors."))
+ << qMakePair(QLatin1String(ENABLE_PYSIDE_EXTENSIONS),
+ QLatin1String("Enable PySide extensions, such as support for signal/slots, use this if you are creating a binding for a Qt-based library."))
+ << qMakePair(QLatin1String(RETURN_VALUE_HEURISTIC),
+ QLatin1String("Enable heuristics to detect parent relationship on return values (USE WITH CAUTION!)"))
+ << qMakePair(QLatin1String(USE_ISNULL_AS_NB_NONZERO),
+ QLatin1String("If a class have an isNull()const method, it will be used to compute the value of boolean casts"));
}
static void getCode(QStringList& code, const CodeSnipList& codeSnips)
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.h b/sources/shiboken2/generator/shiboken2/shibokengenerator.h
index 1be56edc8..497ff4e34 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.h
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.h
@@ -429,7 +429,7 @@ public:
QString extendedIsConvertibleFunctionName(const TypeEntry* targetType) const;
QString extendedToCppFunctionName(const TypeEntry* targetType) const;
- QMap< QString, QString > options() const override;
+ OptionDescriptions options() const override;
/// Returns true if the user enabled the so called "parent constructor heuristic".
bool useCtorHeuristic() const;