aboutsummaryrefslogtreecommitdiff
path: root/paludis/dep_list.hh
blob: b93beee0c4ca7bcc212a515db37dad0314735173 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
 *
 * 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
 */

#ifndef PALUDIS_GUARD_PALUDIS_DEP_LIST_HH
#define PALUDIS_GUARD_PALUDIS_DEP_LIST_HH 1

#include <algorithm>
#include <bitset>
#include <deque>
#include <iterator>
#include <list>
#include <ostream>
#include <set>
#include <paludis/dep_atom.hh>
#include <paludis/dep_tag.hh>
#include <paludis/name.hh>
#include <paludis/environment.hh>
#include <paludis/util/instantiation_policy.hh>
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/util/smart_record.hh>
#include <paludis/version_spec.hh>

namespace paludis
{
    /**
     * Keys for a DepListEntry.
     */
    enum DepListEntryKeys
    {
        dle_name,            ///< Package name
        dle_version,         ///< Package version
        dle_metadata,        ///< Package SLOT
        dle_repository,      ///< Repository name
        dle_flags,           ///< Flags
        dle_tag,             ///< Our tag
        last_dle             ///< Number of entries
    };

    /**
     * Flags for a DepListEntry.
     */
    enum DepListEntryFlag
    {
        dlef_has_predeps,
        dlef_has_trypredeps,
        dlef_has_postdeps,
        dlef_skip,
        last_dlef
    };

    /**
     * Flags for a DepListEntry.
     */
    typedef std::bitset<last_dlef> DepListEntryFlags;

    /**
     * Tag for a DepListEntry.
     */
    struct DepListEntryTag :
        SmartRecordTag<comparison_mode::EqualityComparisonTag, comparison_method::SmartRecordCompareByAllTag>,
        SmartRecordKeys<DepListEntryKeys, last_dle>,
        SmartRecordKey<dle_name, QualifiedPackageName>,
        SmartRecordKey<dle_version, VersionSpec>,
        SmartRecordKey<dle_metadata, VersionMetadata::ConstPointer>,
        SmartRecordKey<dle_repository, RepositoryName>,
        SmartRecordKey<dle_flags, DepListEntryFlags>,
        SmartRecordKey<dle_tag, std::set<DepTag::ConstPointer, DepTag::Comparator> >
    {
    };

    /**
     * A DepListEntry represents an entry in a DepList.
     */
    typedef MakeSmartRecord<DepListEntryTag>::Type DepListEntry;

    /**
     * A DepListEntry can be written to a stream.
     */
    std::ostream & operator<< (std::ostream &, const DepListEntry &);

    /**
     * Thrown if an error occurs whilst building a DepList.
     */
    class DepListError : public Exception
    {
        protected:
            /**
             * Constructor.
             */
            DepListError(const std::string &) throw ();
    };

    /**
     * Thrown if a DepList's add stack gets too deep.
     */
    class DepListStackTooDeepError : public DepListError
    {
        public:
            /**
             * Constructor.
             */
            DepListStackTooDeepError(int level) throw ();
    };

    /**
     * Thrown if no entry in a || ( ) block is resolvable.
     */
    class NoResolvableOptionError : public DepListError
    {
        public:
            /**
             * Constructor.
             */
            NoResolvableOptionError() throw ();

            /**
             * Constructor with failure reasons.
             */
            template <typename I_>
            NoResolvableOptionError(I_ i, I_ end) throw ();
    };

    /**
     * Thrown if all versions of a particular atom are masked.
     */
    class AllMaskedError : public DepListError
    {
        private:
            std::string _query;

        public:
            /**
             * Constructor.
             */
            AllMaskedError(const std::string & query) throw ();

            /**
             * Destructor.
             */
            virtual ~AllMaskedError() throw ()
            {
            }

            /**
             * Our query.
             */
            const std::string & query() const
            {
                return _query;
            }
    };

