diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2018-08-03 10:48:10 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2018-08-03 12:43:00 +0200 |
commit | 51b63d5e805814c1ec88e4a874cd7eabd58eb20a (patch) | |
tree | 600a94fe14b9741dc58492df5300265fe284118c /src/lib/corelib/buildgraph | |
parent | ffbc37129d6a2623ddc731520baba0f4d3b6f3b1 (diff) | |
parent | 66131652f178cd1605b8a2c0ba7023392e13ad5a (diff) |
Merge 1.12 into master
Change-Id: I0ce6c28f9117f945c9fec0654bd06daf3d13ace0
Diffstat (limited to 'src/lib/corelib/buildgraph')
5 files changed, 104 insertions, 20 deletions
diff --git a/src/lib/corelib/buildgraph/artifactsscriptvalue.cpp b/src/lib/corelib/buildgraph/artifactsscriptvalue.cpp index 0fcede324..c32e95b2a 100644 --- a/src/lib/corelib/buildgraph/artifactsscriptvalue.cpp +++ b/src/lib/corelib/buildgraph/artifactsscriptvalue.cpp @@ -45,6 +45,7 @@ #include <language/language.h> #include <language/scriptengine.h> +#include <QtScript/qscriptclass.h> #include <QtScript/qscriptcontext.h> namespace qbs { @@ -52,7 +53,44 @@ namespace Internal { enum BuildGraphScriptValueCommonPropertyKeys : quint32 { CachedValueKey, - FileTagKey + FileTagKey, + ProductPtrKey, +}; + +class ArtifactsScriptClass : public QScriptClass +{ +public: + ArtifactsScriptClass(QScriptEngine *engine) : QScriptClass(engine) { } + +private: + QueryFlags queryProperty(const QScriptValue &object, const QScriptString &name, + QueryFlags flags, uint *id) override + { + getProduct(object); + qbsEngine()->setNonExistingArtifactSetRequested(m_product, name.toString()); + return QScriptClass::queryProperty(object, name, flags, id); + } + + QScriptClassPropertyIterator *newIterator(const QScriptValue &object) override + { + getProduct(object); + qbsEngine()->setArtifactsEnumerated(m_product); + return QScriptClass::newIterator(object); + } + + void getProduct(const QScriptValue &object) + { + if (m_lastObjectId != object.objectId()) { + m_lastObjectId = object.objectId(); + m_product = reinterpret_cast<const ResolvedProduct *>( + object.data().property(ProductPtrKey).toVariant().value<quintptr>()); + } + } + + ScriptEngine *qbsEngine() const { return static_cast<ScriptEngine *>(engine()); } + + qint64 m_lastObjectId = 0; + const ResolvedProduct *m_product = nullptr; }; static bool isRelevantArtifact(const ResolvedProduct *, const Artifact *artifact) @@ -74,6 +112,27 @@ static ArtifactSetByFileTag artifactsMap(const ResolvedModule *module) return artifactsMap(module->product); } +static QScriptValue createArtifactsObject(const ResolvedProduct *product, ScriptEngine *engine) +{ + QScriptClass *scriptClass = engine->artifactsScriptClass(); + if (!scriptClass) { + scriptClass = new ArtifactsScriptClass(engine); + engine->setArtifactsScriptClass(scriptClass); + } + QScriptValue artifactsObj = engine->newObject(scriptClass); + QScriptValue data = engine->newObject(); + QVariant v; + v.setValue<quintptr>(reinterpret_cast<quintptr>(product)); + data.setProperty(ProductPtrKey, engine->newVariant(v)); + artifactsObj.setData(data); + return artifactsObj; +} + +static QScriptValue createArtifactsObject(const ResolvedModule *, ScriptEngine *engine) +{ + return engine->newObject(); +} + static bool checkAndSetArtifactsMapUpToDateFlag(const ResolvedProduct *p) { return p->buildData->checkAndSetJsArtifactsMapUpToDateFlag(); @@ -119,7 +178,7 @@ template<class ProductOrModule> static QScriptValue js_artifacts( QScriptValue artifactsObj = ctx->callee().property(CachedValueKey); if (artifactsObj.isObject() && checkAndSetArtifactsMapUpToDateFlag(productOrModule)) return artifactsObj; - artifactsObj = engine->newObject(); + artifactsObj = createArtifactsObject(productOrModule, engine); ctx->callee().setProperty(CachedValueKey, artifactsObj); const auto &map = artifactsMap(productOrModule); for (auto it = map.cbegin(); it != map.cend(); ++it) { diff --git a/src/lib/corelib/buildgraph/requestedartifacts.cpp b/src/lib/corelib/buildgraph/requestedartifacts.cpp index 0028c21bb..200f226ce 100644 --- a/src/lib/corelib/buildgraph/requestedartifacts.cpp +++ b/src/lib/corelib/buildgraph/requestedartifacts.cpp @@ -95,6 +95,20 @@ void RequestedArtifacts::setArtifactsForTag(const ResolvedProduct *product, filePaths.insert(a->filePath()); } +void RequestedArtifacts::setNonExistingTagRequested(const ResolvedProduct *product, + const QString &tag) +{ + RequestedArtifactsPerProduct &ra = m_requestedArtifactsPerProduct[product->uniqueName()]; + QBS_ASSERT(!ra.allTags.empty(), ;); + Set<QString> &filePaths = ra.requestedTags[tag]; + QBS_CHECK(filePaths.empty()); +} + +void RequestedArtifacts::setArtifactsEnumerated(const ResolvedProduct *product) +{ + m_requestedArtifactsPerProduct[product->uniqueName()].artifactsEnumerated = true; +} + void RequestedArtifacts::unite(const RequestedArtifacts &other) { for (auto it = other.m_requestedArtifactsPerProduct.begin(); @@ -129,24 +143,33 @@ bool RequestedArtifacts::RequestedArtifactsPerProduct::isUpToDate( << "is now disabled"; return false; } + + if (!artifactsEnumerated && requestedTags.empty()) + return true; + const ArtifactSetByFileTag currentArtifacts = product->buildData->artifactsByFileTag(); - Set<QString> currentTags; - for (auto it = currentArtifacts.begin(); it != currentArtifacts.end(); ++it) { - const QString tagString = it.key().toString(); - currentTags.insert(tagString); - const auto reqTagsIt = requestedTags.find(tagString); - if (reqTagsIt == requestedTags.end()) - continue; + for (auto reqIt = requestedTags.cbegin(); reqIt != requestedTags.cend(); ++reqIt) { + const FileTag tag = FileTag(reqIt->first.toUtf8()); + const auto currentIt = currentArtifacts.constFind(tag); Set<QString> currentFilePathsForTag; - for (const Artifact * const a : it.value()) - currentFilePathsForTag.insert(a->filePath()); - if (currentFilePathsForTag != reqTagsIt->second) { + if (currentIt != currentArtifacts.constEnd()) { + for (const Artifact * const a : currentIt.value()) + currentFilePathsForTag.insert(a->filePath()); + } + if (currentFilePathsForTag != reqIt->second) { qCDebug(lcBuildGraph) << "artifacts map not up to date: requested artifact set for " - "file tag" << tagString << "in product" + "file tag" << reqIt->first << "in product" << product->uniqueName() << "differs from the current one"; return false; } } + + if (!artifactsEnumerated) + return true; + + Set<QString> currentTags; + for (auto it = currentArtifacts.begin(); it != currentArtifacts.end(); ++it) + currentTags.insert(it.key().toString()); if (currentTags != allTags) { qCDebug(lcBuildGraph) << "artifacts map not up to date: overall file tags differ for " << "product" << product->uniqueName(); @@ -169,10 +192,8 @@ void RequestedArtifacts::RequestedArtifactsPerProduct::unite( void RequestedArtifacts::RequestedArtifactsPerProduct::doSanityChecks() const { - Set<QString> requestedTagsSet; for (auto it = requestedTags.begin(); it != requestedTags.end(); ++it) - requestedTagsSet.insert(it->first); - QBS_CHECK(allTags.contains(requestedTagsSet)); + QBS_CHECK(allTags.contains(it->first) || it->second.empty()); } void RequestedArtifacts::RequestedArtifactsPerProduct::load(PersistentPool &pool) diff --git a/src/lib/corelib/buildgraph/requestedartifacts.h b/src/lib/corelib/buildgraph/requestedartifacts.h index 4d4a01297..82c393803 100644 --- a/src/lib/corelib/buildgraph/requestedartifacts.h +++ b/src/lib/corelib/buildgraph/requestedartifacts.h @@ -61,6 +61,8 @@ public: void clear() { m_requestedArtifactsPerProduct.clear(); } void setAllArtifactTags(const ResolvedProduct *product); void setArtifactsForTag(const ResolvedProduct *product, const FileTag &tag); + void setNonExistingTagRequested(const ResolvedProduct *product, const QString &tag); + void setArtifactsEnumerated(const ResolvedProduct *product); void unite(const RequestedArtifacts &other); void doSanityChecks() const; @@ -78,6 +80,7 @@ private: { Set<QString> allTags; std::unordered_map<QString, Set<QString>> requestedTags; + bool artifactsEnumerated = false; bool isUpToDate(const ResolvedProduct *product) const; @@ -87,7 +90,7 @@ private: template<PersistentPool::OpType opType> void serializationOp(PersistentPool &pool) { - pool.serializationOp<opType>(allTags, requestedTags); + pool.serializationOp<opType>(allTags, requestedTags, artifactsEnumerated); } void load(PersistentPool &pool); diff --git a/src/lib/corelib/buildgraph/transformer.cpp b/src/lib/corelib/buildgraph/transformer.cpp index baf104df5..df371e1fe 100644 --- a/src/lib/corelib/buildgraph/transformer.cpp +++ b/src/lib/corelib/buildgraph/transformer.cpp @@ -49,6 +49,7 @@ #include <tools/scripttools.h> #include <tools/qbsassert.h> #include <tools/stringconstants.h> +#include <tools/stlutils.h> #include <QtCore/qdir.h> @@ -117,7 +118,7 @@ QScriptValue Transformer::translateFileConfig(ScriptEngine *scriptEngine, const setArtifactProperty(obj, StringConstants::completeBaseNameProperty(), js_completeBaseName, artifact); setArtifactProperty(obj, QStringLiteral("baseDir"), js_baseDir, artifact); - const QStringList fileTags = artifact->fileTags().toStringList(); + const QStringList fileTags = sorted(artifact->fileTags().toStringList()); scriptEngine->setObservedProperty(obj, StringConstants::fileTagsProperty(), scriptEngine->toScriptValue(fileTags)); scriptEngine->observer()->addArtifactId(obj.objectId()); diff --git a/src/lib/corelib/buildgraph/transformerchangetracking.cpp b/src/lib/corelib/buildgraph/transformerchangetracking.cpp index 41f4c8219..aa13f967f 100644 --- a/src/lib/corelib/buildgraph/transformerchangetracking.cpp +++ b/src/lib/corelib/buildgraph/transformerchangetracking.cpp @@ -276,7 +276,7 @@ bool TrafoChangeTracker::prepareScriptNeedsRerun() const if (!artifact) return true; if (property.kind == Property::PropertyInArtifact) { - if (artifact->fileTags().toStringList() != property.value.toStringList()) + if (sorted(artifact->fileTags().toStringList()) != property.value.toStringList()) return true; continue; } @@ -312,7 +312,7 @@ bool TrafoChangeTracker::commandsNeedRerun() const if (!artifact) return true; if (property.kind == Property::PropertyInArtifact) { - if (artifact->fileTags().toStringList() != property.value.toStringList()) + if (sorted(artifact->fileTags().toStringList()) != property.value.toStringList()) return true; continue; } |