-
Notifications
You must be signed in to change notification settings - Fork 285
/
dependencies.cpp
2523 lines (2133 loc) · 104 KB
/
dependencies.cpp
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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <vcpkg-test/util.h>
#include <vcpkg/commands.set-installed.h>
#include <vcpkg/dependencies.h>
#include <vcpkg/portfileprovider.h>
#include <vcpkg/sourceparagraph.h>
#include <vcpkg/vcpkgcmdarguments.h>
#include <memory>
#include <vector>
#include <vcpkg-test/mockcmakevarprovider.h>
using namespace vcpkg;
using Test::make_control_file;
using Test::make_status_feature_pgh;
using Test::make_status_pgh;
using Test::MockCMakeVarProvider;
using Test::PackageSpecMap;
struct MockBaselineProvider : IBaselineProvider
{
mutable std::map<std::string, Version, std::less<>> v;
ExpectedL<Version> get_baseline_version(StringView name) const override
{
auto it = v.find(name);
if (it == v.end())
return LocalizedString::from_raw("MockBaselineProvider::get_baseline_version(" + name.to_string() + ")");
return it->second;
}
};
struct MockVersionedPortfileProvider : IVersionedPortfileProvider
{
mutable std::map<std::string, std::map<Version, SourceControlFileAndLocation, VersionMapLess>> v;
ExpectedL<const SourceControlFileAndLocation&> get_control_file(
const vcpkg::VersionSpec& versionspec) const override
{
return get_control_file(versionspec.port_name, versionspec.version);
}
ExpectedL<const SourceControlFileAndLocation&> get_control_file(const std::string& name,
const vcpkg::Version& version) const
{
auto it = v.find(name);
if (it == v.end()) return LocalizedString::from_raw("Unknown port name");
auto it2 = it->second.find(version);
if (it2 == it->second.end()) return LocalizedString::from_raw("Unknown port version");
return it2->second;
}
virtual View<vcpkg::Version> get_port_versions(StringView) const override { Checks::unreachable(VCPKG_LINE_INFO); }
SourceControlFileAndLocation& emplace(std::string&& name,
Version&& version,
VersionScheme scheme = VersionScheme::String)
{
auto&& version_map = v[name];
auto it2 = version_map.find(version);
if (it2 == version_map.end())
{
auto scf = std::make_unique<SourceControlFile>();
auto core = std::make_unique<SourceParagraph>();
core->name = name;
core->version_scheme = scheme;
core->version = version;
scf->core_paragraph = std::move(core);
it2 = version_map
.emplace(std::move(version),
SourceControlFileAndLocation{std::move(scf), Path(std::move(name)) / "vcpkg.json"})
.first;
}
return it2->second;
}
};
struct CoreDependency : Dependency
{
CoreDependency(std::string name,
std::vector<DependencyRequestedFeature> features = {},
PlatformExpression::Expr platform = {})
: Dependency{std::move(name), std::move(features), std::move(platform)}
{
default_features = false;
}
};
static void check_name_and_features(const InstallPlanAction& ipa,
StringLiteral name,
std::initializer_list<StringLiteral> features)
{
CHECK(ipa.spec.name() == name);
CHECK(ipa.source_control_file_and_location.has_value());
{
INFO("ipa.feature_list = [" << Strings::join(", ", ipa.feature_list) << "]");
INFO("features = [" << Strings::join(", ", features) << "]");
CHECK(ipa.feature_list.size() == features.size() + 1);
for (auto&& f : features)
{
INFO("f = \"" << f.c_str() << "\"");
CHECK(Util::find(ipa.feature_list, f) != ipa.feature_list.end());
}
CHECK(Util::find(ipa.feature_list, "core") != ipa.feature_list.end());
}
}
static void check_name_and_version(const InstallPlanAction& ipa,
StringLiteral name,
Version v,
std::initializer_list<StringLiteral> features = {})
{
check_name_and_features(ipa, name, features);
if (auto scfl = ipa.source_control_file_and_location.get())
{
CHECK(scfl->source_control_file->core_paragraph->version == v);
}
}
static void check_semver_version(const ExpectedL<DotVersion>& maybe_version,
const std::string& version_string,
const std::string& prerelease_string,
uint64_t major,
uint64_t minor,
uint64_t patch,
const std::vector<std::string>& identifiers)
{
auto actual_version = maybe_version.value_or_exit(VCPKG_LINE_INFO);
CHECK(actual_version.version_string == version_string);
CHECK(actual_version.prerelease_string == prerelease_string);
REQUIRE(actual_version.version.size() == 3);
CHECK(actual_version.version[0] == major);
CHECK(actual_version.version[1] == minor);
CHECK(actual_version.version[2] == patch);
CHECK(actual_version.identifiers == identifiers);
}
static void check_relaxed_version(const ExpectedL<DotVersion>& maybe_version,
const std::vector<uint64_t>& version,
const std::vector<std::string>& identifiers = {})
{
auto actual_version = maybe_version.value_or_exit(VCPKG_LINE_INFO);
CHECK(actual_version.version == version);
CHECK(actual_version.identifiers == identifiers);
}
static void check_date_version(const ExpectedL<DateVersion>& maybe_version,
const std::string& version_string,
const std::vector<uint64_t>& identifiers)
{
auto actual_version = maybe_version.value_or_exit(VCPKG_LINE_INFO);
CHECK(actual_version.version_string == version_string);
CHECK(actual_version.identifiers == identifiers);
}
static const PackageSpec& toplevel_spec()
{
static const PackageSpec ret("toplevel-spec", Test::X86_WINDOWS);
return ret;
}
struct MockOverlayProvider : IOverlayProvider
{
MockOverlayProvider() = default;
MockOverlayProvider(const MockOverlayProvider&) = delete;
MockOverlayProvider& operator=(const MockOverlayProvider&) = delete;
virtual Optional<const SourceControlFileAndLocation&> get_control_file(StringView name) const override
{
auto it = mappings.find(name);
if (it == mappings.end())
{
return nullopt;
}
return it->second;
}
SourceControlFileAndLocation& emplace(const std::string& name,
Version&& version,
VersionScheme scheme = VersionScheme::String)
{
auto it = mappings.find(name);
if (it == mappings.end())
{
auto scf = std::make_unique<SourceControlFile>();
auto core = std::make_unique<SourceParagraph>();
core->name = name;
core->version_scheme = scheme;
core->version = std::move(version);
scf->core_paragraph = std::move(core);
it = mappings.emplace(name, SourceControlFileAndLocation{std::move(scf), name}).first;
}
return it->second;
}
SourceControlFileAndLocation& emplace(const std::string& name) { return emplace(name, {"1", 0}); }
private:
std::map<std::string, SourceControlFileAndLocation, std::less<>> mappings;
};
static const MockOverlayProvider s_empty_mock_overlay;
#define WITH_EXPECTED(id, expr) \
auto id##_storage = (expr); \
REQUIRE(id##_storage.has_value()); \
auto& id = *id##_storage.get()
static ExpectedL<ActionPlan> create_versioned_install_plan(const IVersionedPortfileProvider& provider,
const IBaselineProvider& bprovider,
const CMakeVars::CMakeVarProvider& var_provider,
const std::vector<Dependency>& deps,
const std::vector<DependencyOverride>& overrides,
const PackageSpec& toplevel)
{
return create_versioned_install_plan(provider,
bprovider,
s_empty_mock_overlay,
var_provider,
deps,
overrides,
toplevel,
{Test::ARM_UWP, "pkgs", UnsupportedPortAction::Error});
}
static ExpectedL<ActionPlan> create_versioned_install_plan(const IVersionedPortfileProvider& provider,
const IBaselineProvider& bprovider,
const IOverlayProvider& oprovider,
const CMakeVars::CMakeVarProvider& var_provider,
const std::vector<Dependency>& deps,
const std::vector<DependencyOverride>& overrides,
const PackageSpec& toplevel)
{
return create_versioned_install_plan(provider,
bprovider,
oprovider,
var_provider,
deps,
overrides,
toplevel,
{Test::ARM_UWP, "pkgs", UnsupportedPortAction::Error});
}
TEST_CASE ("basic version install single", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"1", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"1", 0});
MockCMakeVarProvider var_provider;
WITH_EXPECTED(install_plan, create_versioned_install_plan(vp, bp, var_provider, {{"a"}}, {}, toplevel_spec()));
REQUIRE(install_plan.size() == 1);
REQUIRE(install_plan.install_actions.at(0).spec.name() == "a");
}
TEST_CASE ("basic version install detect cycle", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"1", 0};
bp.v["b"] = {"1", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"1", 0}).source_control_file->core_paragraph->dependencies = {
Dependency{"b", {}, {}, DependencyConstraint{}},
};
vp.emplace("b", {"1", 0}).source_control_file->core_paragraph->dependencies = {
Dependency{"a", {}, {}, DependencyConstraint{}},
};
MockCMakeVarProvider var_provider;
auto install_plan = create_versioned_install_plan(vp, bp, var_provider, {{"a"}}, {}, toplevel_spec());
REQUIRE(!install_plan.has_value());
REQUIRE(install_plan.error() == "error: cycle detected during a:x86-windows:\na:x86-windows@1\nb:x86-windows@1");
}
TEST_CASE ("basic version install scheme", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"1", 0};
bp.v["b"] = {"1", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"1", 0}).source_control_file->core_paragraph->dependencies = {
Dependency{"b", {}, {}, DependencyConstraint{}},
};
vp.emplace("b", {"1", 0});
MockCMakeVarProvider var_provider;
WITH_EXPECTED(install_plan, create_versioned_install_plan(vp, bp, var_provider, {{"a"}}, {}, toplevel_spec()));
REQUIRE(install_plan.size() == 2);
CHECK(install_plan.install_actions[0].spec.name() == "b");
CHECK(install_plan.install_actions[1].spec.name() == "a");
REQUIRE(install_plan.install_actions[1].package_dependencies.size() == 1);
CHECK(install_plan.install_actions[1].package_dependencies[0].name() == "b");
auto it = install_plan.install_actions[1].feature_dependencies.find("core");
REQUIRE(it != install_plan.install_actions[1].feature_dependencies.end());
REQUIRE(it->second.size() == 1);
REQUIRE(it->second[0].port() == "b");
}
TEST_CASE ("basic version install scheme diamond", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"1", 0};
bp.v["b"] = {"1", 0};
bp.v["c"] = {"1", 0};
bp.v["d"] = {"1", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"1", 0}).source_control_file->core_paragraph->dependencies = {
Dependency{"b", {}, {}, DependencyConstraint{}},
Dependency{"c", {}, {}, DependencyConstraint{}},
};
vp.emplace("b", {"1", 0}).source_control_file->core_paragraph->dependencies = {
Dependency{"c", {}, {}, DependencyConstraint{}},
Dependency{"d", {}, {}, DependencyConstraint{}},
};
vp.emplace("c", {"1", 0}).source_control_file->core_paragraph->dependencies = {
Dependency{"d", {}, {}, DependencyConstraint{}},
};
vp.emplace("d", {"1", 0});
MockCMakeVarProvider var_provider;
WITH_EXPECTED(install_plan, create_versioned_install_plan(vp, bp, var_provider, {{"a"}}, {}, toplevel_spec()));
REQUIRE(install_plan.size() == 4);
CHECK(install_plan.install_actions[0].spec.name() == "d");
CHECK(install_plan.install_actions[1].spec.name() == "c");
CHECK(install_plan.install_actions[2].spec.name() == "b");
CHECK(install_plan.install_actions[3].spec.name() == "a");
REQUIRE(install_plan.install_actions[1].package_dependencies.size() == 1);
CHECK(install_plan.install_actions[1].package_dependencies[0].name() == "d");
REQUIRE(install_plan.install_actions[2].package_dependencies.size() == 2);
CHECK(install_plan.install_actions[2].package_dependencies[0].name() == "c");
CHECK(install_plan.install_actions[2].package_dependencies[1].name() == "d");
REQUIRE(install_plan.install_actions[3].package_dependencies.size() == 2);
CHECK(install_plan.install_actions[3].package_dependencies[0].name() == "b");
CHECK(install_plan.install_actions[3].package_dependencies[1].name() == "c");
}
TEST_CASE ("basic version install scheme baseline missing", "[versionplan]")
{
MockBaselineProvider bp;
MockVersionedPortfileProvider vp;
vp.emplace("a", {"1", 0});
MockCMakeVarProvider var_provider;
auto install_plan = create_versioned_install_plan(vp, bp, var_provider, {{"a"}}, {}, toplevel_spec());
REQUIRE(!install_plan.has_value());
REQUIRE(install_plan.error() == "MockBaselineProvider::get_baseline_version(a)");
}
TEST_CASE ("basic version install scheme baseline missing 2", "[versionplan]")
{
MockBaselineProvider bp;
MockVersionedPortfileProvider vp;
vp.emplace("a", {"1", 0});
vp.emplace("a", {"2", 0});
vp.emplace("a", {"3", 0});
MockCMakeVarProvider var_provider;
auto install_plan =
create_versioned_install_plan(vp,
bp,
var_provider,
{
Dependency{"a", {}, {}, {VersionConstraintKind::Minimum, Version{"2", 0}}},
},
{},
toplevel_spec());
REQUIRE(!install_plan.has_value());
REQUIRE(install_plan.error() == "MockBaselineProvider::get_baseline_version(a)");
}
TEST_CASE ("basic version install scheme baseline", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"2", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"1", 0});
vp.emplace("a", {"2", 0});
vp.emplace("a", {"3", 0});
MockCMakeVarProvider var_provider;
auto install_plan = create_versioned_install_plan(vp, bp, var_provider, {{"a"}}, {}, toplevel_spec())
.value_or_exit(VCPKG_LINE_INFO);
REQUIRE(install_plan.size() == 1);
check_name_and_version(install_plan.install_actions[0], "a", {"2", 0});
}
TEST_CASE ("version string baseline agree", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"2", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"1", 0});
vp.emplace("a", {"2", 0});
vp.emplace("a", {"3", 0});
MockCMakeVarProvider var_provider;
auto install_plan =
create_versioned_install_plan(vp,
bp,
var_provider,
{Dependency{"a", {}, {}, {VersionConstraintKind::Minimum, Version{"2", 0}}}},
{},
toplevel_spec());
REQUIRE(install_plan.has_value());
}
TEST_CASE ("version install scheme baseline conflict", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"2", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"1", 0});
vp.emplace("a", {"2", 0});
vp.emplace("a", {"3", 0});
MockCMakeVarProvider var_provider;
auto install_plan =
create_versioned_install_plan(vp,
bp,
var_provider,
{
Dependency{"a", {}, {}, {VersionConstraintKind::Minimum, Version{"3", 0}}},
},
{},
toplevel_spec());
REQUIRE(!install_plan.has_value());
REQUIRE_LINES(
install_plan.error(),
R"(error: version conflict on a:x86-windows: toplevel-spec required 3, which cannot be compared with the baseline version 2.
Both versions have scheme string but different primary text.
This can be resolved by adding an explicit override to the preferred version. For example:
"overrides": [
{ "name": "a", "version": "2" }
]
See `vcpkg help versioning` or https://learn.microsoft.com/vcpkg/users/versioning for more information.)");
}
TEST_CASE ("version install string port version", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"2", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"2", 0});
vp.emplace("a", {"2", 1});
vp.emplace("a", {"2", 2});
MockCMakeVarProvider var_provider;
auto install_plan =
create_versioned_install_plan(vp,
bp,
var_provider,
{
Dependency{"a", {}, {}, {VersionConstraintKind::Minimum, Version{"2", 1}}},
},
{},
toplevel_spec())
.value_or_exit(VCPKG_LINE_INFO);
REQUIRE(install_plan.size() == 1);
check_name_and_version(install_plan.install_actions[0], "a", {"2", 1});
}
TEST_CASE ("version install string port version 2", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"2", 1};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"2", 0});
vp.emplace("a", {"2", 1});
vp.emplace("a", {"2", 2});
MockCMakeVarProvider var_provider;
auto install_plan =
create_versioned_install_plan(vp,
bp,
var_provider,
{
Dependency{"a", {}, {}, {VersionConstraintKind::Minimum, Version{"2", 0}}},
},
{},
toplevel_spec())
.value_or_exit(VCPKG_LINE_INFO);
REQUIRE(install_plan.size() == 1);
check_name_and_version(install_plan.install_actions[0], "a", {"2", 1});
CHECK(install_plan.install_actions[0].request_type == RequestType::USER_REQUESTED);
}
TEST_CASE ("version install transitive string", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"2", 0};
bp.v["b"] = {"2", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"2", 0}).source_control_file->core_paragraph->dependencies = {
Dependency{"b", {}, {}, DependencyConstraint{VersionConstraintKind::Minimum, Version{"1", 0}}},
};
vp.emplace("a", {"2", 1}).source_control_file->core_paragraph->dependencies = {
Dependency{"b", {}, {}, DependencyConstraint{VersionConstraintKind::Minimum, Version{"2", 0}}},
};
vp.emplace("b", {"1", 0});
vp.emplace("b", {"2", 0});
MockCMakeVarProvider var_provider;
auto install_plan1 =
create_versioned_install_plan(vp,
bp,
var_provider,
{
Dependency{"a", {}, {}, {VersionConstraintKind::Minimum, Version{"2", 1}}},
},
{},
toplevel_spec());
REQUIRE(install_plan1.has_value());
auto& install_plan = *install_plan1.get();
REQUIRE(install_plan.size() == 2);
check_name_and_version(install_plan.install_actions[0], "b", {"2", 0});
CHECK(install_plan.install_actions[0].request_type == RequestType::AUTO_SELECTED);
check_name_and_version(install_plan.install_actions[1], "a", {"2", 1});
CHECK(install_plan.install_actions[1].request_type == RequestType::USER_REQUESTED);
}
TEST_CASE ("version install simple relaxed", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"2", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"2", 0}, VersionScheme::Relaxed);
vp.emplace("a", {"3", 0}, VersionScheme::Relaxed);
MockCMakeVarProvider var_provider;
auto install_plan =
create_versioned_install_plan(vp,
bp,
var_provider,
{
Dependency{"a", {}, {}, {VersionConstraintKind::Minimum, Version{"3", 0}}},
},
{},
toplevel_spec())
.value_or_exit(VCPKG_LINE_INFO);
REQUIRE(install_plan.size() == 1);
check_name_and_version(install_plan.install_actions[0], "a", {"3", 0});
}
TEST_CASE ("version install transitive relaxed", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"2", 0};
bp.v["b"] = {"2", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"2", 0}, VersionScheme::Relaxed);
vp.emplace("a", {"3", 0}, VersionScheme::Relaxed).source_control_file->core_paragraph->dependencies = {
Dependency{"b", {}, {}, DependencyConstraint{VersionConstraintKind::Minimum, Version{"3", 0}}},
};
vp.emplace("b", {"2", 0}, VersionScheme::Relaxed);
vp.emplace("b", {"3", 0}, VersionScheme::Relaxed);
MockCMakeVarProvider var_provider;
auto install_plan =
create_versioned_install_plan(vp,
bp,
var_provider,
{
Dependency{"a", {}, {}, {VersionConstraintKind::Minimum, Version{"3", 0}}},
},
{},
toplevel_spec())
.value_or_exit(VCPKG_LINE_INFO);
REQUIRE(install_plan.size() == 2);
check_name_and_version(install_plan.install_actions[0], "b", {"3", 0});
check_name_and_version(install_plan.install_actions[1], "a", {"3", 0});
}
TEST_CASE ("version install diamond relaxed", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"2", 0};
bp.v["b"] = {"3", 0};
bp.v["c"] = {"5", 1};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"2", 0}, VersionScheme::Relaxed);
vp.emplace("a", {"3", 0}, VersionScheme::Relaxed).source_control_file->core_paragraph->dependencies = {
Dependency{"b", {}, {}, DependencyConstraint{VersionConstraintKind::Minimum, Version{"2", 1}}},
Dependency{"c", {}, {}, DependencyConstraint{VersionConstraintKind::Minimum, Version{"5", 1}}},
};
vp.emplace("b", {"2", 1}, VersionScheme::Relaxed);
vp.emplace("b", {"3", 0}, VersionScheme::Relaxed).source_control_file->core_paragraph->dependencies = {
Dependency{"c", {}, {}, DependencyConstraint{VersionConstraintKind::Minimum, Version{"9", 2}}},
};
vp.emplace("c", {"5", 1}, VersionScheme::Relaxed);
vp.emplace("c", {"9", 2}, VersionScheme::Relaxed);
MockCMakeVarProvider var_provider;
WITH_EXPECTED(
install_plan,
create_versioned_install_plan(vp,
bp,
var_provider,
{
Dependency{"a", {}, {}, {VersionConstraintKind::Minimum, Version{"3", 0}}},
Dependency{"b", {}, {}, {VersionConstraintKind::Minimum, Version{"2", 1}}},
},
{},
toplevel_spec()));
REQUIRE(install_plan.size() == 3);
check_name_and_version(install_plan.install_actions[0], "c", {"9", 2});
check_name_and_version(install_plan.install_actions[1], "b", {"3", 0});
check_name_and_version(install_plan.install_actions[2], "a", {"3", 0});
}
TEST_CASE ("version parse semver", "[versionplan]")
{
check_semver_version(DotVersion::try_parse_semver("1.2.3"), "1.2.3", "", 1, 2, 3, {});
check_semver_version(DotVersion::try_parse_semver("1.0.0-alpha"), "1.0.0", "alpha", 1, 0, 0, {"alpha"});
check_semver_version(DotVersion::try_parse_semver("1.0.0-0alpha0"), "1.0.0", "0alpha0", 1, 0, 0, {"0alpha0"});
check_semver_version(
DotVersion::try_parse_semver("1.0.0-alpha.1.0.0"), "1.0.0", "alpha.1.0.0", 1, 0, 0, {"alpha", "1", "0", "0"});
check_semver_version(DotVersion::try_parse_semver("1.0.0-alpha.1.x.y.z.0-alpha.0-beta.l-a-s-t"),
"1.0.0",
"alpha.1.x.y.z.0-alpha.0-beta.l-a-s-t",
1,
0,
0,
{"alpha", "1", "x", "y", "z", "0-alpha", "0-beta", "l-a-s-t"});
check_semver_version(DotVersion::try_parse_semver("1.0.0----------------------------------"),
"1.0.0",
"---------------------------------",
1,
0,
0,
{"---------------------------------"});
check_semver_version(DotVersion::try_parse_semver("1.0.0+build"), "1.0.0", "", 1, 0, 0, {});
check_semver_version(DotVersion::try_parse_semver("1.0.0-alpha+build"), "1.0.0", "alpha", 1, 0, 0, {"alpha"});
check_semver_version(DotVersion::try_parse_semver("1.0.0-alpha+build.ok"), "1.0.0", "alpha", 1, 0, 0, {"alpha"});
check_semver_version(
DotVersion::try_parse_semver("1.0.0-alpha+build.ok-too"), "1.0.0", "alpha", 1, 0, 0, {"alpha"});
CHECK(!DotVersion::try_parse_semver("1.0").has_value());
CHECK(!DotVersion::try_parse_semver("1.0-alpha").has_value());
CHECK(!DotVersion::try_parse_semver("1.0.0.0").has_value());
CHECK(!DotVersion::try_parse_semver("1.02.03").has_value());
CHECK(!DotVersion::try_parse_semver("1.0.0-").has_value());
CHECK(!DotVersion::try_parse_semver("1.0.0-01").has_value());
CHECK(!DotVersion::try_parse_semver("1.0.0-alpha#2").has_value());
CHECK(!DotVersion::try_parse_semver("1.0.0-alpha+build+notok").has_value());
}
TEST_CASE ("version parse relaxed", "[versionplan]")
{
check_relaxed_version(DotVersion::try_parse_relaxed("1.2.3"), {1, 2, 3});
check_relaxed_version(DotVersion::try_parse_relaxed("1"), {1});
check_relaxed_version(
DotVersion::try_parse_relaxed("1.20.300.4000.50000.6000000.70000000.80000000.18446744073709551610"),
{1, 20, 300, 4000, 50000, 6000000, 70000000, 80000000, 18446744073709551610u});
check_relaxed_version(DotVersion::try_parse_relaxed("1.0.0.0-alpha"), {1, 0, 0, 0}, {"alpha"});
check_relaxed_version(DotVersion::try_parse_relaxed("1.0.0.0-alpha-0.1"), {1, 0, 0, 0}, {"alpha-0", "1"});
check_relaxed_version(DotVersion::try_parse_relaxed("1.0.0.0-alpha+build-ok"), {1, 0, 0, 0}, {"alpha"});
CHECK(!DotVersion::try_parse_relaxed("1.1a.2").has_value());
CHECK(!DotVersion::try_parse_relaxed("01.002.003").has_value());
CHECK(!DotVersion::try_parse_relaxed("1.0.0-").has_value());
CHECK(!DotVersion::try_parse_relaxed("1.0.0+extra+other").has_value());
}
TEST_CASE ("version parse date", "[versionplan]")
{
check_date_version(DateVersion::try_parse("2020-12-25"), "2020-12-25", {});
check_date_version(DateVersion::try_parse("2020-12-25.1.2.3"), "2020-12-25", {1, 2, 3});
CHECK(!DateVersion::try_parse("2020-1-1").has_value());
CHECK(!DateVersion::try_parse("2020-01-01.alpha").has_value());
CHECK(!DateVersion::try_parse("2020-01-01.2a").has_value());
CHECK(!DateVersion::try_parse("2020-01-01.01").has_value());
}
TEST_CASE ("version sort semver", "[versionplan]")
{
std::vector<DotVersion> versions{
DotVersion::try_parse_semver("1.0.0").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("0.0.0").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("1.1.0").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("2.0.0").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("1.1.1").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("1.0.1").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("1.0.0-alpha.1").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("1.0.0-beta").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("1.0.0-alpha").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("1.0.0-alpha.beta").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("1.0.0-rc").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("1.0.0-beta.2").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("1.0.0-beta.20").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("1.0.0-beta.3").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("1.0.0-1").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_semver("1.0.0-0alpha").value_or_exit(VCPKG_LINE_INFO),
};
std::sort(std::begin(versions), std::end(versions));
CHECK(versions[0].original_string == "0.0.0");
CHECK(versions[1].original_string == "1.0.0-1");
CHECK(versions[2].original_string == "1.0.0-0alpha");
CHECK(versions[3].original_string == "1.0.0-alpha");
CHECK(versions[4].original_string == "1.0.0-alpha.1");
CHECK(versions[5].original_string == "1.0.0-alpha.beta");
CHECK(versions[6].original_string == "1.0.0-beta");
CHECK(versions[7].original_string == "1.0.0-beta.2");
CHECK(versions[8].original_string == "1.0.0-beta.3");
CHECK(versions[9].original_string == "1.0.0-beta.20");
CHECK(versions[10].original_string == "1.0.0-rc");
CHECK(versions[11].original_string == "1.0.0");
CHECK(versions[12].original_string == "1.0.1");
CHECK(versions[13].original_string == "1.1.0");
CHECK(versions[14].original_string == "1.1.1");
CHECK(versions[15].original_string == "2.0.0");
}
TEST_CASE ("version sort relaxed", "[versionplan]")
{
std::vector<DotVersion> versions{
DotVersion::try_parse_relaxed("2.1-alpha.alpha").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("1.0.0").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("2.0-1").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("1.0").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("1").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("2.1-alpha").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("2").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("1.1").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("1.10.1").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("2.0-0").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("1.0.1").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("2.1-beta").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("1.0.0.1").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("1.0.0.2").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("2.0").value_or_exit(VCPKG_LINE_INFO),
DotVersion::try_parse_relaxed("2.0-rc").value_or_exit(VCPKG_LINE_INFO),
};
std::sort(std::begin(versions), std::end(versions));
CHECK(versions[0].original_string == "1");
CHECK(versions[1].original_string == "1.0");
CHECK(versions[2].original_string == "1.0.0");
CHECK(versions[3].original_string == "1.0.0.1");
CHECK(versions[4].original_string == "1.0.0.2");
CHECK(versions[5].original_string == "1.0.1");
CHECK(versions[6].original_string == "1.1");
CHECK(versions[7].original_string == "1.10.1");
CHECK(versions[8].original_string == "2");
CHECK(versions[9].original_string == "2.0-0");
CHECK(versions[10].original_string == "2.0-1");
CHECK(versions[11].original_string == "2.0-rc");
CHECK(versions[12].original_string == "2.0");
CHECK(versions[13].original_string == "2.1-alpha");
CHECK(versions[14].original_string == "2.1-alpha.alpha");
CHECK(versions[15].original_string == "2.1-beta");
}
TEST_CASE ("version sort date", "[versionplan]")
{
std::vector<DateVersion> versions{
DateVersion::try_parse("2021-01-01.2").value_or_exit(VCPKG_LINE_INFO),
DateVersion::try_parse("2021-01-01.1").value_or_exit(VCPKG_LINE_INFO),
DateVersion::try_parse("2021-01-01.1.1").value_or_exit(VCPKG_LINE_INFO),
DateVersion::try_parse("2021-01-01.1.0").value_or_exit(VCPKG_LINE_INFO),
DateVersion::try_parse("2021-01-01").value_or_exit(VCPKG_LINE_INFO),
DateVersion::try_parse("2021-01-01").value_or_exit(VCPKG_LINE_INFO),
DateVersion::try_parse("2020-12-25").value_or_exit(VCPKG_LINE_INFO),
DateVersion::try_parse("2020-12-31").value_or_exit(VCPKG_LINE_INFO),
DateVersion::try_parse("2021-01-01.10").value_or_exit(VCPKG_LINE_INFO),
};
std::sort(std::begin(versions), std::end(versions));
CHECK(versions[0].original_string == "2020-12-25");
CHECK(versions[1].original_string == "2020-12-31");
CHECK(versions[2].original_string == "2021-01-01");
CHECK(versions[3].original_string == "2021-01-01");
CHECK(versions[4].original_string == "2021-01-01.1");
CHECK(versions[5].original_string == "2021-01-01.1.0");
CHECK(versions[6].original_string == "2021-01-01.1.1");
CHECK(versions[7].original_string == "2021-01-01.2");
CHECK(versions[8].original_string == "2021-01-01.10");
}
TEST_CASE ("version compare string", "[versionplan]")
{
const Version a_0("a", 0);
const Version a_1("a", 1);
const Version b_1("b", 1);
CHECK(VerComp::lt == compare_versions(VersionScheme::String, a_0, VersionScheme::String, a_1));
CHECK(VerComp::eq == compare_versions(VersionScheme::String, a_0, VersionScheme::String, a_0));
CHECK(VerComp::gt == compare_versions(VersionScheme::String, a_1, VersionScheme::String, a_0));
CHECK(VerComp::unk == compare_versions(VersionScheme::String, a_1, VersionScheme::String, b_1));
}
TEST_CASE ("version compare_any", "[versionplan]")
{
const Version a_0("a", 0);
const Version a_1("a", 1);
const Version b_1("b", 1);
CHECK(VerComp::lt == compare_any(a_0, a_1));
CHECK(VerComp::gt == compare_any(a_1, a_0));
CHECK(VerComp::eq == compare_any(a_0, a_0));
CHECK(VerComp::unk == compare_any(a_1, b_1));
const Version v_0_0("0", 0);
const Version v_1_0("1", 0);
const Version v_1_1_1("1.1", 1);
CHECK(VerComp::lt == compare_any(v_0_0, v_1_0));
CHECK(VerComp::gt == compare_any(v_1_1_1, v_1_0));
CHECK(VerComp::eq == compare_any(v_0_0, v_0_0));
const Version date_0("2021-04-05", 0);
const Version date_1("2022-02-01", 0);
CHECK(VerComp::eq == compare_any(date_0, date_0));
CHECK(VerComp::lt == compare_any(date_0, date_1));
CHECK(VerComp::unk == compare_any(date_0, a_0));
// Note: dates are valid relaxed dotversions, so these are valid comparisons
CHECK(VerComp::gt == compare_any(date_0, v_0_0));
CHECK(VerComp::gt == compare_any(date_0, v_1_1_1));
}
TEST_CASE ("version install simple semver", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"2.0.0", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"2.0.0", 0}, VersionScheme::Semver);
vp.emplace("a", {"3.0.0", 0}, VersionScheme::Semver);
MockCMakeVarProvider var_provider;
auto install_plan = create_versioned_install_plan(
vp,
bp,
var_provider,
{
Dependency{"a", {}, {}, {VersionConstraintKind::Minimum, Version{"3.0.0", 0}}},
},
{},
toplevel_spec())
.value_or_exit(VCPKG_LINE_INFO);
REQUIRE(install_plan.size() == 1);
check_name_and_version(install_plan.install_actions[0], "a", {"3.0.0", 0});
}
TEST_CASE ("version install transitive semver", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"2.0.0", 0};
bp.v["b"] = {"2.0.0", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"2.0.0", 0}, VersionScheme::Semver);
vp.emplace("a", {"3.0.0", 0}, VersionScheme::Semver).source_control_file->core_paragraph->dependencies = {
Dependency{"b", {}, {}, DependencyConstraint{VersionConstraintKind::Minimum, Version{"3.0.0", 0}}},
};
vp.emplace("b", {"2.0.0", 0}, VersionScheme::Semver);
vp.emplace("b", {"3.0.0", 0}, VersionScheme::Semver);
MockCMakeVarProvider var_provider;
auto install_plan = create_versioned_install_plan(
vp,
bp,
var_provider,
{
Dependency{"a", {}, {}, {VersionConstraintKind::Minimum, Version{"3.0.0", 0}}},
},
{},
toplevel_spec())
.value_or_exit(VCPKG_LINE_INFO);
REQUIRE(install_plan.size() == 2);
check_name_and_version(install_plan.install_actions[0], "b", {"3.0.0", 0});
check_name_and_version(install_plan.install_actions[1], "a", {"3.0.0", 0});
}
TEST_CASE ("version install diamond semver", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"2.0.0", 0};
bp.v["b"] = {"3.0.0", 0};
bp.v["c"] = {"5.0.0", 1};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"2.0.0", 0}, VersionScheme::Semver);
vp.emplace("a", {"3.0.0", 0}, VersionScheme::Semver).source_control_file->core_paragraph->dependencies = {
Dependency{"b", {}, {}, DependencyConstraint{VersionConstraintKind::Minimum, Version{"2.0.0", 1}}},
Dependency{"c", {}, {}, DependencyConstraint{VersionConstraintKind::Minimum, Version{"5.0.0", 1}}},
};
vp.emplace("b", {"2.0.0", 1}, VersionScheme::Semver);
vp.emplace("b", {"3.0.0", 0}, VersionScheme::Semver).source_control_file->core_paragraph->dependencies = {
Dependency{"c", {}, {}, DependencyConstraint{VersionConstraintKind::Minimum, Version{"9.0.0", 2}}},
};
vp.emplace("c", {"5.0.0", 1}, VersionScheme::Semver);
vp.emplace("c", {"9.0.0", 2}, VersionScheme::Semver);
MockCMakeVarProvider var_provider;
WITH_EXPECTED(install_plan,
create_versioned_install_plan(
vp,
bp,
var_provider,
{
Dependency{"a", {}, {}, {VersionConstraintKind::Minimum, Version{"3.0.0", 0}}},
Dependency{"b", {}, {}, {VersionConstraintKind::Minimum, Version{"2.0.0", 1}}},
},
{},
toplevel_spec()));
REQUIRE(install_plan.size() == 3);
check_name_and_version(install_plan.install_actions[0], "c", {"9.0.0", 2});
check_name_and_version(install_plan.install_actions[1], "b", {"3.0.0", 0});
check_name_and_version(install_plan.install_actions[2], "a", {"3.0.0", 0});
}
TEST_CASE ("version install simple date", "[versionplan]")
{
MockBaselineProvider bp;
bp.v["a"] = {"2020-02-01", 0};
MockVersionedPortfileProvider vp;
vp.emplace("a", {"2020-02-01", 0}, VersionScheme::Date);
vp.emplace("a", {"2020-03-01", 0}, VersionScheme::Date);
MockCMakeVarProvider var_provider;
WITH_EXPECTED(install_plan,
create_versioned_install_plan(
vp,
bp,
var_provider,
{
Dependency{"a", {}, {}, {VersionConstraintKind::Minimum, Version{"2020-03-01", 0}}},
},
{},
toplevel_spec()));