aboutsummaryrefslogtreecommitdiff
path: root/paludis/qa/dep_any_check.cc
blob: 660bbbccea023735a14d3f45f878b38d225865fd (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
138
139
140
141
142
143
144
145
146
147
148
/* 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/qa/dep_any_check.hh>

#include <paludis/portage_dep_parser.hh>
#include <paludis/dep_spec.hh>
#include <paludis/package_database_entry.hh>
#include <paludis/environment.hh>
#include <paludis/util/iterator.hh>
#include <paludis/util/save.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
    {
        CheckResult & result;
        const std::string role;
        bool in_any;

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

        void visit(const PackageDepSpec * const)
        {
        }

        void visit(const AllDepSpec * const a)
        {
            /* yes, the following line is correct. */
            Save<bool> in_any_save(&in_any, false);
            std::for_each(a->begin(), a->end(), accept_visitor(this));
        }

        void visit(const AnyDepSpec * const a)
        {
            Save<bool> in_any_save(&in_any, true);
            if (a->begin() == a->end())
                result << Message(qal_minor, "Empty || ( ) block in " + role);
            else
            {
                if (a->end() == next(a->begin()))
                    result << Message(qal_minor, "One item in || ( ) block in " + role);

                std::for_each(a->begin(), a->end(), accept_visitor(this));
            }
        }

        void visit(const UseDepSpec * const u)
        {
            if (in_any)
                result << Message(qal_maybe, "Conditional on '" + stringify(u->flag()) + 
                        "' inside || ( ) block in " + role);
            std::for_each(u->begin(), u->end(), accept_visitor(this));
        }

        void visit(const PlainTextDepSpec * const) PALUDIS_ATTRIBUTE((noreturn));

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

    void Checker::visit(const PlainTextDepSpec * const t)
    {
        throw InternalError(PALUDIS_HERE, "Found unexpected PlainTextDepSpec '"
                + t->text() + "'");
    }
}

DepAnyCheck::DepAnyCheck()
{
}

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

        if (metadata->deps_interface)
        {
            Checker depend_checker(result, "DEPEND");
            std::string depend(metadata->deps_interface->build_depend_string);
            PortageDepParser::parse(depend)->accept(&depend_checker);

            Checker rdepend_checker(result, "RDEPEND");
            std::string rdepend(metadata->deps_interface->run_depend_string);
            PortageDepParser::parse(rdepend)->accept(&rdepend_checker);

            Checker pdepend_checker(result, "PDEPEND");
            std::string pdepend(metadata->deps_interface->post_depend_string);
            PortageDepParser::parse(pdepend)->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 &
DepAnyCheck::identifier()
{
    static const std::string id("any_deps");
    return id;
}