aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-01-10 20:20:11 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-01-25 08:32:20 -0300
commita2318f763a91bc7c47bb751e39036ab95f4b45fc (patch)
tree444b617b85bc0ca356938ec06b73f95f78c57243
parente674a8ddbc11e51f3f701e8ab7783aefec8cfeec (diff)
Added the "project-file" command line option.
The project file is a XML that provides the same options that could be provided via command line. Command line arguments added by further modules will be converted into xml tags on the project file following this rule: GENERATOR --new-boolean-option --new-option=SOMETHING in XML turns into: <new-boolean-option /> <new-option value="SOMETHING />
-rw-r--r--CMakeLists.txt6
-rw-r--r--main.cpp93
2 files changed, 93 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5de216a8a..7a0d16074 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -59,7 +59,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${APIEXTRACTOR_INCLUDE_DIR}
${QT_INCLUDE_DIR}
- ${QT_QTCORE_INCLUDE_DIR})
+ ${QT_QTCORE_INCLUDE_DIR}
+ ${QT_QTXML_INCLUDE_DIR})
add_library(genrunner SHARED generator.cpp)
set_target_properties(genrunner PROPERTIES VERSION ${generator_VERSION} DEFINE_SYMBOL GENRUNNER_EXPORTS)
@@ -73,7 +74,8 @@ set_target_properties(generatorrunner PROPERTIES OUTPUT_NAME generatorrunner${ge
target_link_libraries(generatorrunner
genrunner
${APIEXTRACTOR_LIBRARY}
- ${QT_QTCORE_LIBRARY})
+ ${QT_QTCORE_LIBRARY}
+ ${QT_QTXML_LIBRARY})
# uninstall target
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake"
diff --git a/main.cpp b/main.cpp
index 9397ba87c..782f6b514 100644
--- a/main.cpp
+++ b/main.cpp
@@ -24,6 +24,7 @@
#include <QCoreApplication>
#include <QLinkedList>
#include <QLibrary>
+#include <QDomDocument>
#include <iostream>
#include <apiextractor.h>
#include "generatorrunnerconfig.h"
@@ -49,12 +50,95 @@ static void printOptions(QTextStream& s, const QMap<QString, QString>& options)
typedef void (*getGeneratorsFunc)(QLinkedList<Generator*>*);
-QMap<QString, QString> getCommandLineArgs(int argc, char** argv)
+static QString getPathString(const QDomElement& element)
+{
+ QStringList path;
+ QDomNode n = element.firstChild();
+ while (!n.isNull()) {
+ QDomElement e = n.toElement(); // try to convert the node to an element.
+ if (e.tagName() == "path")
+ path << QDir::toNativeSeparators(e.attribute("location"));
+ n = n.nextSibling();
+ }
+ return path.join(PATH_SPLITTER);
+}
+
+static QMap<QString, QString> getInitializedArguments()
{
QMap<QString, QString> args;
+ QStringList arguments = QCoreApplication::arguments();
+ QString appName = arguments.first();
+ arguments.removeFirst();
+
+ QString projectFileName;
+ foreach (const QString& arg, arguments) {
+ if (arg.startsWith("--project-file")) {
+ int split = arg.indexOf("=");
+ if (split > 0)
+ projectFileName = arg.mid(split + 1).trimmed();
+ break;
+ }
+ }
+
+ if (projectFileName.isNull())
+ return args;
+
+ if (!QFile::exists(projectFileName)) {
+ std::cerr << qPrintable(appName) << ": Project file \"" << qPrintable(projectFileName) << "\" not found." << std::endl;
+ return args;
+ }
+
+ QFile projectFile(projectFileName);
+ if (!projectFile.open(QIODevice::ReadOnly))
+ return args;
+
+ QDomDocument doc("project-file");
+ if (!doc.setContent(&projectFile)) {
+ projectFile.close();
+ return args;
+ }
+ projectFile.close();
+
+ QDomElement docElem = doc.documentElement();
+ QDomNode n = docElem.firstChild();
+ while (!n.isNull()) {
+ QDomElement e = n.toElement(); // try to convert the node to an element.
+ if (!e.isNull()) {
+ QString tag = e.tagName();
+ if (tag == "generator-set")
+ args[tag] = e.attribute("generator");
+ else if (tag == "output-directory" || tag == "license-file")
+ args[tag] = e.attribute("location");
+ else if (tag == "api-version")
+ args[tag] = e.attribute("version");
+ else if (tag == "debug")
+ args[tag] = e.attribute("level");
+ else if (tag == "documentation-only" || tag == "no-suppress-warnings" || tag == "silent")
+ args[tag] = QString();
+ else if (tag == "include-paths" || tag == "typesystem-paths")
+ args[tag] = getPathString(e);
+ else if (tag == "header-file")
+ args["arg-1"] = e.attribute("location");
+ else if (tag == "typesystem-file")
+ args["arg-2"] = e.attribute("location");
+ else
+ args[tag] = e.attribute("value");
+ }
+ n = n.nextSibling();
+ }
+
+ return args;
+}
+
+static QMap<QString, QString> getCommandLineArgs()
+{
+ QMap<QString, QString> args = getInitializedArguments();
+
+ QStringList arguments = QCoreApplication::arguments();
+ arguments.removeFirst();
+
int argNum = 0;
- for (int i = 1; i < argc; ++i) {
- QString arg(argv[i]);
+ foreach (QString arg, arguments) {
arg = arg.trimmed();
if (arg.startsWith("--")) {
int split = arg.indexOf("=");
@@ -79,6 +163,7 @@ void printUsage(const GeneratorList& generators)
<< "generator [options] header-file typesystem-file\n\n"
"General options:\n";
QMap<QString, QString> generalOptions;
+ generalOptions.insert("project-file=[file]", "XML file containing a description of the binding project. Replaces and overrides command line arguments");
generalOptions.insert("debug-level=[sparse|medium|full]", "Set the debug level");
generalOptions.insert("silent", "Avoid printing any message");
generalOptions.insert("help", "Display this help and exit");
@@ -108,7 +193,7 @@ int main(int argc, char *argv[])
QCoreApplication app(argc, argv);
// Store command arguments in a map
- QMap<QString, QString> args = getCommandLineArgs(argc, argv);
+ QMap<QString, QString> args = getCommandLineArgs();
GeneratorList generators;
if (args.contains("version")) {