summaryrefslogtreecommitdiff
path: root/src/lib/corelib/language/scriptengine.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2016-11-07 13:34:54 +0100
committerJoerg Bornemann <joerg.bornemann@qt.io>2016-11-11 10:33:24 +0000
commitab14d325eaa1ee762dacc8b9fbbc902dae4d5e6e (patch)
tree6f8d2e8c15376eaf6cf1795bcf5506034faa7180 /src/lib/corelib/language/scriptengine.cpp
parent18ea9077c0aff50ae1d891bea4d4bbe2ba20bab7 (diff)
downloadqbs-ab14d325eaa1ee762dacc8b9fbbc902dae4d5e6e.tar.gz
Warn against possibly improper use of JS extensions in qbs project files
For instance, we inform users when they are doing potentially slow File I/O operations during project resolving and advise them to use a Probe instead. Task-number: QBS-1033 Change-Id: I3e9d0eb36c6ddebc5f4a112c329f96d25856ac0a Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/lib/corelib/language/scriptengine.cpp')
-rw-r--r--src/lib/corelib/language/scriptengine.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/lib/corelib/language/scriptengine.cpp b/src/lib/corelib/language/scriptengine.cpp
index b383504b8..3e83fe6cb 100644
--- a/src/lib/corelib/language/scriptengine.cpp
+++ b/src/lib/corelib/language/scriptengine.cpp
@@ -159,6 +159,37 @@ void ScriptEngine::clearImportsCache()
m_jsImportCache.clear();
}
+void ScriptEngine::checkContext(const QString &operation,
+ const DubiousContextList &dubiousContexts)
+{
+ for (auto it = dubiousContexts.cbegin(); it != dubiousContexts.cend(); ++it) {
+ const DubiousContext &info = *it;
+ if (info.context != evalContext())
+ continue;
+ QString warning;
+ switch (info.context) {
+ case EvalContext::PropertyEvaluation:
+ warning = Tr::tr("Suspicious use of %1 during property evaluation.").arg(operation);
+ if (info.suggestion == DubiousContext::SuggestMoving)
+ warning += QLatin1Char(' ') + Tr::tr("Should this call be in a Probe instead?");
+ break;
+ case EvalContext::RuleExecution:
+ warning = Tr::tr("Suspicious use of %1 during rule execution.").arg(operation);
+ if (info.suggestion == DubiousContext::SuggestMoving) {
+ warning += QLatin1Char(' ')
+ + Tr::tr("Should this call be in a JavaScriptCommand instead?");
+ }
+ break;
+ case EvalContext::ProbeExecution:
+ case EvalContext::JsCommand:
+ QBS_ASSERT(false, continue);
+ break;
+ }
+ m_logger.printWarning(ErrorInfo(warning, currentContext()->backtrace()));
+ return;
+ }
+}
+
void ScriptEngine::addPropertyRequestedFromArtifact(const Artifact *artifact,
const Property &property)
{