summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@theqtcompany.com>2016-04-14 11:40:34 +0200
committerChristian Kandeler <christian.kandeler@theqtcompany.com>2016-04-14 10:29:48 +0000
commitde21bd6cb84dded97aaf3260f3f727cea7e7f678 (patch)
tree2888cfa74d770c0155b44d55eebf8a5dec0d7bbd
parenta48d3e9d28274a9f3e6ce8415c3344ba01acc51a (diff)
downloadqbs-de21bd6cb84dded97aaf3260f3f727cea7e7f678.tar.gz
Respect Probe conditions.
Apparently, we've never tested the conditions of Probe items, so the configure script was always run. Change-Id: I7e4bff6843de8a1f8eae35dd54282ab4de2a5cee Reviewed-by: Jake Petroules <jake.petroules@qt.io>
-rw-r--r--share/qbs/modules/bundle/BundleModule.qbs2
-rw-r--r--src/lib/corelib/language/moduleloader.cpp15
-rw-r--r--src/lib/corelib/language/testdata/throwing-probe.qbs12
-rw-r--r--src/lib/corelib/language/tst_language.cpp25
-rw-r--r--src/lib/corelib/language/tst_language.h2
5 files changed, 51 insertions, 5 deletions
diff --git a/share/qbs/modules/bundle/BundleModule.qbs b/share/qbs/modules/bundle/BundleModule.qbs
index ab66d8d79..88fb6ecd6 100644
--- a/share/qbs/modules/bundle/BundleModule.qbs
+++ b/share/qbs/modules/bundle/BundleModule.qbs
@@ -71,8 +71,6 @@ Module {
property var xcodeSettings: ({})
configure: {
- if (!qbs.targetOS.contains("darwin")) // TODO: Remove when probe conditions are working
- return;
var specsPath = path;
var specsSeparator = "-";
if (xcodeDeveloperPath && _useXcodeBuildSpecs) {
diff --git a/src/lib/corelib/language/moduleloader.cpp b/src/lib/corelib/language/moduleloader.cpp
index ebd8dc67f..8560929e8 100644
--- a/src/lib/corelib/language/moduleloader.cpp
+++ b/src/lib/corelib/language/moduleloader.cpp
@@ -1533,6 +1533,7 @@ void ModuleLoader::resolveProbes(Item *item)
void ModuleLoader::resolveProbe(Item *parent, Item *probe)
{
+ m_logger.qbsTrace() << "Resolving Probe at " << probe->location().toString();
const JSSourceValueConstPtr configureScript = probe->sourceProperty(QLatin1String("configure"));
if (Q_UNLIKELY(!configureScript))
throw ErrorInfo(Tr::tr("Probe.configure must be set."), probe->location());
@@ -1551,9 +1552,15 @@ void ModuleLoader::resolveProbe(Item *parent, Item *probe)
m_engine->currentContext()->pushScope(scope);
foreach (const ProbeProperty &b, probeBindings)
scope.setProperty(b.first, b.second);
- QScriptValue sv = m_engine->evaluate(configureScript->sourceCodeForEvaluation());
- if (Q_UNLIKELY(m_engine->hasErrorOrException(sv)))
- throw ErrorInfo(m_engine->lastErrorString(sv), configureScript->location());
+ const bool runProbe = m_evaluator->boolValue(probe, QLatin1String("condition"));
+ ErrorInfo evalError;
+ if (runProbe) {
+ QScriptValue sv = m_engine->evaluate(configureScript->sourceCodeForEvaluation());
+ if (Q_UNLIKELY(m_engine->hasErrorOrException(sv)))
+ evalError = ErrorInfo(m_engine->lastErrorString(sv), configureScript->location());
+ } else {
+ m_logger.qbsDebug() << "Probe disabled; skipping";
+ }
foreach (const ProbeProperty &b, probeBindings) {
const QVariant newValue = scope.property(b.first).toVariant();
if (newValue != b.second.toVariant())
@@ -1562,6 +1569,8 @@ void ModuleLoader::resolveProbe(Item *parent, Item *probe)
m_engine->currentContext()->popScope();
m_engine->currentContext()->popScope();
m_engine->currentContext()->popScope();
+ if (evalError.hasError())
+ throw evalError;
}
void ModuleLoader::checkCancelation() const
diff --git a/src/lib/corelib/language/testdata/throwing-probe.qbs b/src/lib/corelib/language/testdata/throwing-probe.qbs
new file mode 100644
index 000000000..7f4a77a57
--- /dev/null
+++ b/src/lib/corelib/language/testdata/throwing-probe.qbs
@@ -0,0 +1,12 @@
+import qbs
+
+Product {
+ name: "theProduct"
+ property bool enableProbe
+ Probe {
+ condition: enableProbe
+ configure: {
+ throw "Error!";
+ }
+ }
+}
diff --git a/src/lib/corelib/language/tst_language.cpp b/src/lib/corelib/language/tst_language.cpp
index 31d21c35c..702af884e 100644
--- a/src/lib/corelib/language/tst_language.cpp
+++ b/src/lib/corelib/language/tst_language.cpp
@@ -1595,6 +1595,31 @@ void TestLanguage::relaxedErrorMode_data()
QTest::newRow("relaxed mode") << false;
}
+void TestLanguage::throwingProbe()
+{
+ QFETCH(bool, enableProbe);
+ try {
+ SetupProjectParameters params = defaultParameters;
+ params.setProjectFilePath(testProject("throwing-probe.qbs"));
+ QVariantMap properties;
+ properties.insert(QLatin1String("theProduct.enableProbe"), enableProbe);
+ params.setOverriddenValues(properties);
+ const TopLevelProjectPtr project = loader->loadProject(params);
+ QVERIFY(project);
+ QVERIFY(!enableProbe);
+ } catch (const ErrorInfo &e) {
+ QVERIFY2(enableProbe, qPrintable(e.toString()));
+ }
+}
+
+void TestLanguage::throwingProbe_data()
+{
+ QTest::addColumn<bool>("enableProbe");
+
+ QTest::newRow("enabled probe") << true;
+ QTest::newRow("disabled probe") << false;
+}
+
void TestLanguage::qualifiedId()
{
QString str = "foo.bar.baz";
diff --git a/src/lib/corelib/language/tst_language.h b/src/lib/corelib/language/tst_language.h
index 93ae173ea..60a1f08f8 100644
--- a/src/lib/corelib/language/tst_language.h
+++ b/src/lib/corelib/language/tst_language.h
@@ -113,6 +113,8 @@ private slots:
void qbsPropertiesInProjectCondition();
void relaxedErrorMode();
void relaxedErrorMode_data();
+ void throwingProbe();
+ void throwingProbe_data();
void defaultValue();
void defaultValue_data();
void qualifiedId();