aboutsummaryrefslogtreecommitdiff
path: root/paludis/qa/deps_exist_check.cc
blob: 5a69cb9b4b85559becd1410835c6ab8861754d20 (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
137
/* 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/package_database_entry.hh>
#include <paludis/environment.hh>
#include <paludis/portage_dep_parser.hh>
#include <paludis/qa/deps_exist_check.hh>
#include <paludis/util/save.hh>
#include <paludis/query.hh>
#include <paludis/qa/qa_environment.hh>
#include <paludis/repositories/gentoo/portage_repository.hh>

using namespace paludis;
using namespace paludis::qa;

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

        CheckResult & result;
        const std::string role;
        const Environment * env;
        bool in_any;

        Checker(CheckResult & rr, const std::string & r, const Environment * e) :
            result(rr),
            role(r),
            env(e),
            in_any(false)
        {
        }

        void visit(const PackageDepSpec * const p)
        {
            if (p->package_ptr() &&
                    env->package_database()->query(query::Package(*p->package_ptr()), qo_whatever)->empty())
            {
                if (in_any)
                    result << Message(qal_maybe, "No match for " + role + " entry '"
                            + stringify(*p) + "' inside || ( ) block");
                else
                    result << Message(qal_major, "No match for " + role + " entry '"
                            + stringify(*p) + "'");
            }
        }

        void visit(const AnyDepSpec * const a)
        {
            /// \todo VV make this smarter
            Save<bool> save_in_any(&in_any, true);
            std::for_each(a->begin(), a->end(), accept_visitor(this));
        }

        void visit(const BlockDepSpec * const b)
        {
            if (b->blocked_spec()->package_ptr() &&
                    env->package_database()->query(query::Package(*b->blocked_spec()->package_ptr()),
                        qo_whatever)->empty())
                result << Message(qal_maybe, "No match for " + role + " block '!"
                        + stringify(*b->blocked_spec()->package_ptr()) + "'");
        }

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

DepsExistCheck::DepsExistCheck()
{
}

CheckResult
DepsExistCheck::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));

        Checker depend_checker(result, "DEPEND", e.environment);
        metadata->deps_interface->build_depend()->accept(&depend_checker);

        Checker rdepend_checker(result, "RDEPEND", e.environment);
        metadata->deps_interface->run_depend()->accept(&rdepend_checker);

        Checker pdepend_checker(result, "PDEPEND", e.environment);
        metadata->deps_interface->post_depend()->accept(&pdepend_checker);
    }
    catch (const InternalError &)
    {
        throw;
    }
    catch (const Exception & err)
    {
        result << Message(qal_fatal, "Caught Exception '" + err.message() + "' ("
                + err.what() + ")");
    }

    return result;
}

const std::string &
DepsExistCheck::identifier()
{
    static const std::string id("deps_exist");
    return id;
}