From d07c24c701963ac0eaf1e7fb1774efcf2ee4dee3 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 17 Oct 2016 12:20:01 +0200 Subject: Add support for the QtScxml module [ChangeLog] Added support for QtScxml module. Change-Id: I1ad8d51a3d9532d4a24270e4cc13f26f51620b07 Reviewed-by: Jake Petroules --- doc/reference/modules/qt-modules.qdoc | 52 +++++++++++++++++ src/lib/qtprofilesetup/qtprofilesetup.cpp | 2 + src/lib/qtprofilesetup/templates.qrc | 1 + src/lib/qtprofilesetup/templates/scxml.qbs | 68 ++++++++++++++++++++++ .../testdata/qtscxml/dummystatemachine.scxml | 3 + tests/auto/blackbox/testdata/qtscxml/main.cpp | 15 +++++ tests/auto/blackbox/testdata/qtscxml/qtscxml.qbs | 52 +++++++++++++++++ tests/auto/blackbox/tst_blackbox.cpp | 10 ++++ tests/auto/blackbox/tst_blackbox.h | 1 + 9 files changed, 204 insertions(+) create mode 100644 src/lib/qtprofilesetup/templates/scxml.qbs create mode 100644 tests/auto/blackbox/testdata/qtscxml/dummystatemachine.scxml create mode 100644 tests/auto/blackbox/testdata/qtscxml/main.cpp create mode 100644 tests/auto/blackbox/testdata/qtscxml/qtscxml.qbs diff --git a/doc/reference/modules/qt-modules.qdoc b/doc/reference/modules/qt-modules.qdoc index f0e2c8954..d9704b8d0 100644 --- a/doc/reference/modules/qt-modules.qdoc +++ b/doc/reference/modules/qt-modules.qdoc @@ -152,6 +152,14 @@ \li script \li Qt Script \li + \row + \li scxml + \li Qt Scxml + \li For more information on the properties you can specify, see + \l{scxml Properties}. + + For more information on the relevant file tags, see + \l {scxml File Tags}. \row \li sql \li Qt SQL @@ -452,6 +460,33 @@ \endtable + \section2 scxml Properties + + \table + \header + \li Property + \li Type + \li Default + \li Description + \row + \li className + \li \c{string} + \li \c undefined + \li The class name of the generated state machine. By default, the compiler will use the + \c name attribute of the input file's \c{} tag. + \row + \li namespace + \li \c{string} + \li \c undefined + \li The C++ namespace in which to put the generated class. By default, the compiler will + place the class in the global namespace. + \row + \li qscxmlcName + \li \c{string} + \li \c{"qscxmlc"} + \li The base name of the Qt SCXML compiler. Set this if your system uses a different name. + \endtable + \section1 Relevant File Tags The following sections describe the file tags that are relevant for the Qt @@ -559,4 +594,21 @@ \li 1.0 \li Source files with this tag serve as inputs to the rule running the \c uic tool. \endtable + + \section2 scxml File Tags + + \table + \header + \li Tag + \li Auto-tagged File Names + \li Since + \li Description + \row + \li \c{"qt.scxml.compilable"} + \li - + \li 1.7 + \li Source files with this tag serve as inputs to the rule running the Qt SCXML compiler, + which will create a C++ class representing a state machine. + \endtable + */ diff --git a/src/lib/qtprofilesetup/qtprofilesetup.cpp b/src/lib/qtprofilesetup/qtprofilesetup.cpp index ca45bfa86..23aa658af 100644 --- a/src/lib/qtprofilesetup/qtprofilesetup.cpp +++ b/src/lib/qtprofilesetup/qtprofilesetup.cpp @@ -222,6 +222,8 @@ static void createModules(Profile &profile, Settings *settings, &allFiles); } else if (module.qbsName == QLatin1String("gui")) { moduleTemplateFileName = QLatin1String("gui.qbs"); + } else if (module.qbsName == QLatin1String("scxml")) { + moduleTemplateFileName = QLatin1String("scxml.qbs"); } else if (module.qbsName == QLatin1String("dbus")) { moduleTemplateFileName = QLatin1String("dbus.qbs"); copyTemplateFile(QLatin1String("dbus.js"), qbsQtModuleDir, profile, qtEnvironment, diff --git a/src/lib/qtprofilesetup/templates.qrc b/src/lib/qtprofilesetup/templates.qrc index 257e89a54..bcbf2bd67 100644 --- a/src/lib/qtprofilesetup/templates.qrc +++ b/src/lib/qtprofilesetup/templates.qrc @@ -11,5 +11,6 @@ templates/QtPlugin.qbs templates/dbus.js templates/dbus.qbs + templates/scxml.qbs diff --git a/src/lib/qtprofilesetup/templates/scxml.qbs b/src/lib/qtprofilesetup/templates/scxml.qbs new file mode 100644 index 000000000..206d914a2 --- /dev/null +++ b/src/lib/qtprofilesetup/templates/scxml.qbs @@ -0,0 +1,68 @@ +import qbs 1.0 +import qbs.FileInfo +import "../QtModule.qbs" as QtModule + +QtModule { + qtModuleName: "Scxml" + + property string qscxmlcName: "qscxmlc" + property string className + property string namespace + + Rule { + inputs: ["qt.scxml.compilable"] + + Artifact { + filePath: FileInfo.joinPaths(product.moduleProperty("Qt.core", "generatedHeadersDir"), + input.baseName + ".h") + fileTags: ["hpp", "unmocable"] + } + Artifact { + filePath: input.baseName + ".cpp" + fileTags: ["cpp"] + } + + prepare: { + var compilerName = product.moduleProperty("Qt.scxml", "qscxmlcName"); + var compilerPath = FileInfo.joinPaths(input.moduleProperty("Qt.core", "binPath"), + compilerName); + var args = ["--header", outputs["hpp"][0].filePath, + "--impl", outputs["cpp"][0].filePath]; + var cxx98 = input.moduleProperty("cpp", "cxxLanguageVersion") === "c++98"; + if (cxx98) + args.push("-no-c++11"); + var className = input.moduleProperty("Qt.scxml", "className"); + if (className) + args.push("--classname", className); + var namespace = input.moduleProperty("Qt.scxml", "namespace"); + if (namespace) + args.push("--namespace", namespace); + args.push(input.filePath); + var cmd = new Command(compilerPath, args); + cmd.description = "compiling " + input.fileName; + cmd.highlight = "codegen"; + return [cmd]; + } + } + + staticLibsDebug: @staticLibsDebug@ + staticLibsRelease: @staticLibsRelease@ + dynamicLibsDebug: @dynamicLibsDebug@ + dynamicLibsRelease: @dynamicLibsRelease@ + linkerFlagsDebug: @linkerFlagsDebug@ + linkerFlagsRelease: @linkerFlagsRelease@ + frameworksDebug: @frameworksDebug@ + frameworksRelease: @frameworksRelease@ + frameworkPathsDebug: @frameworkPathsDebug@ + frameworkPathsRelease: @frameworkPathsRelease@ + libNameForLinkerDebug: @libNameForLinkerDebug@ + libNameForLinkerRelease: @libNameForLinkerRelease@ + libFilePathDebug: @libFilePathDebug@ + libFilePathRelease: @libFilePathRelease@ + + cpp.defines: @defines@ + cpp.includePaths: @includes@ + cpp.libraryPaths: @libraryPaths@ + + @special_properties@ +} diff --git a/tests/auto/blackbox/testdata/qtscxml/dummystatemachine.scxml b/tests/auto/blackbox/testdata/qtscxml/dummystatemachine.scxml new file mode 100644 index 000000000..6c751866f --- /dev/null +++ b/tests/auto/blackbox/testdata/qtscxml/dummystatemachine.scxml @@ -0,0 +1,3 @@ + + + diff --git a/tests/auto/blackbox/testdata/qtscxml/main.cpp b/tests/auto/blackbox/testdata/qtscxml/main.cpp new file mode 100644 index 000000000..c9a7d7741 --- /dev/null +++ b/tests/auto/blackbox/testdata/qtscxml/main.cpp @@ -0,0 +1,15 @@ +#ifdef HAS_QTSCXML +#include +#endif + +#include + +int main() +{ +#ifdef HAS_QTSCXML + QbsTest::QbsStateMachine machine; + std::cout << "state machine name: " << qPrintable(machine.name()) << std::endl; +#else + std::cout << "QtScxml not present" << std::endl; +#endif +} diff --git a/tests/auto/blackbox/testdata/qtscxml/qtscxml.qbs b/tests/auto/blackbox/testdata/qtscxml/qtscxml.qbs new file mode 100644 index 000000000..af96b8594 --- /dev/null +++ b/tests/auto/blackbox/testdata/qtscxml/qtscxml.qbs @@ -0,0 +1,52 @@ +import qbs +import qbs.FileInfo + +Project { + QtApplication { + name: "app" + Depends { name: "Qt.scxml"; required: false } + + Properties { + condition: Qt.scxml.present + cpp.defines: ["HAS_QTSCXML"] + } + + Qt.scxml.className: "QbsStateMachine" + Qt.scxml.namespace: "QbsTest" + + files: ["main.cpp"] + Group { + files: ["dummystatemachine.scxml"] + fileTags: ["qt.scxml.compilable"] + } + } + + Product { + name: "runner" + type: ["runner"] + Depends { name: "app" } + Rule { + inputsFromDependencies: ["application"] + Artifact { + filePath: "dummy" + fileTags: ["runner"] + } + prepare: { + var cmd = new Command(input.filePath); + cmd.description = "running " + input.filePath; + var pathVar; + var pathValue; + if (product.moduleProperty("qbs", "hostOS").contains("windows")) { + pathVar = "PATH"; + pathValue = FileInfo.toWindowsSeparators( + input.moduleProperty("Qt.core", "binPath")); + } else { + pathVar = "LD_LIBRARY_PATH"; + pathValue = input.moduleProperty("Qt.core", "libPath"); + } + cmd.environment = [pathVar + '=' + pathValue]; + return [cmd]; + } + } + } +} diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index 4f41cd6ea..03c1df6b0 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -2191,6 +2191,16 @@ void TestBlackbox::qtBug51237() QCOMPARE(runQbs(params), 0); } +void TestBlackbox::qtScxml() +{ + QDir::setCurrent(testDataDir + "/qtscxml"); + QCOMPARE(runQbs(), 0); + if (m_qbsStdout.contains("QtScxml not present")) + QSKIP("QtScxml module not present"); + QVERIFY2(m_qbsStdout.contains("state machine name: qbs_test_machine"), + m_qbsStdout.constData()); +} + void TestBlackbox::dynamicMultiplexRule() { const QString testDir = testDataDir + "/dynamicMultiplexRule"; diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h index 182221b78..c7a344e60 100644 --- a/tests/auto/blackbox/tst_blackbox.h +++ b/tests/auto/blackbox/tst_blackbox.h @@ -146,6 +146,7 @@ private slots: void qmlDebugging(); void qobjectInObjectiveCpp(); void qtBug51237(); + void qtScxml(); void radAfterIncompleteBuild(); void radAfterIncompleteBuild_data(); void recursiveRenaming(); -- cgit v1.2.3