diff options
| author | Joerg Bornemann <joerg.bornemann@digia.com> | 2013-09-24 12:22:48 +0200 |
|---|---|---|
| committer | Joerg Bornemann <joerg.bornemann@digia.com> | 2013-09-24 15:01:59 +0200 |
| commit | 543a38424a98bb72b8cf34bacbd3ff552a306776 (patch) | |
| tree | e6f4a9d2bf041dc007dff033a32b24ed2340504f /src/lib/buildgraph/rulesapplicator.cpp | |
| parent | 6a3f198e1a8beebc8cc1cf560016125efc60970b (diff) | |
| download | qbs-543a38424a98bb72b8cf34bacbd3ff552a306776.tar.gz | |
fix calling of prepare script function
The scope that contains inputs, outputs and friends was bound to the
function object, which is wrong when applying the function later on.
Instead, we're passing those variables as function arguments now.
Change-Id: I7ad7b6a742091fae889ed57b7c9cbceea4a2ead2
Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
Diffstat (limited to 'src/lib/buildgraph/rulesapplicator.cpp')
| -rw-r--r-- | src/lib/buildgraph/rulesapplicator.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/lib/buildgraph/rulesapplicator.cpp b/src/lib/buildgraph/rulesapplicator.cpp index d057c3cfb..70de2bc17 100644 --- a/src/lib/buildgraph/rulesapplicator.cpp +++ b/src/lib/buildgraph/rulesapplicator.cpp @@ -67,30 +67,35 @@ void RulesApplicator::applyAllRules() void RulesApplicator::applyRule(const RuleConstPtr &rule) { m_rule = rule; - QScriptValue scopeValue = scope(); - setupScriptEngineForProduct(engine(), m_product, m_rule, scopeValue, this); - Q_ASSERT_X(scope().property("product").strictlyEquals(engine()->evaluate("product")), - "BG", "Product object is not in current scope."); - m_productObjectId = scopeValue.property(QLatin1String("product")).objectId(); + QScriptValue prepareScriptContext = engine()->newObject(); + setupScriptEngineForFile(engine(), m_rule->script->fileContext, scope()); + setupScriptEngineForProduct(engine(), m_product, m_rule, prepareScriptContext, this); + m_productObjectId = prepareScriptContext.property(QLatin1String("product")).objectId(); ArtifactList inputArtifacts; foreach (const FileTag &fileTag, m_rule->inputs) inputArtifacts.unite(m_artifactsPerFileTag.value(fileTag)); if (m_rule->multiplex) { // apply the rule once for a set of inputs if (!inputArtifacts.isEmpty()) - doApply(inputArtifacts); + doApply(inputArtifacts, prepareScriptContext); } else { // apply the rule once for each input ArtifactList lst; foreach (Artifact * const inputArtifact, inputArtifacts) { setupScriptEngineForArtifact(inputArtifact); lst += inputArtifact; - doApply(lst); + doApply(lst, prepareScriptContext); lst.clear(); } } } -void RulesApplicator::doApply(const ArtifactList &inputArtifacts) +static void copyProperty(const QString &name, const QScriptValue &src, QScriptValue dst) +{ + dst.setProperty(name, src.property(name)); +} + +void RulesApplicator::doApply(const ArtifactList &inputArtifacts, + QScriptValue &prepareScriptContext) { evalContext()->checkForCancelation(); @@ -119,6 +124,8 @@ void RulesApplicator::doApply(const ArtifactList &inputArtifacts) m_transformer.clear(); // create the output artifacts from the set of input artifacts + copyProperty(QLatin1String("product"), prepareScriptContext, scope()); + copyProperty(QLatin1String("project"), prepareScriptContext, scope()); foreach (const RuleArtifactConstPtr &ruleArtifact, m_rule->artifacts) { Artifact * const outputArtifact = createOutputArtifact(ruleArtifact, inputArtifacts); outputArtifacts << outputArtifact; @@ -149,10 +156,12 @@ void RulesApplicator::doApply(const ArtifactList &inputArtifacts) -= outputArtifact; } - m_transformer->setupInputs(engine(), scope()); + m_transformer->setupInputs(engine(), prepareScriptContext); // change the transformer outputs according to the bindings in Artifact QScriptValue scriptValue; + if (!ruleArtifactArtifactMap.isEmpty()) + engine()->currentContext()->pushScope(prepareScriptContext); for (int i = ruleArtifactArtifactMap.count(); --i >= 0;) { const RuleArtifact *ra = ruleArtifactArtifactMap.at(i).first; if (ra->bindings.isEmpty()) @@ -180,9 +189,12 @@ void RulesApplicator::doApply(const ArtifactList &inputArtifacts) outputArtifactConfig.insert("modules", artifactModulesCfg); outputArtifact->properties->setValue(outputArtifactConfig); } + if (!ruleArtifactArtifactMap.isEmpty()) + engine()->currentContext()->popScope(); - m_transformer->setupOutputs(engine(), scope()); - m_transformer->createCommands(m_rule->script, evalContext()); + m_transformer->setupOutputs(engine(), prepareScriptContext); + m_transformer->createCommands(m_rule->script, evalContext(), + ScriptEngine::argumentList(m_rule->script->argumentNames, prepareScriptContext)); if (Q_UNLIKELY(m_transformer->commands.isEmpty())) throw ErrorInfo(QString("There's a rule without commands: %1.").arg(m_rule->toString()), m_rule->script->location); } |
