From 9ad4bc2401dd3d3be8b6c4407666b9ea1973dbb5 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 20 Nov 2013 18:16:34 +0100 Subject: API: Allow to remove files from a product. Task-number: QBS-20 Change-Id: Ia8b8c4745e8e68ec219e16876fb630d02453425b Reviewed-by: Joerg Bornemann --- src/lib/buildgraph/buildgraphloader.cpp | 35 ++++++--------------------------- src/lib/buildgraph/projectbuilddata.cpp | 30 ++++++++++++++++++++++++++++ src/lib/buildgraph/projectbuilddata.h | 2 ++ 3 files changed, 38 insertions(+), 29 deletions(-) (limited to 'src/lib/buildgraph') diff --git a/src/lib/buildgraph/buildgraphloader.cpp b/src/lib/buildgraph/buildgraphloader.cpp index 94ce07f57..8c3639104 100644 --- a/src/lib/buildgraph/buildgraphloader.cpp +++ b/src/lib/buildgraph/buildgraphloader.cpp @@ -548,7 +548,9 @@ void BuildGraphLoader::onProductFileListChanged(const ResolvedProductPtr &restor Artifact *artifact = lookupArtifact(restoredProduct, oldBuildData, a->absoluteFilePath, true); QBS_CHECK(artifact); - removeArtifactAndExclusiveDependents(artifact, &artifactsToRemove); + newlyResolvedProduct->topLevelProject()->buildData + ->removeArtifactAndExclusiveDependents(artifact, m_logger, true, + &artifactsToRemove); continue; } @@ -574,7 +576,9 @@ void BuildGraphLoader::onProductFileListChanged(const ResolvedProductPtr &restor foreach (Artifact *parent, artifact->parents) { if (parent->transformer && parent->transformer->rule->inputs.contains(removedFileTag)) { // this parent has been created because of the removed filetag - removeArtifactAndExclusiveDependents(parent, &artifactsToRemove); + newlyResolvedProduct->topLevelProject()->buildData + ->removeArtifactAndExclusiveDependents(parent, m_logger, true, + &artifactsToRemove); } } } @@ -602,33 +606,6 @@ void BuildGraphLoader::onProductFileListChanged(const ResolvedProductPtr &restor } } -/** - * Removes the artifact and all the artifacts that depend exclusively on it. - * Example: if you remove a cpp artifact then the obj artifact is removed but - * not the resulting application (if there's more then one cpp artifact). - */ -void BuildGraphLoader::removeArtifactAndExclusiveDependents(Artifact *artifact, - ArtifactList *removedArtifacts) -{ - if (removedArtifacts) - removedArtifacts->insert(artifact); - TopLevelProject * const project = artifact->product->topLevelProject(); - foreach (Artifact *parent, artifact->parents) { - bool removeParent = false; - disconnect(parent, artifact, m_logger); - if (parent->children.isEmpty()) { - removeParent = true; - } else if (parent->transformer) { - project->buildData->artifactsThatMustGetNewTransformers += parent; - parent->transformer->inputs.remove(artifact); - removeParent = parent->transformer->inputs.isEmpty(); - } - if (removeParent) - removeArtifactAndExclusiveDependents(parent, removedArtifacts); - } - project->buildData->removeArtifact(artifact, m_logger); -} - static SourceArtifactConstPtr findSourceArtifact(const ResolvedProductConstPtr &product, const QString &artifactFilePath, QMap &artifactMap) { diff --git a/src/lib/buildgraph/projectbuilddata.cpp b/src/lib/buildgraph/projectbuilddata.cpp index bec6585bc..57d7ea6e0 100644 --- a/src/lib/buildgraph/projectbuilddata.cpp +++ b/src/lib/buildgraph/projectbuilddata.cpp @@ -142,6 +142,36 @@ static void disconnectArtifact(Artifact *artifact, ProjectBuildData *projectBuil disconnectArtifactParents(artifact, projectBuildData, logger); } +/*! + * Removes the artifact and all the artifacts that depend exclusively on it. + * Example: if you remove a cpp artifact then the obj artifact is removed but + * not the resulting application (if there's more then one cpp artifact). + */ +void ProjectBuildData::removeArtifactAndExclusiveDependents(Artifact *artifact, + const Logger &logger, bool removeFromProduct, + ArtifactList *removedArtifacts) +{ + if (removedArtifacts) + removedArtifacts->insert(artifact); + foreach (Artifact *parent, artifact->parents) { + bool removeParent = false; + disconnect(parent, artifact, logger); + if (parent->children.isEmpty()) { + removeParent = true; + } else if (parent->transformer) { + artifactsThatMustGetNewTransformers += parent; + parent->transformer->inputs.remove(artifact); + removeParent = parent->transformer->inputs.isEmpty(); + } + if (removeParent) { + removeArtifactAndExclusiveDependents(parent, logger, removeFromProduct, + removedArtifacts); + } + } + const bool removeFromDisk = artifact->artifactType == Artifact::Generated; + removeArtifact(artifact, logger, removeFromDisk, removeFromProduct); +} + void ProjectBuildData::removeArtifact(Artifact *artifact, const Logger &logger, bool removeFromDisk, bool removeFromProduct) { diff --git a/src/lib/buildgraph/projectbuilddata.h b/src/lib/buildgraph/projectbuilddata.h index 346291dc6..2268d67f0 100644 --- a/src/lib/buildgraph/projectbuilddata.h +++ b/src/lib/buildgraph/projectbuilddata.h @@ -63,6 +63,8 @@ public: QList lookupFiles(const Artifact *artifact) const; void insertFileDependency(FileDependency *dependency); void updateNodesThatMustGetNewTransformer(const Logger &logger); + void removeArtifactAndExclusiveDependents(Artifact *artifact, const Logger &logger, + bool removeFromProduct = true, ArtifactList *removedArtifacts = 0); void removeArtifact(Artifact *artifact, const Logger &logger, bool removeFromDisk = true, bool removeFromProduct = true); -- cgit v1.2.1