aboutsummaryrefslogtreecommitdiff
path: root/paludis/dep_spec.cc
blob: 432f0fbf693b9c4aa4a2854f16afdaa1a8372c94 (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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

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

#include <paludis/dep_spec.hh>
#include <paludis/environment.hh>
#include <paludis/version_operator.hh>
#include <paludis/version_spec.hh>
#include <paludis/version_requirements.hh>
#include <paludis/util/clone-impl.hh>
#include <paludis/util/log.hh>
#include <paludis/util/join.hh>
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/mutex.hh>
#include <paludis/util/sequence-impl.hh>
#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <paludis/util/wrapped_output_iterator.hh>
#include <paludis/util/iterator_funcs.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/options.hh>
#include <paludis/additional_package_dep_spec_requirement.hh>
#include <paludis/dep_spec_data.hh>

#include <functional>
#include <algorithm>
#include <list>
#include <map>

using namespace paludis;

namespace paludis
{
    template <>
    struct Imp<DepSpec>
    {
        std::shared_ptr<const DepSpecAnnotations> annotations;
    };
}

DepSpec::DepSpec() :
    _imp()
{
}

DepSpec::~DepSpec()
{
}

const std::shared_ptr<const DepSpecAnnotations>
DepSpec::maybe_annotations() const
{
    return _imp->annotations;
}

void
DepSpec::set_annotations(const std::shared_ptr<const DepSpecAnnotations> & a)
{
    _imp->annotations = a;
}

AnyDepSpec::AnyDepSpec()
{
}

std::shared_ptr<DepSpec>
AnyDepSpec::clone() const
{
    std::shared_ptr<AnyDepSpec> result(std::make_shared<AnyDepSpec>());
    result->set_annotations(maybe_annotations());
    return result;
}

AllDepSpec::AllDepSpec()
{
}

std::shared_ptr<DepSpec>
AllDepSpec::clone() const
{
    std::shared_ptr<AllDepSpec> result(std::make_shared<AllDepSpec>());
    result->set_annotations(maybe_annotations());
    return result;
}

ExactlyOneDepSpec::ExactlyOneDepSpec()
{
}

std::shared_ptr<DepSpec>
ExactlyOneDepSpec::clone() const
{
    std::shared_ptr<ExactlyOneDepSpec> result(std::make_shared<ExactlyOneDepSpec>());
    result->set_annotations(maybe_annotations());
    return result;
}

namespace paludis
{
    template <>
    struct Imp<ConditionalDepSpec>
    {
        const std::shared_ptr<const ConditionalDepSpecData> data;

        Imp(const std::shared_ptr<const ConditionalDepSpecData> & d) :
            data(d)
        {
        }
    };
}

ConditionalDepSpec::ConditionalDepSpec(const std::shared_ptr<const ConditionalDepSpecData> & d) :
    _imp(d)
{
}

namespace
{
    template <void (ConditionalDepSpec::* f_) () const>
    const ConditionalDepSpec & horrible_hack_to_force_key_copy(const ConditionalDepSpec & spec)
    {
        (spec.*f_)();
        return spec;
    }
}

ConditionalDepSpec::ConditionalDepSpec(const ConditionalDepSpec & other) :
    Cloneable<DepSpec>(),
    DepSpec(),
    CloneUsingThis<DepSpec, ConditionalDepSpec>(other),
    _imp(other._imp->data)
{
    set_annotations(other.maybe_annotations());
}

ConditionalDepSpec::~ConditionalDepSpec()
{
}

bool
ConditionalDepSpec::condition_met(const Environment * const env, const std::shared_ptr<const PackageID> & id) const
{
    return _imp->data->condition_met(env, id);
}

bool
ConditionalDepSpec::condition_would_be_met_when(
        const Environment * const env,
        const std::shared_ptr<const PackageID> & id,
        const ChangedChoices & c) const
{
    return _imp->data->condition_would_be_met_when(env, id, c);
}

bool
ConditionalDepSpec::condition_meetable(const Environment * const env, const std::shared_ptr<const PackageID> & id) const
{
    return _imp->data->condition_meetable(env, id);
}

const std::shared_ptr<const ConditionalDepSpecData>
ConditionalDepSpec::data() const
{
    return _imp->data;
}

std::string
ConditionalDepSpec::_as_string() const
{
    return _imp->data->as_string();
}

std::string
StringDepSpec::text() const
{
    return _str;
}

NamedSetDepSpec::NamedSetDepSpec(const SetName & n) :
    StringDepSpec(stringify(n)),
    _name(n)
{
}

const SetName
NamedSetDepSpec::name() const
{
    return _name;
}

std::shared_ptr<DepSpec>
NamedSetDepSpec::clone() const
{
    std::shared_ptr<NamedSetDepSpec> result(std::make_shared<NamedSetDepSpec>(_name));
    result->set_annotations(maybe_annotations());
    return result;
}

BlockDepSpec::BlockDepSpec(const std::string & s, const PackageDepSpec & p) :
    StringDepSpec(s),
    _spec(p)
{
}

BlockDepSpec::BlockDepSpec(const BlockDepSpec & other) :
    StringDepSpec(other.text()),
    _spec(other._spec)
{
    set_annotations(other.maybe_annotations());
}

std::ostream &
paludis::operator<< (std::ostream & s, const PlainTextDepSpec & a)
{
    s << a.text();
    return s;
}

std::ostream &
paludis::operator<< (std::ostream & s, const LicenseDepSpec & a)
{
    s << a.text();
    return s;
}

std::ostream &
paludis::operator<< (std::ostream & s, const NamedSetDepSpec & a)
{
    s << a.name();
    return s;
}

std::ostream &
paludis::operator<< (std::ostream & s, const BlockDepSpec & a)
{
    s << a.text();
    return s;
}

std::ostream &
paludis::operator<< (std::ostream & s, const FetchableURIDepSpec & p)
{
    if (! p.renamed_url_suffix().empty())
        s << p.original_url() << " -> " << p.renamed_url_suffix();
    else
        s << p.original_url();

    return s;
}

std::ostream &
paludis::operator<< (std::ostream & s, const SimpleURIDepSpec & p)
{
    s << p.text();
    return s;
}

std::ostream &
paludis::operator<< (std::ostream & s, const PackageDepSpec & a)
{
    s << a._as_string();
    return s;
}

std::ostream &
paludis::operator<< (std::ostream & s, const ConditionalDepSpec & a)
{
    s << a._as_string();
    return s;
}

std::ostream &
paludis::operator<< (std::ostream & s, const URILabelsDepSpec & l)
{
    s << join(indirect_iterator(l.begin()), indirect_iterator(l.end()), "+") << ":";
    return s;
}

std::ostream &
paludis::operator<< (std::ostream & s, const DependenciesLabelsDepSpec & l)
{
    s << join(indirect_iterator(l.begin()), indirect_iterator(l.end()), "+") << ":";
    return s;
}

std::ostream &
paludis::operator<< (std::ostream & s, const PlainTextLabelDepSpec & l)
{
    s << l.label() << ":";
    return s;
}

PackageDepSpecError::PackageDepSpecError(const std::string & msg) throw () :
    Exception(msg)
{
}

StringDepSpec::StringDepSpec(const std::string & s) :
    _str(s)
{
}

StringDepSpec::~StringDepSpec()
{
}


PlainTextDepSpec::PlainTextDepSpec(const std::string & s) :
    StringDepSpec(s)
{
}

std::shared_ptr<DepSpec>
PlainTextDepSpec::clone() const
{
    std::shared_ptr<PlainTextDepSpec> result(std::make_shared<PlainTextDepSpec>(text()));
    result->set_annotations(maybe_annotations());
    return result;
}

PlainTextLabelDepSpec::PlainTextLabelDepSpec(const std::string & s) :
    StringDepSpec(s)
{
}

PlainTextLabelDepSpec::~PlainTextLabelDepSpec()
{
}

std::shared_ptr<DepSpec>
PlainTextLabelDepSpec::clone() const
{
    std::shared_ptr<PlainTextLabelDepSpec> result(std::make_shared<PlainTextLabelDepSpec>(text()));
    result->set_annotations(maybe_annotations());
    return result;
}

const std::string
PlainTextLabelDepSpec::label() const
{
    return text().substr(0, text().length() - 1);
}

LicenseDepSpec::LicenseDepSpec(const std::string & s) :
    StringDepSpec(s)
{
}

std::shared_ptr<DepSpec>
LicenseDepSpec::clone() const
{
    std::shared_ptr<LicenseDepSpec> result(std::make_shared<LicenseDepSpec>(text()));
    result->set_annotations(maybe_annotations());
    return result;
}

SimpleURIDepSpec::SimpleURIDepSpec(const std::string & s) :
    StringDepSpec(s)
{
}

std::shared_ptr<DepSpec>
SimpleURIDepSpec::clone() const
{
    std::shared_ptr<SimpleURIDepSpec> result(std::make_shared<SimpleURIDepSpec>(text()));
    result->set_annotations(maybe_annotations());
    return result;
}

const PackageDepSpec
BlockDepSpec::blocking() const
{
    return _spec;
}

std::shared_ptr<DepSpec>
BlockDepSpec::clone() const
{
    std::shared_ptr<BlockDepSpec> result(std::make_shared<BlockDepSpec>(*this));
    result->set_annotations(maybe_annotations());
    return result;
}

FetchableURIDepSpec::FetchableURIDepSpec(const std::string & s) :
    StringDepSpec(s)
{
}

std::string
FetchableURIDepSpec::original_url() const
{
    std::string::size_type p(text().find(" -> "));
    if (std::string::npos == p)
        return text();
    else
        return text().substr(0, p);
}

std::string
FetchableURIDepSpec::renamed_url_suffix() const
{
    std::string::size_type p(text().find(" -> "));
    if (std::string::npos == p)
        return "";
    else
        return text().substr(p + 4);
}

std::string
FetchableURIDepSpec::filename() const
{
    std::string rus = renamed_url_suffix();
    if (! rus.empty())
        return rus;

    std::string orig = original_url();
    std::string::size_type p(orig.rfind('/'));

    if (std::string::npos == p)
        return orig;
    return orig.substr(p+1);
}

std::shared_ptr<DepSpec>
FetchableURIDepSpec::clone() const
{
    std::shared_ptr<FetchableURIDepSpec> result(std::make_shared<FetchableURIDepSpec>(text()));
    result->set_annotations(maybe_annotations());
    return result;
}

namespace paludis
{
    template <typename T_>
    struct Imp<LabelsDepSpec<T_ > >
    {
        std::list<std::shared_ptr<const T_> > items;
    };

    template <>
    struct WrappedForwardIteratorTraits<DependenciesLabelsDepSpec::ConstIteratorTag>
    {
        typedef std::list<std::shared_ptr<const DependenciesLabel> >::const_iterator UnderlyingIterator;
    };

    template <>
    struct WrappedForwardIteratorTraits<URILabelsDepSpec::ConstIteratorTag>
    {
        typedef std::list<std::shared_ptr<const URILabel> >::const_iterator UnderlyingIterator;
    };
}

template <typename T_>
LabelsDepSpec<T_>::LabelsDepSpec() :
    _imp()
{
}

template <typename T_>
LabelsDepSpec<T_>::~LabelsDepSpec()
{
}

template <typename T_>
std::shared_ptr<DepSpec>
LabelsDepSpec<T_>::clone() const
{
    using namespace std::placeholders;
    std::shared_ptr<LabelsDepSpec<T_> > my_clone(std::make_shared<LabelsDepSpec<T_>>());
    my_clone->set_annotations(maybe_annotations());
    std::for_each(begin(), end(), std::bind(std::mem_fn(&LabelsDepSpec<T_>::add_label), my_clone.get(), _1));
    return my_clone;
}

template <typename T_>
typename LabelsDepSpec<T_>::ConstIterator
LabelsDepSpec<T_>::begin() const
{
    return ConstIterator(_imp->items.begin());
}

template <typename T_>
typename LabelsDepSpec<T_>::ConstIterator
LabelsDepSpec<T_>::end() const
{
    return ConstIterator(_imp->items.end());
}

template <typename T_>
void
LabelsDepSpec<T_>::add_label(const std::shared_ptr<const T_> & item)
{
    _imp->items.push_back(item);
}

namespace paludis
{
    template <>
    struct Imp<PackageDepSpec>
    {
        const std::shared_ptr<const PackageDepSpecData> data;

        Imp(const std::shared_ptr<const PackageDepSpecData> & d) :
            data(d)
        {
        }
    };
}

PackageDepSpec::PackageDepSpec(const std::shared_ptr<const PackageDepSpecData> & d) :
    Cloneable<DepSpec>(),
    StringDepSpec(d->as_string()),
    _imp(d)
{
}

PackageDepSpec::~PackageDepSpec()
{
}

PackageDepSpec::PackageDepSpec(const PackageDepSpec & d) :
    Cloneable<DepSpec>(d),
    StringDepSpec(d._imp->data->as_string()),
    CloneUsingThis<DepSpec, PackageDepSpec>(d),
    _imp(d._imp->data)
{
    set_annotations(d.maybe_annotations());
}

const std::shared_ptr<const NameConstraint>
PackageDepSpec::package_name_constraint() const
{
    return _imp->data->package_name_constraint();
}

const std::shared_ptr<const PackageNamePartConstraint>
PackageDepSpec::package_name_part_constraint() const
{
    return _imp->data->package_name_part_constraint();
}

const std::shared_ptr<const CategoryNamePartConstraint>
PackageDepSpec::category_name_part_constraint() const
{
    return _imp->data->category_name_part_constraint();
}

std::shared_ptr<const VersionRequirements>
PackageDepSpec::version_requirements_ptr() const
{
    return _imp->data->version_requirements_ptr();
}

VersionRequirementsMode
PackageDepSpec::version_requirements_mode() const
{
    return _imp->data->version_requirements_mode();
}

const std::shared_ptr<const AnySlotConstraint>
PackageDepSpec::any_slot_constraint() const
{
    return _imp->data->any_slot_constraint();
}

const std::shared_ptr<const ExactSlotConstraint>
PackageDepSpec::exact_slot_constraint() const
{
    return _imp->data->exact_slot_constraint();
}

const std::shared_ptr<const InRepositoryConstraint>
PackageDepSpec::in_repository_constraint() const
{
    return _imp->data->in_repository_constraint();
}

const std::shared_ptr<const InstallableToRepositoryConstraint>
PackageDepSpec::installable_to_repository_constraint() const
{
    return _imp->data->installable_to_repository_constraint();
}

const std::shared_ptr<const FromRepositoryConstraint>
PackageDepSpec::from_repository_constraint() const
{
    return _imp->data->from_repository_constraint();
}

const std::shared_ptr<const InstalledAtPathConstraint>
PackageDepSpec::installed_at_path_constraint() const
{
    return _imp->data->installed_at_path_constraint();
}

const std::shared_ptr<const InstallableToPathConstraint>
PackageDepSpec::installable_to_path_constraint() const
{
    return _imp->data->installable_to_path_constraint();
}

std::shared_ptr<const AdditionalPackageDepSpecRequirements>
PackageDepSpec::additional_requirements_ptr() const
{
    return _imp->data->additional_requirements_ptr();
}

std::string
PackageDepSpec::_as_string() const
{
    return _imp->data->as_string();
}

std::shared_ptr<const PackageDepSpecData>
PackageDepSpec::data() const
{
    return _imp->data;
}

template class LabelsDepSpec<URILabel>;
template class LabelsDepSpec<DependenciesLabel>;

template class Cloneable<DepSpec>;
template class Pimp<ConditionalDepSpec>;
template class CloneUsingThis<DepSpec, ConditionalDepSpec>;
template class Pimp<PackageDepSpec>;
template class CloneUsingThis<DepSpec, PackageDepSpec>;
template class Pimp<URILabelsDepSpec>;
template class Pimp<DependenciesLabelsDepSpec>;

template class WrappedForwardIterator<DependenciesLabelsDepSpec::ConstIteratorTag,
         const std::shared_ptr<const DependenciesLabel> >;
template class WrappedForwardIterator<URILabelsDepSpec::ConstIteratorTag,
         const std::shared_ptr<const URILabel> >;