aboutsummaryrefslogtreecommitdiff
path: root/paludis/qa/pdepend_overlap_check.cc
blob: 870f500798e19c0d92ee45cb9e902ce65aa6555b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
 *
 * 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/dep_spec.hh>
#include <paludis/portage_dep_parser.hh>
#include <paludis/package_database_entry.hh>
#include <paludis/environment.hh>
#include <paludis/qa/pdepend_overlap_check.hh>
#include <paludis/util/join.hh>
#include <paludis/qa/qa_environment.hh>
#include <paludis/repositories/gentoo/portage_repository.hh>
#include <set>

using namespace paludis;
using namespace paludis::qa;

namespace
{
    struct Collector :
        DepSpecVisitorTypes::ConstVisitor,
        DepSpecVisitorTypes::ConstVisitor::VisitChildren<Collector, AllDepSpec>,
        DepSpecVisitorTypes::ConstVisitor::VisitChildren<Collector, AnyDepSpec>,
        DepSpecVisitorTypes::ConstVisitor::VisitChildren<Collector, UseDepSpec>
    {
        using DepSpecVisitorTypes::ConstVisitor::VisitChildren<Collector, UseDepSpec>::visit;
        using DepSpecVisitorTypes::ConstVisitor::VisitChildren<Collector, AllDepSpec>::visit;
        using DepSpecVisitorTypes::ConstVisitor::VisitChildren<Collector, AnyDepSpec>::visit;

        std::set<QualifiedPackageName> result;

        Collector()
        {
        }

        void visit(const PackageDepSpec * const p)
        {
            if (p->package_ptr())
                result.insert(*p->package_ptr());
        }

        void visit(const BlockDepSpec * const)
        {
        }

        void visit(const PlainTextDepSpec * const)
        {
        }
    };
}

PdependOverlapCheck::PdependOverlapCheck()
{
}

CheckResult
PdependOverlapCheck::operator() (const EbuildCheckData & e) const
{
    CheckResult result(stringify(e.name) + "-" + stringify(e.version),
            identifier());

    try
    {
        PackageDatabaseEntry ee(e.name, e.version,
                e.environment->portage_repository()->name());
        std::tr1::shared_ptr<const VersionMetadata> metadata(
                e.environment->package_database()->fetch_repository(ee.repository)->version_metadata(ee.name, ee.version));

        Collector pdepend_collector;
        metadata->deps_interface->post_depend()->accept(&pdepend_collector);

        {
            Collector depend_collector;
            metadata->deps_interface->build_depend()->accept(&depend_collector);

            std::set<QualifiedPackageName> overlap;
            std::set_intersection(depend_collector.result.begin(), depend_collector.result.end(),
                    pdepend_collector.result.begin(), pdepend_collector.result.end(),
                    std::inserter(overlap, overlap.begin()));

            if (! overlap.empty())
                result << Message(qal_major, "Overlap between DEPEND and PDEPEND: '" +
                        join(overlap.begin(), overlap.end(), "', ") + "'");
        }

        {
            Collector rdepend_collector;
            metadata->deps_interface->run_depend()->accept(&rdepend_collector);

            std::set<QualifiedPackageName> overlap;
            std::set_intersection(rdepend_collector.result.begin(), rdepend_collector.result.end(),
                    pdepend_collector.result.begin(), pdepend_collector.result.end(),
                    std::inserter(overlap, overlap.begin()));

            if (! overlap.empty())
                result << Message(qal_major, "Overlap between RDEPEND and PDEPEND: '" +
                        join(overlap.begin(), overlap.end(), "', ") + "'");
        }

    }
    catch (const InternalError &)
    {
        throw;
    }
    catch (const Exception & err)
    {
        result << Message(qal_fatal, "Caught Exception '" + err.message() + "' ("
                + err.what() + ")");
    }

    return result;
}

const std::string &
PdependOverlapCheck::identifier()
{
    static const std::string id("pdepend_overlap");
    return id;
}