diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2017-11-14 16:07:28 +0100 |
---|---|---|
committer | Jake Petroules <jake.petroules@qt.io> | 2017-11-15 11:56:53 +0000 |
commit | 9da21f445ff860ece50036326e23c232f64ac15e (patch) | |
tree | 79affb607296f767b009dc053abe2261d49fa1f5 /src/lib | |
parent | 6e9ac907c5427fdf5f764a5736e9edf4db8d49d2 (diff) | |
download | qbs-9da21f445ff860ece50036326e23c232f64ac15e.tar.gz |
Do not store argument names in ScriptFunction objects
These are fixed and always available from the calling context.
Change-Id: Ibdf55de1fdb0c1819ae8afa6d44e54ebb3e126d7
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/corelib/buildgraph/rulesapplicator.cpp | 5 | ||||
-rw-r--r-- | src/lib/corelib/language/language.cpp | 28 | ||||
-rw-r--r-- | src/lib/corelib/language/language.h | 6 | ||||
-rw-r--r-- | src/lib/corelib/language/projectresolver.cpp | 1 | ||||
-rw-r--r-- | src/lib/corelib/tools/persistence.cpp | 2 |
5 files changed, 33 insertions, 9 deletions
diff --git a/src/lib/corelib/buildgraph/rulesapplicator.cpp b/src/lib/corelib/buildgraph/rulesapplicator.cpp index 8f979b2fa..3bac97e7e 100644 --- a/src/lib/corelib/buildgraph/rulesapplicator.cpp +++ b/src/lib/corelib/buildgraph/rulesapplicator.cpp @@ -183,8 +183,7 @@ void RulesApplicator::doApply(const ArtifactSet &inputArtifacts, QScriptValue &p copyProperty(QLatin1String("project"), prepareScriptContext, scope()); if (m_rule->isDynamic()) { outputArtifacts = runOutputArtifactsScript(inputArtifacts, - ScriptEngine::argumentList(m_rule->outputArtifactsScript->argumentNames, - scope())); + ScriptEngine::argumentList(Rule::argumentNamesForOutputArtifacts(), scope())); ArtifactSet newOutputs = ArtifactSet::fromList(outputArtifacts); const ArtifactSet oldOutputs = collectOldOutputArtifacts(inputArtifacts); handleRemovedRuleOutputs(m_completeInputSet, oldOutputs - newOutputs, m_logger); @@ -249,7 +248,7 @@ void RulesApplicator::doApply(const ArtifactSet &inputArtifacts, QScriptValue &p m_transformer->setupOutputs(prepareScriptContext); m_transformer->createCommands(engine(), m_rule->prepareScript, - ScriptEngine::argumentList(m_rule->prepareScript->argumentNames, prepareScriptContext)); + ScriptEngine::argumentList(Rule::argumentNamesForPrepare(), prepareScriptContext)); if (Q_UNLIKELY(m_transformer->commands.isEmpty())) throw ErrorInfo(Tr::tr("There is a rule without commands: %1.") .arg(m_rule->toString()), m_rule->prepareScript->location); diff --git a/src/lib/corelib/language/language.cpp b/src/lib/corelib/language/language.cpp index b839c8e28..1c0006bcc 100644 --- a/src/lib/corelib/language/language.cpp +++ b/src/lib/corelib/language/language.cpp @@ -40,6 +40,7 @@ #include "language.h" #include "artifactproperties.h" +#include "builtindeclarations.h" #include "propertymapinternal.h" #include "resolvedfilecontext.h" #include "scriptengine.h" @@ -328,7 +329,6 @@ bool ScriptFunction::isValid() const void ScriptFunction::load(PersistentPool &pool) { pool.load(sourceCode); - pool.load(argumentNames); location.load(pool); pool.load(fileContext); } @@ -336,7 +336,6 @@ void ScriptFunction::load(PersistentPool &pool) void ScriptFunction::store(PersistentPool &pool) const { pool.store(sourceCode); - pool.store(argumentNames); location.store(pool); pool.store(fileContext); } @@ -345,7 +344,6 @@ bool operator==(const ScriptFunction &a, const ScriptFunction &b) { return a.sourceCode == b.sourceCode && a.location == b.location - && a.argumentNames == b.argumentNames && equals(a.fileContext.get(), b.fileContext.get()); } @@ -381,6 +379,30 @@ RulePtr Rule::clone() const return std::make_shared<Rule>(*this); } +QStringList Rule::argumentNamesForOutputArtifacts() +{ + static const QStringList argNames = argumentNames(QStringLiteral("outputArtifacts")); + return argNames; +} + +QStringList Rule::argumentNamesForPrepare() +{ + static const QStringList argNames = argumentNames(QStringLiteral("prepare")); + return argNames; +} + +QStringList Rule::argumentNames(const QString &scriptName) +{ + static const ItemDeclaration ruleDecl + = BuiltinDeclarations::instance().declarationsForType(ItemType::Rule); + for (const PropertyDeclaration &propDecl : ruleDecl.properties()) { + if (propDecl.name() == scriptName) + return propDecl.functionArgumentNames(); + } + QBS_CHECK(false); + return QStringList(); +} + QString Rule::toString() const { QStringList outputTagsSorted = collectedOutputFileTags().toStringList(); diff --git a/src/lib/corelib/language/language.h b/src/lib/corelib/language/language.h index ec0598c29..7e6ac1f0f 100644 --- a/src/lib/corelib/language/language.h +++ b/src/lib/corelib/language/language.h @@ -283,7 +283,6 @@ public: ~ScriptFunction(); QString sourceCode; - QStringList argumentNames; CodeLocation location; ResolvedFileContextConstPtr fileContext; mutable QScriptValue scriptFunction; // cache @@ -355,6 +354,9 @@ public: // members that we don't need to save int ruleGraphId; + static QStringList argumentNamesForOutputArtifacts(); + static QStringList argumentNamesForPrepare(); + QString toString() const; bool acceptsAsInput(Artifact *artifact) const; FileTags staticOutputFileTags() const; @@ -364,6 +366,8 @@ public: private: Rule() : multiplex(false), alwaysRun(false), ruleGraphId(-1) {} + static QStringList argumentNames(const QString &scriptName); + void load(PersistentPool &pool); void store(PersistentPool &pool) const; }; diff --git a/src/lib/corelib/language/projectresolver.cpp b/src/lib/corelib/language/projectresolver.cpp index c69df523b..ef1168adf 100644 --- a/src/lib/corelib/language/projectresolver.cpp +++ b/src/lib/corelib/language/projectresolver.cpp @@ -845,7 +845,6 @@ ScriptFunctionPtr ProjectResolver::scriptFunctionValue(Item *item, const QString if (value) { const PropertyDeclaration decl = item->propertyDeclaration(name); script->sourceCode = sourceCodeAsFunction(value, decl); - script->argumentNames = decl.functionArgumentNames(); script->location = value->location(); script->fileContext = resolvedFileContext(value->file()); } diff --git a/src/lib/corelib/tools/persistence.cpp b/src/lib/corelib/tools/persistence.cpp index 6d803c0a0..dd1265f92 100644 --- a/src/lib/corelib/tools/persistence.cpp +++ b/src/lib/corelib/tools/persistence.cpp @@ -49,7 +49,7 @@ namespace qbs { namespace Internal { -static const char QBS_PERSISTENCE_MAGIC[] = "QBSPERSISTENCE_109"; +static const char QBS_PERSISTENCE_MAGIC[] = "QBSPERSISTENCE_110"; NoBuildGraphError::NoBuildGraphError(const QString &filePath) : ErrorInfo(Tr::tr("Build graph not found for configuration '%1'. Expected location was '%2'.") |