aboutsummaryrefslogtreecommitdiff
path: root/paludis/dep_list.hh
blob: 5deb9a82c0800de672ff19923b6997a6c3654b39 (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
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010 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
 */

#ifndef PALUDIS_GUARD_PALUDIS_DEP_LIST_HH
#define PALUDIS_GUARD_PALUDIS_DEP_LIST_HH 1

#include <paludis/dep_spec-fwd.hh>
#include <paludis/mask-fwd.hh>
#include <paludis/dep_tag.hh>
#include <paludis/dep_list_options.hh>
#include <paludis/dep_list-fwd.hh>
#include <paludis/handled_information-fwd.hh>
#include <paludis/name.hh>
#include <paludis/environment.hh>
#include <paludis/match_package.hh>
#include <paludis/util/instantiation_policy.hh>
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/util/options.hh>
#include <paludis/version_spec.hh>
#include <tr1/functional>
#include <iosfwd>

/** \file
 * Declarations for DepList and related classes.
 *
 * \ingroup g_dep_list
 *
 * \section Examples
 *
 * - None at this time. Use InstallTask if you need to install things.
 */

namespace paludis
{
    namespace n
    {
        typedef Name<struct associated_entry_name> associated_entry;
        typedef Name<struct blocks_name> blocks;
        typedef Name<struct circular_name> circular;
        typedef Name<struct dependency_tags_name> dependency_tags;
        typedef Name<struct destination_name> destination;
        typedef Name<struct downgrade_name> downgrade;
        typedef Name<struct fall_back_name> fall_back;
        typedef Name<struct generation_name> generation;
        typedef Name<struct handled_name> handled;
        typedef Name<struct installed_deps_post_name> installed_deps_post;
        typedef Name<struct installed_deps_pre_name> installed_deps_pre;
        typedef Name<struct installed_deps_runtime_name> installed_deps_runtime;
        typedef Name<struct kind_name> kind;
        typedef Name<struct match_package_options_name> match_package_options;
        typedef Name<struct new_slots_name> new_slots;
        typedef Name<struct override_masks_name> override_masks;
        typedef Name<struct package_id_name> package_id;
        typedef Name<struct reinstall_name> reinstall;
        typedef Name<struct reinstall_scm_name> reinstall_scm;
        typedef Name<struct state_name> state;
        typedef Name<struct suggested_name> suggested;
        typedef Name<struct tags_name> tags;
        typedef Name<struct target_type_name> target_type;
        typedef Name<struct uninstalled_deps_post_name> uninstalled_deps_post;
        typedef Name<struct uninstalled_deps_pre_name> uninstalled_deps_pre;
        typedef Name<struct uninstalled_deps_runtime_name> uninstalled_deps_runtime;
        typedef Name<struct uninstalled_deps_suggested_name> uninstalled_deps_suggested;
        typedef Name<struct upgrade_name> upgrade;
        typedef Name<struct use_name> use;
    }

    /**
     * A sequence of functions to try, in order, when overriding masks.
     *
     * \ingroup g_dep_list
     */
    typedef Sequence<std::tr1::function<bool (const PackageID &, const Mask &)> > DepListOverrideMasksFunctions;

    /**
     * An entry in a DepList.
     *
     * \see DepList
     * \ingroup g_dep_list
     * \nosubgrouping
     */
    struct DepListEntry
    {
        NamedValue<n::associated_entry, const DepListEntry *> associated_entry;
        NamedValue<n::destination, std::tr1::shared_ptr<Repository> > destination;
        NamedValue<n::generation, long> generation;
        NamedValue<n::handled, std::tr1::shared_ptr<const DepListEntryHandled> > handled;
        NamedValue<n::kind, DepListEntryKind> kind;
        NamedValue<n::package_id, std::tr1::shared_ptr<const PackageID> > package_id;
        NamedValue<n::state, DepListEntryState> state;
        NamedValue<n::tags, std::tr1::shared_ptr<DepListEntryTags> > tags;
    };

    /**
     * Parameters for a DepList.
     *
     * \see DepList
     * \ingroup g_dep_list
     * \nosubgrouping
     */
    struct PALUDIS_VISIBLE DepListOptions
    {
        DepListOptions();

        NamedValue<n::blocks, DepListBlocksOption> blocks;
        NamedValue<n::circular, DepListCircularOption> circular;
        NamedValue<n::dependency_tags, bool> dependency_tags;
        NamedValue<n::downgrade, DepListDowngradeOption> downgrade;
        NamedValue<n::fall_back, DepListFallBackOption> fall_back;
        NamedValue<n::installed_deps_post, DepListDepsOption> installed_deps_post;
        NamedValue<n::installed_deps_pre, DepListDepsOption> installed_deps_pre;
        NamedValue<n::installed_deps_runtime, DepListDepsOption> installed_deps_runtime;
        NamedValue<n::match_package_options, MatchPackageOptions> match_package_options;
        NamedValue<n::new_slots, DepListNewSlotsOption> new_slots;
        NamedValue<n::override_masks, std::tr1::shared_ptr<DepListOverrideMasksFunctions> > override_masks;
        NamedValue<n::reinstall, DepListReinstallOption> reinstall;
        NamedValue<n::reinstall_scm, DepListReinstallScmOption> reinstall_scm;
        NamedValue<n::suggested, DepListSuggestedOption> suggested;
        NamedValue<n::target_type, DepListTargetType> target_type;
        NamedValue<n::uninstalled_deps_post, DepListDepsOption> uninstalled_deps_post;
        NamedValue<n::uninstalled_deps_pre, DepListDepsOption> uninstalled_deps_pre;
        NamedValue<n::uninstalled_deps_runtime, DepListDepsOption> uninstalled_deps_runtime;
        NamedValue<n::uninstalled_deps_suggested, DepListDepsOption> uninstalled_deps_suggested;
        NamedValue<n::upgrade, DepListUpgradeOption> upgrade;
        NamedValue<n::use, DepListUseOption> use;
    };

    /**
     * Holds a list of dependencies in merge order.
     *
     * \ingroup g_dep_list
     * \nosubgrouping
     */
    class PALUDIS_VISIBLE DepList :
        private InstantiationPolicy<DepList, instantiation_method::NonCopyableTag>,
        private PrivateImplementationPattern<DepList>
    {
        protected:
            class AddVisitor;
            friend class AddVisitor;

            /**
             * Find an appropriate destination for a package.
             */
            std::tr1::shared_ptr<Repository> find_destination(const PackageID &,
                    const std::tr1::shared_ptr<const DestinationsSet> &);

            /**
             * Add a DepSpec with role context.
             */
            void add_in_role(const bool only_if_not_suggested_label, const DependencySpecTree::BasicNode &, const std::string & role,
                    const std::tr1::shared_ptr<const DestinationsSet> &);

            /**
             * Return whether we prefer the first parameter, which is installed,
             * over the second, which isn't.
             */
            bool prefer_installed_over_uninstalled(const PackageID &,
                    const PackageID &);

            /**
             * Add a package to the list.
             */
            void add_package(const std::tr1::shared_ptr<const PackageID> &, const std::tr1::shared_ptr<const DepTag> &,
                    const PackageDepSpec &, const std::tr1::shared_ptr<const DestinationsSet> & destinations);

            /**
             * Add an already installed package to the list.
             */
            void add_already_installed_package(const std::tr1::shared_ptr<const PackageID> &, const std::tr1::shared_ptr<const DepTag> &,
                    const PackageDepSpec &, const std::tr1::shared_ptr<const DestinationsSet> & destinations);

            /**
             * Add an error package to the list.
             */
            void add_error_package(const std::tr1::shared_ptr<const PackageID> &, const DepListEntryKind, const PackageDepSpec &);

            /**
             * Add predependencies.
             */
            void add_predeps(const DependencySpecTree::BasicNode &, const DepListDepsOption, const std::string &,
                    const std::tr1::shared_ptr<const DestinationsSet> & destinations, const bool only_if_not_suggested_label);

            /**
             * Add postdependencies.
             */
            void add_postdeps(const DependencySpecTree::BasicNode &, const DepListDepsOption, const std::string &,
                    const std::tr1::shared_ptr<const DestinationsSet> & destinations, const bool only_if_not_suggested_label);

            /**
             * Return whether the specified PackageID is matched by
             * the top level target.
             */
            bool is_top_level_target(const PackageID &) const;

            void add_not_top_level(
                    const bool only_if_not_suggested_label,
                    const DependencySpecTree::BasicNode &,
                    const std::tr1::shared_ptr<const DestinationsSet> & target_destinations);

        public:
            ///\name Basic operations
            ///\{

            DepList(const Environment * const, const DepListOptions &);

            virtual ~DepList();

            ///\}

            ///\name Iterate over our dependency list entries.
            ///\{

            struct IteratorTag;
            typedef WrappedForwardIterator<IteratorTag, DepListEntry> Iterator;

            struct ConstIteratorTag;
            typedef WrappedForwardIterator<ConstIteratorTag, const DepListEntry> ConstIterator;

            Iterator begin();
            Iterator end();

            ConstIterator begin() const;
            ConstIterator end() const;

            ///\}

            /**
             * Our options.
             */
            std::tr1::shared_ptr<DepListOptions> options();

            /**
             * Our options.
             */
            const std::tr1::shared_ptr<const DepListOptions> options() const;

            /**
             * Add the packages required to resolve an additional dependency
             * spec.
             */
            void add(const SetSpecTree &,
                    const std::tr1::shared_ptr<const DestinationsSet> & target_destinations);

            /**
             * Add the packages required to resolve an additional dependency
             * spec.
             */
            void add(const PackageDepSpec &,
                    const std::tr1::shared_ptr<const DestinationsSet> & target_destinations);

            /**
             * Manually add a DepListEntry to the list.
             *
             * Does not work well with ordered resolution, and does not do much
             * sanity checking. This is used by InstallTask to implement resume
             * commands and the exec command.
             */
            Iterator push_back(const DepListEntry &);

            /**
             * Clear the list.
             */
            void clear();

            /**
             * Return whether a spec structure is already installed.
             */
            bool already_installed(const DependencySpecTree::BasicNode &,
                    const std::tr1::shared_ptr<const DestinationsSet> & target_destinations) const;

            /**
             * Return whether a PackageID has been replaced.
             */
            bool replaced(const PackageID &) const;

            /**
             * Return whether a spec matches an item in the list.
             */
            bool match_on_list(const PackageDepSpec &) const;

            /**
             * Whether we have any errors.
             */
            bool has_errors() const;

            /**
             * Add a suggested package to the list.
             */
            void add_suggested_package(const std::tr1::shared_ptr<const PackageID> &,
                    const PackageDepSpec &, const std::tr1::shared_ptr<const DestinationsSet> & destinations);
    };

#ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
    extern template class PrivateImplementationPattern<DepList>;
    extern template class WrappedForwardIterator<DepList::IteratorTag, DepListEntry>;
    extern template class WrappedForwardIterator<DepList::ConstIteratorTag, const DepListEntry>;
    extern template WrappedForwardIterator<DepList::ConstIteratorTag, const DepListEntry>::WrappedForwardIterator(const DepList::Iterator &);
#endif
}

#endif