    /**
     * Thrown if a block is encountered.
     */
    class BlockError : public DepListError
    {
        public:
            /**
             * Constructor.
             */
            BlockError(const std::string & msg) throw ();
    };

    /**
     * Thrown if a circular dependency is encountered.
     */
    class CircularDependencyError : public DepListError
    {
        private:
            unsigned _cycle_size;

        public:
            /**
             * Constructor, from a sequence of the items causing the circular
             * dependency.
             */
            template <typename I_>
            CircularDependencyError(I_ begin, const I_ end) throw () :
                DepListError("Circular dependency: " + join(begin, end, " -> ")),
                _cycle_size(std::distance(begin, end))
            {
            }

            /**
             * How large is our circular dependency cycle?
             */
            unsigned cycle_size() const
            {
                return _cycle_size;
            }
    };

    /**
     * Used in DepList::set_rdepend_post
     */
    enum DepListRdependOption 
    { 
        /**
         * RDEPENDs are always merged before the package; abort if this fails.
         */
        dlro_never,

        /**
         * RDEPENDs can be merged after the package, just before PDEPEND, if this is
         * necessary for correct resolution
         */
        dlro_as_needed,

        /**
         * RDEPENDs are always merged with PDEPENDs.
         */
        dlro_always
    };

    /**
     * Holds a list of dependencies in merge order.
     */
    class DepList :
        private InstantiationPolicy<DepList, instantiation_method::NonCopyableTag>,
        private PrivateImplementationPattern<DepList>,
        protected DepAtomVisitorTypes::ConstVisitor
    {
        private:
            void _add_raw(const DepAtom * const);

            void _add(DepAtom::ConstPointer a)
            {
                _add_raw(a.raw_pointer());
            }

            void _add_in_role_raw(const DepAtom * const, const std::string & role);

            void _add_in_role(DepAtom::ConstPointer a, const std::string & role)
            {
                _add_in_role_raw(a.raw_pointer(), role);
            }

        protected:
            ///\name Visit functions
            ///{
            void visit(const PlainTextDepAtom * const) PALUDIS_ATTRIBUTE((noreturn));
            void visit(const PackageDepAtom * const);
            void visit(const UseDepAtom * const);
            void visit(const AnyDepAtom * const);
            void visit(const BlockDepAtom * const);
            void visit(const AllDepAtom * const);
            ///}

        public:
            /**
             * Iterator for our children.
             */
            typedef std::list<DepListEntry>::const_iterator Iterator;

            /**
             * Constructor.
             */
            DepList(const Environment * const);

            /**
             * Destructor.
             */
            virtual ~DepList();

            /**
             * Add the packages required to resolve an additional dependency
             * atom.
             */
            void add(DepAtom::ConstPointer);

            /**
             * Start of our dependency list.
             */
            Iterator begin() const;

            /**
             * One past the end of our dependency list.
             */
            Iterator end() const;

            /**
             * Behaviour: determines when RDEPEND entries can be treated as PDEPEND.
             */
            void set_rdepend_post(const DepListRdependOption value);

            /**
             * Behaviour: if set, a package that depends directly upon itself
             * will be accepted.
             */
            void set_drop_self_circular(const bool value);

            /**
             * Behaviour: if set, any circular dependencies are treated as if
             * they do not exist.
             */
            void set_drop_circular(const bool value);

            /**
             * Behaviour: if set, any dependencies are treated as if
             * they do not exist.
             */
            void set_drop_all(const bool value);

            /**
             * Behaviour: ignore installed packages.
             */
            void set_ignore_installed(const bool value);

            /**
             * Behaviour: check nth level dependencies for packages that are
             * already installed.
             */
            void set_recursive_deps(const bool value);

            /**
             * Behaviour: set the maximum stack depth.
             */
            void set_max_stack_depth(const int value);

            /**
             * Behaviour: set whether we reinstall first level deps.
             */
            void set_reinstall(const bool value);
    };
}

#endif