aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories/e/dependencies_rewriter.cc
diff options
context:
space:
mode:
Diffstat (limited to 'paludis/repositories/e/dependencies_rewriter.cc')
-rw-r--r--paludis/repositories/e/dependencies_rewriter.cc277
1 files changed, 0 insertions, 277 deletions
diff --git a/paludis/repositories/e/dependencies_rewriter.cc b/paludis/repositories/e/dependencies_rewriter.cc
deleted file mode 100644
index ceb5e76cb..000000000
--- a/paludis/repositories/e/dependencies_rewriter.cc
+++ /dev/null
@@ -1,277 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2008, 2009, 2010, 2011 Ciaran McCreesh
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <paludis/repositories/e/dependencies_rewriter.hh>
-#include <paludis/util/pimp-impl.hh>
-#include <paludis/util/stringify.hh>
-#include <paludis/util/return_literal_function.hh>
-#include <paludis/util/save.hh>
-#include <paludis/util/indirect_iterator-impl.hh>
-#include <paludis/util/simple_visitor_cast.hh>
-#include <paludis/util/set.hh>
-#include <paludis/util/wrapped_forward_iterator.hh>
-#include <paludis/util/wrapped_output_iterator.hh>
-#include <paludis/util/sequence.hh>
-#include <paludis/util/accept_visitor.hh>
-#include <paludis/util/singleton-impl.hh>
-#include <paludis/dep_spec_annotations.hh>
-#include <paludis/always_enabled_dependency_label.hh>
-#include <list>
-#include <algorithm>
-
-using namespace paludis;
-using namespace paludis::erepository;
-
-typedef std::list<std::shared_ptr<DependenciesLabelSequence> > LabelsStack;
-
-namespace
-{
- const std::string get_annotations(const DepSpec & a)
- {
- std::stringstream s;
- if (a.maybe_annotations() && (a.maybe_annotations()->begin() != a.maybe_annotations()->end()))
- {
- s << " [[ ";
- for (auto m(a.maybe_annotations()->begin()), m_end(a.maybe_annotations()->end()) ;
- m != m_end ; ++m)
- s << m->key() << " = [" << (m->value().empty() ? " " : " " + m->value() + " ") << "] ";
-
- s << "]]";
- }
- return s.str();
- }
-
- struct DependenciesRewriterData :
- Singleton<DependenciesRewriterData>
- {
- std::shared_ptr<DependenciesLabelSequence> default_labels;
-
- DependenciesRewriterData() :
- default_labels(std::make_shared<DependenciesLabelSequence>())
- {
- default_labels->push_back(std::make_shared<AlwaysEnabledDependencyLabel<DependenciesBuildLabelTag> >("build"));
- default_labels->push_back(std::make_shared<AlwaysEnabledDependencyLabel<DependenciesRunLabelTag> >("run"));
- }
- };
-}
-
-namespace paludis
-{
- template <>
- struct Imp<DependenciesRewriter>
- {
- std::string depend;
- std::string rdepend;
- std::string pdepend;
-
- LabelsStack labels;
-
- Imp()
- {
- labels.push_front(DependenciesRewriterData::get_instance()->default_labels);
- }
- };
-}
-
-DependenciesRewriter::DependenciesRewriter() :
- _imp()
-{
-}
-
-DependenciesRewriter::~DependenciesRewriter()
-{
-}
-
-const std::string
-DependenciesRewriter::depend() const
-{
- return _imp->depend;
-}
-
-const std::string
-DependenciesRewriter::rdepend() const
-{
- return _imp->rdepend;
-}
-
-const std::string
-DependenciesRewriter::pdepend() const
-{
- return _imp->pdepend;
-}
-
-void
-DependenciesRewriter::visit(const DependencySpecTree::NodeType<PackageDepSpec>::Type & node)
-{
- _add_where_necessary(stringify(*node.spec()), *node.spec());
-}
-
-void
-DependenciesRewriter::visit(const DependencySpecTree::NodeType<NamedSetDepSpec>::Type & node)
-{
- _add_where_necessary(stringify(*node.spec()), *node.spec());
-}
-
-void
-DependenciesRewriter::visit(const DependencySpecTree::NodeType<BlockDepSpec>::Type & node)
-{
- _add_where_necessary(stringify(*node.spec()), *node.spec());
-}
-
-void
-DependenciesRewriter::visit(const DependencySpecTree::NodeType<DependenciesLabelsDepSpec>::Type & node)
-{
- _imp->depend.append(" " + stringify(*node.spec()) + get_annotations(*node.spec()));
- _imp->rdepend.append(" " + stringify(*node.spec()) + get_annotations(*node.spec()));
- _imp->pdepend.append(" " + stringify(*node.spec()) + get_annotations(*node.spec()));
-
- std::shared_ptr<DependenciesLabelSequence> labels(std::make_shared<DependenciesLabelSequence>());
- std::copy(node.spec()->begin(), node.spec()->end(), labels->back_inserter());
- *_imp->labels.begin() = labels;
-}
-
-void
-DependenciesRewriter::visit(const DependencySpecTree::NodeType<AllDepSpec>::Type & node)
-{
- _imp->labels.push_front(*_imp->labels.begin());
- RunOnDestruction restore_labels(std::bind(std::mem_fn(&LabelsStack::pop_front), &_imp->labels));
-
- std::string d(_imp->depend), r(_imp->rdepend), p(_imp->pdepend);
- _imp->depend.clear();
- _imp->rdepend.clear();
- _imp->pdepend.clear();
-
- std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(*this));
-
- _imp->depend = d + " ( " + _imp->depend + " )" + get_annotations(*node.spec());
- _imp->rdepend = r + " ( " + _imp->rdepend + " )" + get_annotations(*node.spec());
- _imp->pdepend = p + " ( " + _imp->pdepend + " )" + get_annotations(*node.spec());
-}
-
-void
-DependenciesRewriter::visit(const DependencySpecTree::NodeType<AnyDepSpec>::Type & node)
-{
- _imp->labels.push_front(*_imp->labels.begin());
- RunOnDestruction restore_labels(std::bind(std::mem_fn(&LabelsStack::pop_front), &_imp->labels));
-
- std::string d(_imp->depend), r(_imp->rdepend), p(_imp->pdepend);
- _imp->depend.clear();
- _imp->rdepend.clear();
- _imp->pdepend.clear();
-
- std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(*this));
-
- _imp->depend = d + " || ( " + _imp->depend + " )" + get_annotations(*node.spec());
- _imp->rdepend = r + " || ( " + _imp->rdepend + " )" + get_annotations(*node.spec());
- _imp->pdepend = p + " || ( " + _imp->pdepend + " )" + get_annotations(*node.spec());
-}
-
-void
-DependenciesRewriter::visit(const DependencySpecTree::NodeType<ConditionalDepSpec>::Type & node)
-{
- _imp->labels.push_front(*_imp->labels.begin());
- RunOnDestruction restore_labels(std::bind(std::mem_fn(&LabelsStack::pop_front), &_imp->labels));
-
- std::string d(_imp->depend), r(_imp->rdepend), p(_imp->pdepend);
- _imp->depend.clear();
- _imp->rdepend.clear();
- _imp->pdepend.clear();
-
- std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(*this));
-
- _imp->depend = d + " " + stringify(*node.spec()) + " ( " + _imp->depend + " )" + get_annotations(*node.spec());
- _imp->rdepend = r + " " + stringify(*node.spec()) + " ( " + _imp->rdepend + " )" + get_annotations(*node.spec());
- _imp->pdepend = p + " " + stringify(*node.spec()) + " ( " + _imp->pdepend + " )" + get_annotations(*node.spec());
-}
-
-namespace
-{
- struct AddWhereNecessary
- {
- std::string & d, & r, & p;
- const std::string & s;
- const DepSpec & a;
-
- AddWhereNecessary(std::string & dd, std::string & rr, std::string & pp, const std::string & ss,
- const DepSpec & aa) :
- d(dd),
- r(rr),
- p(pp),
- s(ss),
- a(aa)
- {
- }
-
- void visit(const DependenciesRunLabel &)
- {
- r.append(" " + s + get_annotations(a));
- }
-
- void visit(const DependenciesPostLabel &)
- {
- p.append(" " + s + get_annotations(a));
- }
-
- void visit(const DependenciesSuggestionLabel &)
- {
- p.append(" " + s + get_annotations(a));
- }
-
- void visit(const DependenciesRecommendationLabel &)
- {
- p.append(" " + s + get_annotations(a));
- }
-
- void visit(const DependenciesBuildLabel &)
- {
- d.append(" " + s + get_annotations(a));
- }
-
- void visit(const DependenciesTestLabel &)
- {
- d.append(" " + s + get_annotations(a));
- }
-
- void visit(const DependenciesFetchLabel &)
- {
- d.append(" " + s + get_annotations(a));
- }
-
- void visit(const DependenciesCompileAgainstLabel &)
- {
- r.append(" " + s + get_annotations(a));
- }
-
- void visit(const DependenciesInstallLabel &)
- {
- d.append(" " + s + get_annotations(a));
- }
- };
-}
-
-void
-DependenciesRewriter::_add_where_necessary(const std::string & s, const DepSpec & a)
-{
- AddWhereNecessary v(_imp->depend, _imp->rdepend, _imp->pdepend, s, a);
- std::for_each(
- indirect_iterator((*_imp->labels.begin())->begin()),
- indirect_iterator((*_imp->labels.begin())->end()),
- accept_visitor(v));
-}
-