-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathjson.rs
1364 lines (1237 loc) · 58.4 KB
/
json.rs
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
// Copyright (c) The cargo-guppy Contributors
// SPDX-License-Identifier: MIT OR Apache-2.0
use crate::{
details::{FixtureDetails, LinkDetails, PackageDetails, PlatformResults},
package_id,
};
use ahash::AHashMap;
use camino::{Utf8Component, Utf8Path, Utf8PathBuf};
use guppy::{
CargoMetadata, DependencyKind,
errors::{FeatureBuildStage, FeatureGraphWarning},
graph::{BuildTargetId, BuildTargetKind, PackageGraph},
platform::{EnabledTernary, Platform, TargetFeatures},
};
use once_cell::sync::{Lazy, OnceCell};
use std::{collections::BTreeMap, fs};
// Metadata along with interesting crate names.
pub static METADATA1_PATH: &str = "../small/metadata1.json";
pub static METADATA1_TESTCRATE: &str = "testcrate 0.1.0 (path+file:///fakepath/testcrate)";
pub static METADATA1_DATATEST: &str =
"datatest 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA1_REGION: &str =
"region 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA1_DTOA: &str =
"dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA2_PATH: &str = "../small/metadata2.json";
pub static METADATA2_TESTCRATE: &str =
"testworkspace-crate 0.1.0 (path+file:///Users/fakeuser/local/testworkspace/testcrate)";
pub static METADATA2_WALKDIR: &str =
"walkdir 2.2.9 (path+file:///Users/fakeuser/local/testworkspace/walkdir)";
pub static METADATA2_QUOTE: &str = "quote 1.0.2 (path+file:///Users/fakeuser/local/quote)";
pub static METADATA_BUILDDEP_PATH: &str = "../small/builddep.json";
pub static METADATA_DUPS_PATH: &str = "../small/metadata_dups.json";
pub static METADATA_DUPS_TESTCRATE: &str =
"testcrate-dups 0.1.0 (path+file:///Users/fakeuser/local/testcrates/testcrate-dups)";
pub static METADATA_DUPS_LAZY_STATIC_1: &str =
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_DUPS_LAZY_STATIC_02: &str =
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_DUPS_BYTES_03: &str =
"bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_DUPS_BYTES_05: &str =
"bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_CYCLE1_PATH: &str = "../small/metadata_cycle1.json";
pub static METADATA_CYCLE1_BASE: &str = "testcycles-base 0.1.0 (path+file:///Users/fakeuser/local/testcrates/testcycles/testcycles-base)";
pub static METADATA_CYCLE1_HELPER: &str = "testcycles-helper 0.1.0 (path+file:///Users/fakeuser/local/testcrates/testcycles/testcycles-helper)";
pub static METADATA_CYCLE2_PATH: &str = "../small/metadata_cycle2.json";
pub static METADATA_CYCLE2_UPPER_A: &str =
"upper-a 0.1.0 (path+file:///Users/fakeuser/local/testcrates/cycle2/upper-a)";
pub static METADATA_CYCLE2_UPPER_B: &str =
"upper-b 0.1.0 (path+file:///Users/fakeuser/local/testcrates/cycle2/upper-b)";
pub static METADATA_CYCLE2_LOWER_A: &str =
"lower-a 0.1.0 (path+file:///Users/fakeuser/local/testcrates/cycle2/lower-a)";
pub static METADATA_CYCLE2_LOWER_B: &str =
"lower-b 0.1.0 (path+file:///Users/fakeuser/local/testcrates/cycle2/lower-b)";
pub static METADATA_CYCLE_FEATURES_PATH: &str = "../small/metadata_cycle_features.json";
pub static METADATA_CYCLE_FEATURES_BASE: &str =
"testcycles-base 0.1.0 (path+file:///fakepath/testcycles-features/testcycles-base)";
pub static METADATA_CYCLE_FEATURES_HELPER: &str =
"testcycles-helper 0.1.0 (path+file:///fakepath/testcycles-features/testcycles-helper)";
pub static METADATA_TARGETS1_PATH: &str = "../small/metadata_targets1.json";
pub static METADATA_TARGETS1_TESTCRATE: &str =
"testcrate-targets 0.1.0 (path+file:///Users/fakeuser/local/testcrates/testcrate-targets)";
pub static METADATA_TARGETS1_LAZY_STATIC_1: &str =
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_TARGETS1_LAZY_STATIC_02: &str =
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_TARGETS1_LAZY_STATIC_01: &str =
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_TARGETS1_BYTES: &str =
"bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_TARGETS1_DEP_A: &str =
"dep-a 0.1.0 (path+file:///Users/fakeuser/local/testcrates/dep-a)";
pub static METADATA_BUILD_TARGETS1_PATH: &str = "../small/metadata_build_targets1.json";
pub static METADATA_BUILD_TARGETS1_TESTCRATE: &str =
"testcrate 0.1.0 (path+file:///Users/fakeuser/local/testcrates/test-build-targets)";
pub static METADATA_PROC_MACRO1_PATH: &str = "../small/metadata_proc_macro1.json";
pub static METADATA_PROC_MACRO1_MACRO: &str =
"macro 0.1.0 (path+file:///Users/fakeuser/local/testcrates/proc-macro/macro)";
pub static METADATA_PROC_MACRO1_NORMAL_USER: &str =
"normal-user 0.1.0 (path+file:///Users/fakeuser/local/testcrates/proc-macro/normal-user)";
pub static METADATA_PROC_MACRO1_BUILD_USER: &str =
"build-user 0.1.0 (path+file:///Users/fakeuser/local/testcrates/proc-macro/build-user)";
pub static METADATA_PROC_MACRO1_DEV_USER: &str =
"dev-user 0.1.0 (path+file:///Users/fakeuser/local/testcrates/proc-macro/dev-user)";
pub static METADATA_ALTERNATE_REGISTRIES_PATH: &str = "../small/alternate-registries.json";
pub static METADATA_ALTERNATE_REGISTRY_URL: &str = "https://github.com/fakeorg/crates.io-index";
pub static METADATA_WEAK_NAMESPACED_FEATURES_PATH: &str = "../small/weak-namespaced-features.json";
pub static METADATA_WEAK_NAMESPACED_ID: &str =
"namespaced-weak 0.1.0 (path+file:///home/fakeuser/dev/tmp/test-workspaces/namespaced-weak)";
pub static METADATA_WEAK_NAMESPACED_SMALLVEC: &str =
"smallvec 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_WEAK_NAMESPACED_ARRAYVEC: &str =
"arrayvec 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_WEAK_NAMESPACED_TINYVEC: &str =
"tinyvec 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_LIBRA_PATH: &str = "../large/metadata_libra.json";
pub static METADATA_LIBRA_ADMISSION_CONTROL_SERVICE: &str = "admission-control-service 0.1.0 (path+file:///Users/fakeuser/local/libra/admission_control/admission-control-service)";
pub static METADATA_LIBRA_COMPILER: &str =
"compiler 0.1.0 (path+file:///Users/fakeuser/local/libra/language/compiler)";
pub static METADATA_LIBRA_E2E_TESTS: &str =
"language-e2e-tests 0.1.0 (path+file:///Users/fakeuser/local/libra/language/e2e-tests)";
pub static METADATA_LIBRA_EXECUTOR: &str =
"executor 0.1.0 (path+file:///Users/fakeuser/local/libra/execution/executor)";
pub static METADATA_LIBRA_EXECUTOR_UTILS: &str =
"executor-utils 0.1.0 (path+file:///Users/fakeuser/local/libra/execution/executor-utils)";
pub static METADATA_LIBRA_COST_SYNTHESIS: &str =
"cost-synthesis 0.1.0 (path+file:///Users/fakeuser/local/libra/language/tools/cost-synthesis)";
pub static METADATA_LIBRA_FUNCTIONAL_TESTS: &str =
"functional_tests 0.1.0 (path+file:///Users/fakeuser/local/libra/language/functional_tests)";
pub static METADATA_LIBRA_FUNCTIONAL_HYPHEN_TESTS: &str =
"functional-tests 0.1.0 (path+file:///Users/fakeuser/local/libra/language/functional-tests)";
pub static METADATA_LIBRA_LIBRA_VM: &str =
"libra-vm 0.1.0 (path+file:///Users/fakeuser/local/libra/language/libra-vm)";
pub static METADATA_LIBRA_MOVE_LANG: &str =
"move-lang 0.0.1 (path+file:///Users/fakeuser/local/libra/language/move-lang)";
pub static METADATA_LIBRA_MOVE_LANG_STDLIB: &str =
"move-lang-stdlib 0.1.0 (path+file:///Users/fakeuser/local/libra/language/move-lang/stdlib)";
pub static METADATA_LIBRA_MOVE_VM_RUNTIME: &str =
"move-vm-runtime 0.1.0 (path+file:///Users/fakeuser/local/libra/language/move-vm/runtime)";
pub static METADATA_LIBRA_STDLIB: &str =
"stdlib 0.1.0 (path+file:///Users/fakeuser/local/libra/language/stdlib)";
pub static METADATA_LIBRA_TEST_GENERATION: &str = "test-generation 0.1.0 (path+file:///Users/fakeuser/local/libra/language/tools/test-generation)";
pub static METADATA_LIBRA_TRANSACTION_BUILDER: &str = "transaction-builder 0.1.0 (path+file:///Users/fakeuser/local/libra/language/transaction-builder)";
pub static METADATA_LIBRA_VM_GENESIS: &str =
"vm-genesis 0.1.0 (path+file:///Users/fakeuser/local/libra/language/tools/vm-genesis)";
pub static METADATA_LIBRA_LANGUAGE_BENCHMARKS: &str =
"language_benchmarks 0.1.0 (path+file:///Users/fakeuser/local/libra/language/benchmarks)";
pub static METADATA_LIBRA_TREE_HEAP: &str = "tree_heap 0.1.0 (path+file:///Users/fakeuser/local/libra/language/stackless-bytecode/tree_heap)";
pub static METADATA_LIBRA_LAZY_STATIC: &str =
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_LIBRA_BACKTRACE: &str =
"backtrace 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_LIBRA_CFG_IF: &str =
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)";
pub static METADATA_LIBRA_F0091A4_PATH: &str = "../large/metadata_libra_f0091a4.json";
pub static METADATA_LIBRA_9FFD93B_PATH: &str = "../large/metadata_libra_9ffd93b.json";
pub static MNEMOS_B3B4DA9_PATH: &str = "../large/mnemos_b3b4da9.json";
pub static HYPER_UTIL_7AFB1ED_PATH: &str = "../large/hyper_util_7afb1ed.json";
pub static METADATA_GUPPY_78CB7E8_PATH: &str = "../guppy/metadata_guppy_78cb7e8.json";
pub static METADATA_GUPPY_869476C_PATH: &str = "../guppy/metadata_guppy_869476c.json";
pub static METADATA_GUPPY_C9B4F76_PATH: &str = "../guppy/metadata_guppy_c9b4f76.json";
pub static METADATA_GUPPY_44B62FA_PATH: &str = "../guppy/metadata_guppy_44b62fa.json";
pub static METADATA_GUPPY_CARGO_GUPPY: &str =
"cargo-guppy 0.1.0 (path+file:///home/fakeuser/dev/cargo-guppy/cargo-guppy)";
pub static FAKE_AUTHOR: &str = "Fake Author <[email protected]>";
macro_rules! define_fixtures {
($($name: ident => $json_path: ident,)*) => {
impl JsonFixture {
// Access all fixtures.
pub fn all_fixtures() -> &'static BTreeMap<&'static str, JsonFixture> {
// Provide a list of all fixtures.
static ALL_FIXTURES: Lazy<BTreeMap<&'static str, JsonFixture>> = Lazy::new(|| {
let mut map = BTreeMap::new();
$(map.insert(
stringify!($name),
JsonFixture::new(stringify!($name), $json_path, FixtureDetails::$name()),
);)*
map
});
&*ALL_FIXTURES
}
// Access individual fixtures if the name is known.
$(pub fn $name() -> &'static Self {
&JsonFixture::all_fixtures()[stringify!($name)]
})*
}
};
}
define_fixtures! {
metadata1 => METADATA1_PATH,
metadata2 => METADATA2_PATH,
metadata_builddep => METADATA_BUILDDEP_PATH,
metadata_dups => METADATA_DUPS_PATH,
metadata_cycle1 => METADATA_CYCLE1_PATH,
metadata_cycle2 => METADATA_CYCLE2_PATH,
metadata_cycle_features => METADATA_CYCLE_FEATURES_PATH,
metadata_targets1 => METADATA_TARGETS1_PATH,
metadata_build_targets1 => METADATA_BUILD_TARGETS1_PATH,
metadata_proc_macro1 => METADATA_PROC_MACRO1_PATH,
metadata_alternate_registries => METADATA_ALTERNATE_REGISTRIES_PATH,
metadata_weak_namespaced_features => METADATA_WEAK_NAMESPACED_FEATURES_PATH,
metadata_libra => METADATA_LIBRA_PATH,
metadata_libra_f0091a4 => METADATA_LIBRA_F0091A4_PATH,
metadata_libra_9ffd93b => METADATA_LIBRA_9FFD93B_PATH,
mnemos_b3b4da9 => MNEMOS_B3B4DA9_PATH,
hyper_util_7afb1ed => HYPER_UTIL_7AFB1ED_PATH,
metadata_guppy_78cb7e8 => METADATA_GUPPY_78CB7E8_PATH,
metadata_guppy_869476c => METADATA_GUPPY_869476C_PATH,
metadata_guppy_c9b4f76 => METADATA_GUPPY_C9B4F76_PATH,
metadata_guppy_44b62fa => METADATA_GUPPY_44B62FA_PATH,
}
pub struct JsonFixture {
name: &'static str,
workspace_path: Utf8PathBuf,
abs_path: Utf8PathBuf,
json_graph: OnceCell<(String, PackageGraph)>,
details: FixtureDetails,
}
impl JsonFixture {
fn new(name: &'static str, rel_path: &'static str, details: FixtureDetails) -> Self {
let rel_path = Utf8Path::new(rel_path);
let fixtures_dir = Utf8Path::new(env!("CARGO_MANIFEST_DIR"));
// rel_path is relative to this dir.
let mut abs_path = fixtures_dir.join("src");
abs_path.push(rel_path);
let abs_path = Utf8PathBuf::from_path_buf(
abs_path
.canonicalize()
.expect("fixture path canonicalization succeeded"),
)
.expect("valid UTF-8 path");
let workspace_root = fixtures_dir.parent().expect("up to workspace root");
let workspace_path = Utf8PathBuf::from_path_buf(
pathdiff::diff_paths(&abs_path, workspace_root)
.expect("both abs_path and workspace root are absolute"),
)
.expect("diff of UTF-8 paths is UTF-8");
// No symlinks in this repo, so normalize this path.
let workspace_path = normalize_assuming_no_symlinks(workspace_path);
Self {
name,
workspace_path,
abs_path,
json_graph: OnceCell::new(),
details,
}
}
/// Lookup a fixture by name, or `None` if the name wasn't found.
pub fn by_name(name: &str) -> Option<&'static Self> {
Self::all_fixtures().get(name)
}
/// Returns the name of this fixture.
pub fn name(&self) -> &'static str {
self.name
}
/// Returns the absolute path of this fixture.
pub fn abs_path(&self) -> &Utf8Path {
&self.abs_path
}
/// Returns the path of this fixture, relative to the workspace root.
pub fn workspace_path(&self) -> &Utf8Path {
&self.workspace_path
}
/// Returns the unparsed JSON string for this fixture.
pub fn json(&self) -> &str {
self.init_graph().0
}
/// Returns the package graph for this fixture.
pub fn graph(&self) -> &PackageGraph {
self.init_graph().1
}
/// Returns the test details for this fixture.
pub fn details(&self) -> &FixtureDetails {
&self.details
}
/// Verifies that the parsed metadata matches known details.
pub fn verify(&self) {
let graph = self.graph();
graph.verify().expect("graph verification should succeed");
// Check that all external sources parse correctly in all graphs.
for package in graph.packages() {
let source = package.source();
if source.is_external() {
let external = source
.parse_external()
.unwrap_or_else(|| panic!("cannot parse external source {}", source));
assert_eq!(
format!("{}", external),
source.external_source().expect("is_external is true"),
"roundtrip with ExternalSource"
);
}
}
self.details.assert_cycles(graph, "cycles");
self.details.assert_workspace(graph.workspace());
self.details.assert_topo(graph);
for id in self.details.known_ids() {
let msg = format!("error while verifying package '{}'", id);
let metadata = graph.metadata(id).expect(&msg);
self.details.assert_metadata(id, metadata, &msg);
// Check for build targets.
if self.details.has_build_targets(id) {
self.details.assert_build_targets(metadata, &msg);
}
// Check for direct dependency queries.
if self.details.has_deps(id) {
self.details.assert_deps(graph, id, &msg);
}
if self.details.has_reverse_deps(id) {
self.details.assert_reverse_deps(graph, id, &msg);
}
// Check for transitive dependency queries. Use both ID based and edge-based queries.
if self.details.has_transitive_deps(id) {
self.details.assert_transitive_deps(
graph,
id,
&format!("{} (transitive deps)", msg),
);
}
if self.details.has_transitive_reverse_deps(id) {
self.details.assert_transitive_reverse_deps(
graph,
id,
&format!("{} (transitive reverse deps)", msg),
);
}
// Check for named features.
if self.details.has_named_features(id) {
self.details
.assert_named_features(graph, id, &format!("{} (named features)", msg));
}
}
self.details.assert_link_details(graph, "link details");
// Tests for the feature graph.
self.details
.assert_feature_graph_warnings(graph, "feature graph warnings");
}
fn init_graph(&self) -> (&str, &PackageGraph) {
let (json, package_graph) = self.json_graph.get_or_init(|| {
let json = fs::read_to_string(&self.abs_path)
.unwrap_or_else(|err| panic!("reading file '{}' failed: {}", self.abs_path, err));
let graph = Self::parse_graph(&json);
(json, graph)
});
(json.as_str(), package_graph)
}
fn parse_graph(json: &str) -> PackageGraph {
let metadata =
CargoMetadata::parse_json(json).expect("parsing metadata JSON should succeed");
PackageGraph::from_metadata(metadata).expect("constructing package graph should succeed")
}
}
// Thanks to @porglezomp on Twitter for this simple normalization method.
fn normalize_assuming_no_symlinks(p: impl AsRef<Utf8Path>) -> Utf8PathBuf {
let mut out = Utf8PathBuf::new();
for c in p.as_ref().components() {
match c {
Utf8Component::ParentDir => {
out.pop();
}
c => out.push(c),
}
}
out
}
// Some clones in here make the code more uniform overall.
#[allow(clippy::redundant_clone)]
impl FixtureDetails {
// Specific fixtures follow.
pub(crate) fn metadata1() -> Self {
let mut details = AHashMap::new();
PackageDetails::new(
METADATA1_TESTCRATE,
"testcrate",
"0.1.0",
vec![FAKE_AUTHOR],
None,
None,
)
.with_workspace_path("")
.with_build_targets(vec![(
BuildTargetId::Binary("testcrate"),
BuildTargetKind::Binary,
"src/main.rs",
)])
.with_deps(vec![("datatest", METADATA1_DATATEST)])
.with_reverse_deps(vec![])
.insert_into(&mut details);
#[rustfmt::skip]
let datatest_deps =
vec![
("ctor", "ctor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)"),
("datatest-derive", "datatest-derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)"),
("regex", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)"),
("region", "region 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)"),
("serde", "serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)"),
("serde_yaml", "serde_yaml 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)"),
("version_check", "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)"),
// walkdir was replaced with [replace] (see metadata1.toml) -- ensure that the
// *replaced* version shows up here, not the regular one.
("walkdir", "walkdir 2.2.9 (git+https://github.com/BurntSushi/walkdir?tag=2.2.9#7c7013259eb9db400b3e5c7bc60330ca08068826)"),
("yaml-rust", "yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)")
];
static LIB_TYPE: Lazy<Vec<String>> = Lazy::new(|| vec!["lib".into()]);
PackageDetails::new(
METADATA1_DATATEST,
"datatest",
"0.4.2",
vec!["Ivan Dubrov <[email protected]>"],
Some("Data-driven tests in Rust\n"),
Some("MIT/Apache-2.0"),
)
.with_crates_io()
.with_build_targets(vec![
(
BuildTargetId::Library,
BuildTargetKind::LibraryOrExample(&LIB_TYPE),
"src/lib.rs",
),
(
BuildTargetId::BuildScript,
BuildTargetKind::Binary,
"build.rs",
),
(
BuildTargetId::Test("bench"),
BuildTargetKind::Binary,
"tests/bench.rs",
),
(
BuildTargetId::Test("datatest"),
BuildTargetKind::Binary,
"tests/datatest.rs",
),
(
BuildTargetId::Test("datatest_stable"),
BuildTargetKind::Binary,
"tests/datatest_stable.rs",
),
(
BuildTargetId::Test("datatest_stable_unsafe"),
BuildTargetKind::Binary,
"tests/datatest_stable_unsafe.rs",
),
(
BuildTargetId::Test("unicode"),
BuildTargetKind::Binary,
"tests/unicode.rs",
),
])
.with_deps(datatest_deps)
.with_reverse_deps(vec![("datatest", METADATA1_TESTCRATE)])
.insert_into(&mut details);
Self::new(details).with_workspace_members(vec![("", METADATA1_TESTCRATE)])
}
pub(crate) fn metadata2() -> Self {
let mut details = AHashMap::new();
PackageDetails::new(
METADATA2_TESTCRATE,
"testworkspace-crate",
"0.1.0",
vec![FAKE_AUTHOR],
None,
None,
)
.with_workspace_path("testcrate")
.with_deps(vec![
(
"datatest",
"datatest 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
),
// There are three instances of walkdir in the dependencies -- ensure they all
// link up correctly.
("walkdir", METADATA2_WALKDIR),
(
"walkdir-crates-io",
"walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
),
(
"walkdir-nuevo",
"walkdir 0.1.0 (path+file:///Users/fakeuser/local/walkdir)",
),
])
.with_reverse_deps(vec![])
.insert_into(&mut details);
PackageDetails::new(
METADATA2_WALKDIR,
"walkdir",
"2.2.9",
vec![FAKE_AUTHOR],
None,
None,
)
.with_workspace_path("walkdir")
.with_deps(vec![])
.with_reverse_deps(vec![("walkdir", METADATA2_TESTCRATE)])
.insert_into(&mut details);
// quote was replaced with [patch].
PackageDetails::new(
METADATA2_QUOTE,
"quote",
"1.0.2",
vec!["David Tolnay <[email protected]>"],
Some("Quasi-quoting macro quote!(...)"),
Some("MIT OR Apache-2.0"),
)
.with_local_path("../quote")
.with_deps(vec![(
"proc-macro2",
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
)])
.with_reverse_deps(vec![
(
"quote",
"ctor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
),
(
"quote",
"datatest-derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
),
(
"quote",
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
),
])
.with_named_features(vec!["default", "proc-macro"])
.insert_into(&mut details);
Self::new(details).with_workspace_members(vec![
("testcrate", METADATA2_TESTCRATE),
("walkdir", METADATA2_WALKDIR),
])
}
pub(crate) fn metadata_builddep() -> Self {
let details = AHashMap::new();
Self::new(details)
}
pub(crate) fn metadata_dups() -> Self {
let mut details = AHashMap::new();
PackageDetails::new(
METADATA_DUPS_TESTCRATE,
"testcrate-dups",
"0.1.0",
vec![FAKE_AUTHOR],
None,
None,
)
.with_workspace_path("")
.with_deps(vec![
("lazy_static", METADATA_DUPS_LAZY_STATIC_1),
("lazy_static", METADATA_DUPS_LAZY_STATIC_02),
("bytes-package", METADATA_DUPS_BYTES_03),
("bytes-package", METADATA_DUPS_BYTES_05),
])
.insert_into(&mut details);
Self::new(details).with_workspace_members(vec![("", METADATA_DUPS_TESTCRATE)])
}
pub(crate) fn metadata_cycle1() -> Self {
let mut details = AHashMap::new();
PackageDetails::new(
METADATA_CYCLE1_BASE,
"testcycles-base",
"0.1.0",
vec![FAKE_AUTHOR],
None,
None,
)
.with_workspace_path("")
.with_deps(vec![("testcycles-helper", METADATA_CYCLE1_HELPER)])
.with_transitive_deps(vec![METADATA_CYCLE1_BASE, METADATA_CYCLE1_HELPER])
.with_transitive_reverse_deps(vec![METADATA_CYCLE1_BASE, METADATA_CYCLE1_HELPER])
.insert_into(&mut details);
PackageDetails::new(
METADATA_CYCLE1_HELPER,
"testcycles-helper",
"0.1.0",
vec![FAKE_AUTHOR],
None,
None,
)
.with_local_path("../testcycles-helper")
.with_deps(vec![("testcycles-base", METADATA_CYCLE1_BASE)])
.with_transitive_deps(vec![METADATA_CYCLE1_BASE, METADATA_CYCLE1_HELPER])
.with_transitive_reverse_deps(vec![METADATA_CYCLE1_BASE, METADATA_CYCLE1_HELPER])
.insert_into(&mut details);
Self::new(details)
.with_workspace_members(vec![("", METADATA_CYCLE1_BASE)])
.with_cycles(vec![vec![METADATA_CYCLE1_HELPER, METADATA_CYCLE1_BASE]])
}
pub(crate) fn metadata_cycle2() -> Self {
// upper-a <-> upper-b
// |
// v
// lower-a <-> lower-b
let mut details = AHashMap::new();
// upper-a
PackageDetails::new(
METADATA_CYCLE2_UPPER_A,
"upper-a",
"0.1.0",
vec![FAKE_AUTHOR],
None,
None,
)
.with_workspace_path("upper-a")
.with_deps(vec![("upper-b", METADATA_CYCLE2_UPPER_B)])
.with_reverse_deps(vec![("upper-a", METADATA_CYCLE2_UPPER_B)])
.with_transitive_deps(vec![
METADATA_CYCLE2_UPPER_A,
METADATA_CYCLE2_UPPER_B,
METADATA_CYCLE2_LOWER_A,
METADATA_CYCLE2_LOWER_B,
])
.with_transitive_reverse_deps(vec![METADATA_CYCLE2_UPPER_A, METADATA_CYCLE2_UPPER_B])
.insert_into(&mut details);
// upper-b
PackageDetails::new(
METADATA_CYCLE2_UPPER_B,
"upper-b",
"0.1.0",
vec![FAKE_AUTHOR],
None,
None,
)
.with_workspace_path("upper-b")
.with_deps(vec![
("upper-a", METADATA_CYCLE2_UPPER_A),
("lower-a", METADATA_CYCLE2_LOWER_A),
])
.with_reverse_deps(vec![("upper-b", METADATA_CYCLE2_UPPER_A)])
.with_transitive_deps(vec![
METADATA_CYCLE2_UPPER_A,
METADATA_CYCLE2_UPPER_B,
METADATA_CYCLE2_LOWER_A,
METADATA_CYCLE2_LOWER_B,
])
.with_transitive_reverse_deps(vec![METADATA_CYCLE2_UPPER_A, METADATA_CYCLE2_UPPER_B])
.insert_into(&mut details);
// lower-a
PackageDetails::new(
METADATA_CYCLE2_LOWER_A,
"lower-a",
"0.1.0",
vec![FAKE_AUTHOR],
None,
None,
)
.with_workspace_path("lower-a")
.with_deps(vec![("lower-b", METADATA_CYCLE2_LOWER_B)])
.with_reverse_deps(vec![
("lower-a", METADATA_CYCLE2_UPPER_B),
("lower-a", METADATA_CYCLE2_LOWER_B),
])
.with_transitive_deps(vec![METADATA_CYCLE2_LOWER_A, METADATA_CYCLE2_LOWER_B])
.with_transitive_reverse_deps(vec![
METADATA_CYCLE2_UPPER_A,
METADATA_CYCLE2_UPPER_B,
METADATA_CYCLE2_LOWER_A,
METADATA_CYCLE2_LOWER_B,
])
.insert_into(&mut details);
// lower-b
PackageDetails::new(
METADATA_CYCLE2_LOWER_B,
"lower-b",
"0.1.0",
vec![FAKE_AUTHOR],
None,
None,
)
.with_workspace_path("lower-b")
.with_deps(vec![("lower-a", METADATA_CYCLE2_LOWER_A)])
.with_reverse_deps(vec![("lower-b", METADATA_CYCLE2_LOWER_A)])
.with_transitive_deps(vec![METADATA_CYCLE2_LOWER_A, METADATA_CYCLE2_LOWER_B])
.with_transitive_reverse_deps(vec![
METADATA_CYCLE2_UPPER_A,
METADATA_CYCLE2_UPPER_B,
METADATA_CYCLE2_LOWER_A,
METADATA_CYCLE2_LOWER_B,
])
.insert_into(&mut details);
Self::new(details)
.with_workspace_members(vec![
("upper-a", METADATA_CYCLE2_UPPER_A),
("upper-b", METADATA_CYCLE2_UPPER_B),
("lower-a", METADATA_CYCLE2_LOWER_A),
("lower-b", METADATA_CYCLE2_LOWER_B),
])
.with_cycles(vec![
// upper-b dev-depends on upper-a, and upper-a normal-depends on upper-b.
vec![METADATA_CYCLE2_UPPER_A, METADATA_CYCLE2_UPPER_B],
// lower-b dev-depends on lower-a, and lower-a normal-depends on lower-b.
vec![METADATA_CYCLE2_LOWER_A, METADATA_CYCLE2_LOWER_B],
])
}
pub(crate) fn metadata_cycle_features() -> Self {
let details = AHashMap::new();
Self::new(details)
.with_workspace_members(vec![
("testcycles-base", METADATA_CYCLE_FEATURES_BASE),
("testcycles-helper", METADATA_CYCLE_FEATURES_HELPER),
])
.with_cycles(vec![vec![
METADATA_CYCLE_FEATURES_HELPER,
METADATA_CYCLE_FEATURES_BASE,
]])
}
pub(crate) fn metadata_targets1() -> Self {
// In the testcrate:
//
// ```
// [dependencies]
// lazy_static = "1"
// bytes = { version = "0.5", default-features = false, features = ["serde"] }
// dep-a = { path = "../dep-a", optional = true }
//
// [target.'cfg(not(windows))'.dependencies]
// lazy_static = "0.2"
// dep-a = { path = "../dep-a", features = ["foo"] }
//
// [target.'cfg(windows)'.dev-dependencies]
// lazy_static = "0.1"
//
// [target.'cfg(target_arch = "x86")'.dependencies]
// bytes = { version = "=0.5.3", optional = false }
// dep-a = { path = "../dep-a", features = ["bar"] }
//
// [target.x86_64-unknown-linux-gnu.build-dependencies]
// bytes = { version = "0.5.2", optional = true, default-features = false, features = ["std"] }
//
// # Platform-specific dev-dependencies.
//
// [target.'cfg(any(target_feature = "sse2", target_feature = "atomics"))'.dev-dependencies]
// dep-a = { path = "../dep-a", default-features = false, features = ["baz"] }
//
// [target.'cfg(all(unix, not(target_feature = "sse")))'.dev-dependencies]
// dep-a = { path = "../dep-a" }
//
// [target.'cfg(any(unix, target_feature = "sse"))'.dev-dependencies]
// dep-a = { path = "../dep-a", default-features = false, features = ["quux"] }
//
// # Platform-specific build dependencies.
//
// [target.'cfg(target_feature = "sse")'.build-dependencies]
// dep-a = { path = "../dep-a", default-features = false, features = ["foo"] }
//
// # any -- evaluates to true for unix.
// [target.'cfg(any(unix, target_feature = "sse"))'.build-dependencies]
// dep-a = { path = "../dep-a", optional = true, default-features = true }
//
// # all -- evaluates to unknown on unixes if the target features are unknown.
// # Evaluates to false on Windows whether target features are known or not.
// [target.'cfg(all(unix, target_feature = "sse"))'.build-dependencies]
// dep-a = { path = "../dep-a", optional = true, default-features = false, features = ["bar"] }
// ```
let mut details = AHashMap::new();
PackageDetails::new(
METADATA_TARGETS1_TESTCRATE,
"testcrate-targets",
"0.1.0",
vec![FAKE_AUTHOR],
None,
None,
)
.with_workspace_path("")
.with_deps(vec![
("lazy_static", METADATA_TARGETS1_LAZY_STATIC_1),
("lazy_static", METADATA_TARGETS1_LAZY_STATIC_02),
("lazy_static", METADATA_TARGETS1_LAZY_STATIC_01),
("bytes", METADATA_TARGETS1_BYTES),
("dep-a", METADATA_TARGETS1_DEP_A),
])
.insert_into(&mut details);
let x86_64_linux =
Platform::new("x86_64-unknown-linux-gnu", TargetFeatures::Unknown).unwrap();
let i686_windows = Platform::new(
"i686-pc-windows-msvc",
TargetFeatures::features(["sse", "sse2"].iter().copied()),
)
.unwrap();
let x86_64_windows =
Platform::new("x86_64-pc-windows-msvc", TargetFeatures::Unknown).unwrap();
let mut link_details = AHashMap::new();
use EnabledTernary::*;
// testcrate -> lazy_static 1.
LinkDetails::new(
package_id(METADATA_TARGETS1_TESTCRATE),
package_id(METADATA_TARGETS1_LAZY_STATIC_1),
)
.with_platform_status(
DependencyKind::Normal,
x86_64_linux.clone(),
PlatformResults::new((Enabled, Enabled), (Enabled, Enabled)),
)
.with_platform_status(
DependencyKind::Normal,
i686_windows.clone(),
PlatformResults::new((Enabled, Enabled), (Enabled, Enabled)),
)
.insert_into(&mut link_details);
// testcrate -> lazy_static 0.2.
// Included on not-Windows.
LinkDetails::new(
package_id(METADATA_TARGETS1_TESTCRATE),
package_id(METADATA_TARGETS1_LAZY_STATIC_02),
)
.with_platform_status(
DependencyKind::Normal,
x86_64_linux.clone(),
PlatformResults::new((Enabled, Enabled), (Enabled, Enabled)),
)
.with_platform_status(
DependencyKind::Normal,
i686_windows.clone(),
PlatformResults::new((Disabled, Disabled), (Disabled, Disabled)),
)
.insert_into(&mut link_details);
// testcrate -> lazy_static 0.1.
// Included as a dev-dependency on Windows.
LinkDetails::new(
package_id(METADATA_TARGETS1_TESTCRATE),
package_id(METADATA_TARGETS1_LAZY_STATIC_01),
)
.with_platform_status(
DependencyKind::Development,
x86_64_linux.clone(),
PlatformResults::new((Disabled, Disabled), (Disabled, Disabled)),
)
.with_platform_status(
DependencyKind::Development,
i686_windows.clone(),
PlatformResults::new((Enabled, Enabled), (Enabled, Enabled)),
)
.insert_into(&mut link_details);
// testcrate -> bytes.
// As a normal dependency, this is always built but default-features varies.
// As a build dependency, it is only present on Linux.
LinkDetails::new(
package_id(METADATA_TARGETS1_TESTCRATE),
package_id(METADATA_TARGETS1_BYTES),
)
.with_platform_status(
DependencyKind::Normal,
x86_64_linux.clone(),
PlatformResults::new((Enabled, Enabled), (Disabled, Disabled))
.with_feature_status("serde", (Enabled, Enabled))
.with_feature_status("std", (Disabled, Disabled)),
)
.with_platform_status(
DependencyKind::Normal,
i686_windows.clone(),
PlatformResults::new((Enabled, Enabled), (Enabled, Enabled))
.with_feature_status("serde", (Enabled, Enabled))
.with_feature_status("std", (Disabled, Disabled)),
)
.with_features(DependencyKind::Normal, vec!["serde"])
.with_platform_status(
DependencyKind::Build,
x86_64_linux.clone(),
PlatformResults::new((Disabled, Enabled), (Disabled, Disabled))
.with_feature_status("serde", (Disabled, Disabled))
.with_feature_status("std", (Disabled, Enabled)),
)
.with_platform_status(
DependencyKind::Build,
i686_windows.clone(),
PlatformResults::new((Disabled, Disabled), (Disabled, Disabled))
.with_feature_status("serde", (Disabled, Disabled))
.with_feature_status("std", (Disabled, Disabled)),
)
.with_features(DependencyKind::Build, vec!["std"])
.insert_into(&mut link_details);
// testcrate -> dep-a.
// As a normal dependency, this is optionally built by default, but on not-Windows or on x86
// it is required.
// As a dev dependency, it is present if sse2 or atomics are turned on.
LinkDetails::new(
package_id(METADATA_TARGETS1_TESTCRATE),
package_id(METADATA_TARGETS1_DEP_A),
)
.with_platform_status(
DependencyKind::Normal,
x86_64_linux.clone(),
PlatformResults::new((Enabled, Enabled), (Enabled, Enabled))
.with_feature_status("foo", (Enabled, Enabled))
.with_feature_status("bar", (Disabled, Disabled))
.with_feature_status("baz", (Disabled, Disabled))
.with_feature_status("quux", (Disabled, Disabled)),
)
.with_platform_status(
DependencyKind::Normal,
i686_windows.clone(),
PlatformResults::new((Enabled, Enabled), (Enabled, Enabled))
.with_feature_status("foo", (Disabled, Disabled))
.with_feature_status("bar", (Enabled, Enabled))
.with_feature_status("baz", (Disabled, Disabled))
.with_feature_status("quux", (Disabled, Disabled)),
)
.with_platform_status(
DependencyKind::Normal,
x86_64_windows.clone(),
PlatformResults::new((Disabled, Enabled), (Disabled, Enabled))
.with_feature_status("foo", (Disabled, Disabled))
.with_feature_status("bar", (Disabled, Disabled))
.with_feature_status("baz", (Disabled, Disabled))
.with_feature_status("quux", (Disabled, Disabled)),
)
.with_platform_status(
DependencyKind::Development,
x86_64_linux.clone(),
// x86_64_linux uses TargetFeature::Unknown.
PlatformResults::new((Enabled, Enabled), (Unknown, Unknown))
.with_feature_status("foo", (Disabled, Disabled))
.with_feature_status("bar", (Disabled, Disabled))
.with_feature_status("baz", (Unknown, Unknown))
.with_feature_status("quux", (Enabled, Enabled)),
)
.with_platform_status(
DependencyKind::Development,
i686_windows.clone(),
// i686_windows turns on sse and sse2.
PlatformResults::new((Enabled, Enabled), (Disabled, Disabled))
.with_feature_status("foo", (Disabled, Disabled))
.with_feature_status("bar", (Disabled, Disabled))
.with_feature_status("baz", (Enabled, Enabled))