aboutsummaryrefslogtreecommitdiff
path: root/0.18.0/paludis/environment.hh
blob: 8a958e38b9ef46f1a58246fb108bce6787577307 (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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2005, 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
 */

#ifndef PALUDIS_GUARD_PALUDIS_ENVIRONMENT_HH
#define PALUDIS_GUARD_PALUDIS_ENVIRONMENT_HH 1

#include <paludis/mask_reasons.hh>
#include <paludis/name.hh>
#include <paludis/package_database.hh>
#include <paludis/util/instantiation_policy.hh>

/** \file
 * Declarations for the Environment class.
 *
 * \ingroup grpenvironment
 */

namespace paludis
{
    struct EnvironmentMirrorIteratorTag;

    /**
     * Iterate over environment mirrors.
     *
     * \see Environment
     * \ingroup grpenvironment
     */
    typedef libwrapiter::ForwardIterator<EnvironmentMirrorIteratorTag,
            const std::pair<const std::string, std::string> > EnvironmentMirrorIterator;

    /**
     * Represents the data for an Environment hook call.
     *
     * \ingroup grpenvironment
     */
    class Hook
    {
        private:
            std::map<std::string, std::string> _extra_env;

            std::string _name;

        public:
            /// Constructor.
            Hook(const std::string & name);

            /// Perform the hook.
            Hook operator() (const std::string & key, const std::string & value) const;

            /// Iterate over extra environment data.
            typedef std::map<std::string, std::string>::const_iterator Iterator;

            /// Start of extra environment data.
            Iterator begin() const
            {
                return _extra_env.begin();
            }

            /// End of extra environment data.
            Iterator end() const
            {
                return _extra_env.end();
            }

            /// Our name.
            std::string name() const
            {
                return _name;
            }
    };

    /**
     * Represents a working environment, which contains an available packages
     * database and provides various methods for querying package visibility
     * and options.
     *
     * \ingroup grpenvironment
     */
    class Environment :
        private InstantiationPolicy<Environment, instantiation_method::NonCopyableTag>
    {
        private:
            std::tr1::shared_ptr<PackageDatabase> _package_database;

            mutable bool _has_provide_map;

            mutable std::map<QualifiedPackageName, QualifiedPackageName> _provide_map;

        protected:
            /**
             * Constructor.
             */
            Environment(std::tr1::shared_ptr<PackageDatabase>);

            /**
             * Local package set, or zero.
             */
            virtual std::tr1::shared_ptr<CompositeDepAtom> local_package_set(const SetName &) const
            {
                return std::tr1::shared_ptr<AllDepAtom>();
            }

            /**
             * Change our package database.
             */
            void change_package_database(std::tr1::shared_ptr<PackageDatabase> _p)
            {
                _package_database = _p;
            }

        public:
            /**
             * Does the user want the specified USE flag set for a
             * particular package?
             *
             * Default behaviour: all USE flags turned off, unless overridden by
             * the repository for the pde.
             */
            virtual bool query_use(const UseFlagName &, const PackageDatabaseEntry *) const;

            /**
             * Fetch any known use expand names (excluding prefix) that start with a
             * given prefix.
             *
             * Default behaviour: no names known.
             */
            virtual std::tr1::shared_ptr<const UseFlagNameCollection> known_use_expand_names(const UseFlagName &,
                    const PackageDatabaseEntry *) const;

            /**
             * Is the specified KEYWORD accepted?
             *
             * Default behaviour: only "*" accepted.
             */
            virtual bool accept_keyword(const KeywordName &, const PackageDatabaseEntry * const,
                    const bool override_tilde_keywords = false) const;

            /**
             * Is the specified EAPI accepted?
             *
             * Default behaviour: known EAPIs accepted.
             */
            virtual bool accept_eapi(const std::string &) const;

            /**
             * Is the specified LICENSE accepted?
             *
             * Default behaviour: yes.
             */
            virtual bool accept_license(const std::string &, const PackageDatabaseEntry * const) const;

            /**
             * Fetch the masks for a particular package.
             */
            MaskReasons mask_reasons(const PackageDatabaseEntry &,
                    const bool override_tilde_keywords = false,
                    const bool override_unkeyworded = false) const;

            /**
             * Are there any user masks on a package?
             *
             * Default behaviour: no.
             */
            virtual bool query_user_masks(const PackageDatabaseEntry &) const;

            /**
             * Are there any user unmasks on a package?
             *
             * Default behaviour: no.
             */
            virtual bool query_user_unmasks(const PackageDatabaseEntry &) const;

            /**
             * Fetch our package database.
             */
            std::tr1::shared_ptr<const PackageDatabase> package_database() const
            {
                return _package_database;
            }

            /**
             * Fetch our package database.
             */
            std::tr1::shared_ptr<PackageDatabase> package_database()
            {
                return _package_database;
            }

            /**
             * Our bashrc files.
             *
             * Default behaviour: none.
             */
            virtual std::string bashrc_files() const;

            /**
             * Our hook directories.
             *
             * Default behaviour: none.
             */
            virtual std::string hook_dirs() const;

            /**
             * Our fetchers directories.
             *
             * Default behaviour: user then paludis fetcher dirs.
             */
            virtual std::string fetchers_dirs() const;

            /**
             * Our syncers directories.
             *
             * Default behaviour: user then paludis syncer dirs.
             */
            virtual std::string syncers_dirs() const;

            /**
             * How to run paludis.
             */
            virtual std::string paludis_command() const = 0;

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

            /**
             * Iterator over named mirror entries.
             */
            typedef EnvironmentMirrorIterator MirrorIterator;

            /**
             * Iterator to the start of our mirrors.
             *
             * Default behaviour: no mirrors. If specialising, also do
             * Environment::end_mirrors.
             */
            virtual MirrorIterator begin_mirrors(const std::string & mirror) const;

            /**
             * Iterator to past the end of our mirrors.
             *
             * Default behaviour: no mirrors. If specialising, also do
             * Environment::begin_mirrors.
             */
            virtual MirrorIterator end_mirrors(const std::string & mirror) const;

            /**
             * Fetch a named package set.
             */
            std::tr1::shared_ptr<DepAtom> package_set(const SetName &) const;

            /**
             * Fetch all named sets. Does not include sets from repositories.
             *
             * Default behaviour: no sets.
             */
            virtual std::tr1::shared_ptr<const SetsCollection> sets_list() const;

            /**
             * Subclass for callbacks used by add_appropriate_to_world and
             * remove_appropriate_from_world.
             *
             * \ingroup grpenvironment
             * \nosubgrouping
             */
            class WorldCallbacks
            {
                protected:
                    ///\name Basic operations
                    ///\{

                    WorldCallbacks();

                    ///\}

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

                    virtual ~WorldCallbacks();

                    ///\}

                    /**
                     * Called when adding an entry to world.
                     */
                    virtual void add_callback(const PackageDepAtom &);

                    /**
                     * Called when skipping adding an entry to world.
                     */
                    virtual void skip_callback(const PackageDepAtom &, const std::string &);

                    /**
                     * Called when removing an entry to world.
                     */
                    virtual void remove_callback(const PackageDepAtom &);

                    /**
                     * Called when adding an entry to world.
                     */
                    virtual void add_callback(const SetName &);

                    /**
                     * Called when skipping adding an entry to world.
                     */
                    virtual void skip_callback(const SetName &, const std::string &);

                    /**
                     * Called when removing an entry from world.
                     */
                    virtual void remove_callback(const SetName &);
            };

            /**
             * Add packages to world, if they are not there already, and if they are
             * not a restricted atom.
             */
            void add_appropriate_to_world(std::tr1::shared_ptr<const DepAtom> a, WorldCallbacks *) const;

            /**
             * Remove packages from world, if they are there.
             */
            void remove_appropriate_from_world(std::tr1::shared_ptr<const DepAtom>, WorldCallbacks *) const;

            /**
             * Add a set to world, if it's not inappropriate.
             */
            void add_set_to_world(const SetName &, WorldCallbacks *) const;

            /**
             * Remove a set from world.
             */
            void remove_set_from_world(const SetName &, WorldCallbacks *) const;

            /**
             * Perform a hook.
             *
             * Default behaviour: nothing happens.
             */
            virtual void perform_hook(const Hook & hook) const;
    };
}

#endif