From 1eef55e98f7dddf0aacbf43f369d7bd11b06745e Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 31 Jul 2014 14:47:56 +0200 Subject: add getter/setters for Artifact::fileTags The setters take care of keeping the product's artifact-by-filetags hash up to date. Before, one had to set up the artifact's file tags before insertArtifactToProduct was called. Otherwise the hash didn't get updated. Change-Id: Ibb530d2c992d72c0a99152009b4e6eecbf770098 Reviewed-by: Christian Kandeler --- src/lib/corelib/api/project.cpp | 4 +-- src/lib/corelib/buildgraph/artifact.cpp | 32 ++++++++++++++++++++-- src/lib/corelib/buildgraph/artifact.h | 8 +++++- src/lib/corelib/buildgraph/buildgraph.cpp | 2 +- src/lib/corelib/buildgraph/buildgraphloader.cpp | 14 +++------- src/lib/corelib/buildgraph/depscanner.cpp | 2 +- src/lib/corelib/buildgraph/executor.cpp | 4 +-- .../corelib/buildgraph/inputartifactscanner.cpp | 6 ++-- src/lib/corelib/buildgraph/productbuilddata.cpp | 4 +-- src/lib/corelib/buildgraph/projectbuilddata.cpp | 9 +++--- src/lib/corelib/buildgraph/qtmocscanner.cpp | 2 +- src/lib/corelib/buildgraph/rulenode.cpp | 2 +- src/lib/corelib/buildgraph/rulesapplicator.cpp | 20 ++++++++------ src/lib/corelib/buildgraph/transformer.cpp | 8 +++--- src/lib/corelib/language/language.cpp | 6 ++-- 15 files changed, 76 insertions(+), 47 deletions(-) diff --git a/src/lib/corelib/api/project.cpp b/src/lib/corelib/api/project.cpp index 93daf433f..ab440c753 100644 --- a/src/lib/corelib/api/project.cpp +++ b/src/lib/corelib/api/project.cpp @@ -640,7 +640,7 @@ void ProjectPrivate::retrieveProjectData(ProjectData &projectData, foreach (const Artifact * const a, resolvedProduct->targetArtifacts()) { TargetArtifact ta; ta.d->filePath = a->filePath(); - ta.d->fileTags = a->fileTags.toStringList(); + ta.d->fileTags = a->fileTags().toStringList(); ta.d->properties.d->m_map = a->properties; ta.d->isValid = true; product.d->targetArtifacts << ta; @@ -920,7 +920,7 @@ QList Project::installableFilesForProduct(const ProductData &pr if (targetFilePath.isEmpty()) continue; f.d->sourceFilePath = artifact->filePath(); - f.d->fileTags = artifact->fileTags.toStringList(); + f.d->fileTags = artifact->fileTags().toStringList(); f.d->isValid = true; installableFiles << f; } diff --git a/src/lib/corelib/buildgraph/artifact.cpp b/src/lib/corelib/buildgraph/artifact.cpp index d9f442494..940a34016 100644 --- a/src/lib/corelib/buildgraph/artifact.cpp +++ b/src/lib/corelib/buildgraph/artifact.cpp @@ -31,6 +31,8 @@ #include "transformer.h" #include "buildgraphvisitor.h" +#include "productbuilddata.h" +#include #include #include #include @@ -77,6 +79,32 @@ QString Artifact::toString() const return QLatin1String("ARTIFACT ") + filePath(); } +void Artifact::addFileTag(const FileTag &t) +{ + m_fileTags += t; + if (!product.isNull() && product->buildData) + product->buildData->artifactsByFileTag[t] += this; +} + +void Artifact::removeFileTag(const FileTag &t) +{ + m_fileTags -= t; + if (!product.isNull() && product->buildData) + removeArtifactFromSetByFileTag(this, t, product->buildData->artifactsByFileTag); +} + +void Artifact::setFileTags(const FileTags &newFileTags) +{ + if (product.isNull() || !product->buildData) { + m_fileTags = newFileTags; + return; + } + foreach (const FileTag &t, m_fileTags) + removeArtifactFromSetByFileTag(this, t, product->buildData->artifactsByFileTag); + m_fileTags = newFileTags; + addArtifactToSet(this, product->buildData->artifactsByFileTag); +} + void Artifact::initialize() { artifactType = Unknown; @@ -121,7 +149,7 @@ void Artifact::load(PersistentPool &pool) transformer = pool.idLoadS(); unsigned char c; pool.stream() - >> fileTags + >> m_fileTags >> artifactType >> c; alwaysUpdated = c; @@ -140,7 +168,7 @@ void Artifact::store(PersistentPool &pool) const pool.store(properties); pool.store(transformer); pool.stream() - << fileTags + << m_fileTags << artifactType << static_cast(alwaysUpdated) << static_cast(oldDataPossiblyPresent); diff --git a/src/lib/corelib/buildgraph/artifact.h b/src/lib/corelib/buildgraph/artifact.h index ca62daea7..1f7bbb520 100644 --- a/src/lib/corelib/buildgraph/artifact.h +++ b/src/lib/corelib/buildgraph/artifact.h @@ -62,9 +62,13 @@ public: void accept(BuildGraphVisitor *visitor); QString toString() const; + void addFileTag(const FileTag &t); + void removeFileTag(const FileTag &t); + void setFileTags(const FileTags &newFileTags); + const FileTags &fileTags() const { return m_fileTags; } + ArtifactSet childrenAddedByScanner; QSet fileDependencies; - FileTags fileTags; TransformerPtr transformer; PropertyMapPtr properties; @@ -89,6 +93,8 @@ public: private: void load(PersistentPool &pool); void store(PersistentPool &pool) const; + + FileTags m_fileTags; }; // debugging helper diff --git a/src/lib/corelib/buildgraph/buildgraph.cpp b/src/lib/corelib/buildgraph/buildgraph.cpp index 39fdc2851..59666165b 100644 --- a/src/lib/corelib/buildgraph/buildgraph.cpp +++ b/src/lib/corelib/buildgraph/buildgraph.cpp @@ -409,7 +409,7 @@ Artifact *createArtifact(const ResolvedProductPtr &product, Artifact *artifact = new Artifact; artifact->artifactType = Artifact::SourceFile; artifact->setFilePath(sourceArtifact->absoluteFilePath); - artifact->fileTags = sourceArtifact->fileTags; + artifact->setFileTags(sourceArtifact->fileTags); artifact->properties = sourceArtifact->properties; insertArtifact(product, artifact, logger); return artifact; diff --git a/src/lib/corelib/buildgraph/buildgraphloader.cpp b/src/lib/corelib/buildgraph/buildgraphloader.cpp index 1b7fb1056..a2ea68eba 100644 --- a/src/lib/corelib/buildgraph/buildgraphloader.cpp +++ b/src/lib/corelib/buildgraph/buildgraphloader.cpp @@ -642,19 +642,13 @@ void BuildGraphLoader::onProductFileListChanged(const ResolvedProductPtr &restor Artifact *artifact = lookupArtifact(restoredProduct, oldBuildData, a->absoluteFilePath, true); QBS_CHECK(artifact); - // handle added filetags - foreach (const FileTag &addedFileTag, changedArtifact->fileTags - a->fileTags) { - artifact->fileTags += addedFileTag; - artifact->product->buildData->artifactsByFileTag[addedFileTag].insert(artifact); - } + foreach (const FileTag &addedFileTag, changedArtifact->fileTags - a->fileTags) + artifact->addFileTag(addedFileTag); // handle removed filetags - foreach (const FileTag &removedFileTag, a->fileTags - changedArtifact->fileTags) { - artifact->fileTags -= removedFileTag; - removeArtifactFromSetByFileTag(artifact, removedFileTag, - artifact->product->buildData->artifactsByFileTag); - } + foreach (const FileTag &removedFileTag, a->fileTags - changedArtifact->fileTags) + artifact->removeFileTag(removedFileTag); } if (changedArtifact->properties->value() != a->properties->value()) { diff --git a/src/lib/corelib/buildgraph/depscanner.cpp b/src/lib/corelib/buildgraph/depscanner.cpp index 0deaae37a..5aa3c8676 100644 --- a/src/lib/corelib/buildgraph/depscanner.cpp +++ b/src/lib/corelib/buildgraph/depscanner.cpp @@ -178,7 +178,7 @@ QStringList UserDependencyScanner::evaluate(Artifact *artifact, const ScriptFunc QScriptValue artifactConfig = m_engine->newObject(); ModuleProperties::init(artifactConfig, artifact); artifactConfig.setProperty(QLatin1String("fileName"), artifact->filePath(), 0); - const QStringList fileTags = artifact->fileTags.toStringList(); + const QStringList fileTags = artifact->fileTags().toStringList(); artifactConfig.setProperty(QLatin1String("fileTags"), m_engine->toScriptValue(fileTags)); if (!m_scanner->module->name.isEmpty()) artifactConfig.setProperty(QLatin1String("moduleName"), m_scanner->module->name); diff --git a/src/lib/corelib/buildgraph/executor.cpp b/src/lib/corelib/buildgraph/executor.cpp index e59e1f9d5..5c6376658 100644 --- a/src/lib/corelib/buildgraph/executor.cpp +++ b/src/lib/corelib/buildgraph/executor.cpp @@ -463,7 +463,7 @@ void Executor::executeRuleNode(RuleNode *ruleNode) Artifact *outputArtifact = dynamic_cast(node); if (!outputArtifact) continue; - if (outputArtifact->fileTags.matches(product->fileTags)) + if (outputArtifact->fileTags().matches(product->fileTags)) product->buildData->roots += outputArtifact; foreach (Artifact *inputArtifact, outputArtifact->transformer->inputs) @@ -579,7 +579,7 @@ bool Executor::transformerHasMatchingOutputTags(const TransformerConstPtr &trans return true; // No filtering requested. foreach (Artifact * const output, transformer->outputs) { - if (m_activeFileTags.matches(output->fileTags)) + if (m_activeFileTags.matches(output->fileTags())) return true; } diff --git a/src/lib/corelib/buildgraph/inputartifactscanner.cpp b/src/lib/corelib/buildgraph/inputartifactscanner.cpp index b75184597..e3571c80e 100644 --- a/src/lib/corelib/buildgraph/inputartifactscanner.cpp +++ b/src/lib/corelib/buildgraph/inputartifactscanner.cpp @@ -156,7 +156,7 @@ void InputArtifactScanner::scan() m_logger.qbsTrace() << QString::fromLocal8Bit("[DEPSCAN] inputs for %1 [%2] in product '%3'") .arg(m_artifact->filePath(), - m_artifact->fileTags.toStringList().join(QLatin1String(", ")), + m_artifact->fileTags().toStringList().join(QLatin1String(", ")), m_artifact->product->name); } @@ -183,7 +183,7 @@ void InputArtifactScanner::scanForFileDependencies(Artifact *inputArtifact) m_logger.qbsTrace() << QString::fromLocal8Bit("[DEPSCAN] input artifact %1 [%2]") .arg(inputArtifact->filePath(), - inputArtifact->fileTags.toStringList().join(QLatin1String(", "))); + inputArtifact->fileTags().toStringList().join(QLatin1String(", "))); } InputArtifactScannerContext::CacheItem &cacheItem = m_context->cache[inputArtifact->properties]; @@ -212,7 +212,7 @@ QSet InputArtifactScanner::scannersForArtifact(const Artifa ScriptEngine *engine = product->topLevelProject()->buildData->evaluationContext->engine(); QHash &scannerCache = m_context->scannersCache[product]; - foreach (const FileTag &fileTag, artifact->fileTags) { + foreach (const FileTag &fileTag, artifact->fileTags()) { InputArtifactScannerContext::DependencyScannerCacheItem &cache = scannerCache[fileTag]; if (!cache.valid) { cache.valid = true; diff --git a/src/lib/corelib/buildgraph/productbuilddata.cpp b/src/lib/corelib/buildgraph/productbuilddata.cpp index abea2c861..39fdda32b 100644 --- a/src/lib/corelib/buildgraph/productbuilddata.cpp +++ b/src/lib/corelib/buildgraph/productbuilddata.cpp @@ -121,7 +121,7 @@ void ProductBuildData::store(PersistentPool &pool) const void addArtifactToSet(Artifact *artifact, ProductBuildData::ArtifactSetByFileTag &container) { - foreach (const FileTag &tag, artifact->fileTags) + foreach (const FileTag &tag, artifact->fileTags()) container[tag] += artifact; } @@ -138,7 +138,7 @@ void removeArtifactFromSetByFileTag(Artifact *artifact, const FileTag &fileTag, void removeArtifactFromSet(Artifact *artifact, ProductBuildData::ArtifactSetByFileTag &container) { - foreach (const FileTag &t, artifact->fileTags) + foreach (const FileTag &t, artifact->fileTags()) removeArtifactFromSetByFileTag(artifact, t, container); } diff --git a/src/lib/corelib/buildgraph/projectbuilddata.cpp b/src/lib/corelib/buildgraph/projectbuilddata.cpp index 0e846ae53..4b71ba14f 100644 --- a/src/lib/corelib/buildgraph/projectbuilddata.cpp +++ b/src/lib/corelib/buildgraph/projectbuilddata.cpp @@ -462,8 +462,7 @@ void BuildDataResolver::resolveProductBuildData(const ResolvedProductPtr &produc qbsFileArtifact->properties = product->moduleProperties; insertArtifact(product, qbsFileArtifact, m_logger); } - qbsFileArtifact->fileTags.insert("qbs"); - product->buildData->artifactsByFileTag["qbs"] += qbsFileArtifact; + qbsFileArtifact->addFileTag("qbs"); artifactsPerFileTag["qbs"].insert(qbsFileArtifact); // read sources @@ -473,7 +472,7 @@ void BuildDataResolver::resolveProductBuildData(const ResolvedProductPtr &produc continue; // ignore duplicate artifacts Artifact *artifact = createArtifact(product, sourceArtifact, m_logger); - foreach (const FileTag &fileTag, artifact->fileTags) + foreach (const FileTag &fileTag, artifact->fileTags()) artifactsPerFileTag[fileTag].insert(artifact); } @@ -505,12 +504,12 @@ void BuildDataResolver::resolveProductBuildData(const ResolvedProductPtr &produc product->buildData->roots += outputArtifact; foreach (Artifact *inputArtifact, inputArtifacts) safeConnect(outputArtifact, inputArtifact, m_logger); - foreach (const FileTag &fileTag, outputArtifact->fileTags) + foreach (const FileTag &fileTag, outputArtifact->fileTags()) artifactsPerFileTag[fileTag].insert(outputArtifact); RuleArtifactPtr ruleArtifact = RuleArtifact::create(); ruleArtifact->filePath = outputArtifact->filePath(); - ruleArtifact->fileTags = outputArtifact->fileTags; + ruleArtifact->fileTags = outputArtifact->fileTags(); rule->artifacts += ruleArtifact; } transformer->rule = rule; diff --git a/src/lib/corelib/buildgraph/qtmocscanner.cpp b/src/lib/corelib/buildgraph/qtmocscanner.cpp index f4dd1bbcb..b4caa40b4 100644 --- a/src/lib/corelib/buildgraph/qtmocscanner.cpp +++ b/src/lib/corelib/buildgraph/qtmocscanner.cpp @@ -169,7 +169,7 @@ QScriptValue QtMocScanner::apply(QScriptEngine *engine, const Artifact *artifact bool hasQObjectMacro = false; bool mustCompile = false; bool hasPluginMetaDataMacro = false; - const bool isHeaderFile = artifact->fileTags.contains("hpp"); + const bool isHeaderFile = artifact->fileTags().contains("hpp"); ScannerPlugin * const scanner = isHeaderFile ? m_hppScanner : m_cppScanner; const ScanResultCache::Result scanResult = runScanner(scanner, artifact, m_scanResultCache); diff --git a/src/lib/corelib/buildgraph/rulenode.cpp b/src/lib/corelib/buildgraph/rulenode.cpp index 4bf027bfa..eaccf3c6f 100644 --- a/src/lib/corelib/buildgraph/rulenode.cpp +++ b/src/lib/corelib/buildgraph/rulenode.cpp @@ -157,7 +157,7 @@ ArtifactSet RuleNode::currentInputArtifacts() const foreach (Artifact *targetArtifact, dep->targetArtifacts()) artifactsToCheck += targetArtifact->transformer->outputs; foreach (Artifact *artifact, artifactsToCheck) { - if (artifact->fileTags.matches(m_rule->usings)) + if (artifact->fileTags().matches(m_rule->usings)) s += artifact; } } diff --git a/src/lib/corelib/buildgraph/rulesapplicator.cpp b/src/lib/corelib/buildgraph/rulesapplicator.cpp index 632606566..40301f5ea 100644 --- a/src/lib/corelib/buildgraph/rulesapplicator.cpp +++ b/src/lib/corelib/buildgraph/rulesapplicator.cpp @@ -138,7 +138,7 @@ static QStringList toStringList(const ArtifactSet &artifacts) QStringList lst; foreach (const Artifact *artifact, artifacts) { const QString str = artifact->filePath() + QLatin1String(" [") - + artifact->fileTags.toStringList().join(QLatin1String(", ")) + QLatin1Char(']'); + + artifact->fileTags().toStringList().join(QLatin1String(", ")) + QLatin1Char(']'); lst << str; } return lst; @@ -211,7 +211,7 @@ void RulesApplicator::doApply(const ArtifactSet &inputArtifacts, QScriptValue &p scope().setProperty(QLatin1String("fileName"), engine()->toScriptValue(outputArtifact->filePath())); scope().setProperty(QLatin1String("fileTags"), - toScriptValue(engine(), outputArtifact->fileTags.toStringList())); + toScriptValue(engine(), outputArtifact->fileTags().toStringList())); QVariantMap artifactModulesCfg = outputArtifact->properties->value() .value(QLatin1String("modules")).toMap(); @@ -280,10 +280,10 @@ Artifact *RulesApplicator::createOutputArtifact(const QString &filePath, const F QString e = Tr::tr("Conflicting rules for producing %1 %2 \n") .arg(outputArtifact->filePath(), QLatin1Char('[') + - outputArtifact->fileTags.toStringList().join(QLatin1String(", ")) + outputArtifact->fileTags().toStringList().join(QLatin1String(", ")) + QLatin1Char(']')); QString str = QLatin1Char('[') + m_rule->inputs.toStringList().join(QLatin1String(", ")) - + QLatin1String("] -> [") + outputArtifact->fileTags.toStringList() + + QLatin1String("] -> [") + outputArtifact->fileTags().toStringList() .join(QLatin1String(", ")) + QLatin1Char(']'); e += QString::fromLatin1(" while trying to apply: %1:%2:%3 %4\n") @@ -312,25 +312,27 @@ Artifact *RulesApplicator::createOutputArtifact(const QString &filePath, const F m_transformer = outputArtifact->transformer; m_transformer->inputs.unite(inputArtifacts); } - outputArtifact->fileTags += fileTags; + FileTags tags = fileTags; + tags += outputArtifact->fileTags(); + outputArtifact->setFileTags(tags); outputArtifact->clearTimestamp(); } else { outputArtifact = new Artifact; outputArtifact->artifactType = Artifact::Generated; outputArtifact->setFilePath(outputPath); - outputArtifact->fileTags = fileTags; + outputArtifact->setFileTags(fileTags); outputArtifact->alwaysUpdated = alwaysUpdated; outputArtifact->properties = m_product->moduleProperties; insertArtifact(m_product, outputArtifact, m_logger); m_createdArtifacts += outputArtifact; } - if (outputArtifact->fileTags.isEmpty()) - outputArtifact->fileTags = m_product->fileTagsForFileName(outputArtifact->fileName()); + if (outputArtifact->fileTags().isEmpty()) + outputArtifact->setFileTags(m_product->fileTagsForFileName(outputArtifact->fileName())); for (int i = 0; i < m_product->artifactProperties.count(); ++i) { const ArtifactPropertiesConstPtr &props = m_product->artifactProperties.at(i); - if (outputArtifact->fileTags.matches(props->fileTagsFilter())) { + if (outputArtifact->fileTags().matches(props->fileTagsFilter())) { outputArtifact->properties = props->propertyMap(); break; } diff --git a/src/lib/corelib/buildgraph/transformer.cpp b/src/lib/corelib/buildgraph/transformer.cpp index b9a206851..3e13dba3f 100644 --- a/src/lib/corelib/buildgraph/transformer.cpp +++ b/src/lib/corelib/buildgraph/transformer.cpp @@ -102,7 +102,7 @@ QScriptValue Transformer::translateFileConfig(QScriptEngine *scriptEngine, Artif setArtifactProperty(obj, QLatin1String("baseName"), js_baseName, artifact); setArtifactProperty(obj, QLatin1String("completeBaseName"), js_completeBaseName, artifact); setArtifactProperty(obj, QLatin1String("baseDir"), js_baseDir, artifact); - const QStringList fileTags = artifact->fileTags.toStringList(); + const QStringList fileTags = artifact->fileTags().toStringList(); obj.setProperty(QLatin1String("fileTags"), scriptEngine->toScriptValue(fileTags)); if (!defaultModuleName.isEmpty()) obj.setProperty(QLatin1String("moduleName"), defaultModuleName); @@ -114,7 +114,7 @@ QScriptValue Transformer::translateInOutputs(QScriptEngine *scriptEngine, const typedef QMap > TagArtifactsMap; TagArtifactsMap tagArtifactsMap; foreach (Artifact *artifact, artifacts) - foreach (const FileTag &fileTag, artifact->fileTags) + foreach (const FileTag &fileTag, artifact->fileTags()) tagArtifactsMap[fileTag.toString()].append(artifact); QScriptValue jsTagFiles = scriptEngine->newObject(); @@ -147,7 +147,7 @@ void Transformer::setupInputs(QScriptValue targetScriptValue, const ArtifactSet QScriptValue inputScriptValue; if (inputs.count() == 1) { Artifact *input = *inputs.begin(); - const FileTags &fileTags = input->fileTags; + const FileTags &fileTags = input->fileTags(); QBS_ASSERT(!fileTags.isEmpty(), return); QScriptValue inputsForFileTag = scriptValue.property(fileTags.begin()->toString()); inputScriptValue = inputsForFileTag.property(0); @@ -168,7 +168,7 @@ void Transformer::setupOutputs(QScriptEngine *scriptEngine, QScriptValue targetS QScriptValue outputScriptValue; if (outputs.count() == 1) { Artifact *output = *outputs.begin(); - const FileTags &fileTags = output->fileTags; + const FileTags &fileTags = output->fileTags(); QBS_ASSERT(!fileTags.isEmpty(), return); QScriptValue outputsForFileTag = scriptValue.property(fileTags.begin()->toString()); outputScriptValue = outputsForFileTag.property(0); diff --git a/src/lib/corelib/language/language.cpp b/src/lib/corelib/language/language.cpp index 56a560d44..20ef70b52 100644 --- a/src/lib/corelib/language/language.cpp +++ b/src/lib/corelib/language/language.cpp @@ -343,7 +343,7 @@ QString Rule::toString() const bool Rule::acceptsAsInput(Artifact *artifact) const { - return artifact->fileTags.matches(inputs); + return artifact->fileTags().matches(inputs); } FileTags Rule::staticOutputFileTags() const @@ -705,7 +705,7 @@ ArtifactSet ResolvedProduct::targetArtifacts() const QBS_CHECK(buildData); ArtifactSet taSet; foreach (Artifact * const a, buildData->rootArtifacts()) { - if (a->fileTags.matches(fileTags)) + if (a->fileTags().matches(fileTags)) taSet << a; } return taSet; @@ -731,7 +731,7 @@ static QStringList findGeneratedFiles(const Artifact *base, const FileTags &tags { QStringList result; foreach (const Artifact *parent, base->parentArtifacts()) { - if (tags.isEmpty() || parent->fileTags.matches(tags)) + if (tags.isEmpty() || parent->fileTags().matches(tags)) result << parent->filePath(); } -- cgit v1.2.3