fixtures/
json.rs

1// Copyright (c) The cargo-guppy Contributors
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4use crate::{
5    details::{FixtureDetails, LinkDetails, PackageDetails, PlatformResults},
6    package_id,
7};
8use ahash::AHashMap;
9use camino::{Utf8Component, Utf8Path, Utf8PathBuf};
10use guppy::{
11    CargoMetadata, DependencyKind,
12    errors::{FeatureBuildStage, FeatureGraphWarning},
13    graph::{BuildTargetId, BuildTargetKind, PackageGraph},
14    platform::{EnabledTernary, Platform, TargetFeatures},
15};
16use once_cell::sync::{Lazy, OnceCell};
17use std::{collections::BTreeMap, fs};
18
19// Metadata along with interesting crate names.
20pub static METADATA1_PATH: &str = "../small/metadata1.json";
21pub static METADATA1_TESTCRATE: &str = "testcrate 0.1.0 (path+file:///fakepath/testcrate)";
22pub static METADATA1_DATATEST: &str =
23    "datatest 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)";
24pub static METADATA1_REGION: &str =
25    "region 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)";
26pub static METADATA1_DTOA: &str =
27    "dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)";
28
29pub static METADATA2_PATH: &str = "../small/metadata2.json";
30pub static METADATA2_TESTCRATE: &str =
31    "testworkspace-crate 0.1.0 (path+file:///Users/fakeuser/local/testworkspace/testcrate)";
32pub static METADATA2_WALKDIR: &str =
33    "walkdir 2.2.9 (path+file:///Users/fakeuser/local/testworkspace/walkdir)";
34pub static METADATA2_QUOTE: &str = "quote 1.0.2 (path+file:///Users/fakeuser/local/quote)";
35
36pub static METADATA_BUILDDEP_PATH: &str = "../small/builddep.json";
37
38pub static METADATA_DUPS_PATH: &str = "../small/metadata_dups.json";
39pub static METADATA_DUPS_TESTCRATE: &str =
40    "testcrate-dups 0.1.0 (path+file:///Users/fakeuser/local/testcrates/testcrate-dups)";
41pub static METADATA_DUPS_LAZY_STATIC_1: &str =
42    "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)";
43pub static METADATA_DUPS_LAZY_STATIC_02: &str =
44    "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)";
45pub static METADATA_DUPS_BYTES_03: &str =
46    "bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)";
47pub static METADATA_DUPS_BYTES_05: &str =
48    "bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)";
49
50pub static METADATA_CYCLE1_PATH: &str = "../small/metadata_cycle1.json";
51pub static METADATA_CYCLE1_BASE: &str = "testcycles-base 0.1.0 (path+file:///Users/fakeuser/local/testcrates/testcycles/testcycles-base)";
52pub static METADATA_CYCLE1_HELPER: &str = "testcycles-helper 0.1.0 (path+file:///Users/fakeuser/local/testcrates/testcycles/testcycles-helper)";
53
54pub static METADATA_CYCLE2_PATH: &str = "../small/metadata_cycle2.json";
55pub static METADATA_CYCLE2_UPPER_A: &str =
56    "upper-a 0.1.0 (path+file:///Users/fakeuser/local/testcrates/cycle2/upper-a)";
57pub static METADATA_CYCLE2_UPPER_B: &str =
58    "upper-b 0.1.0 (path+file:///Users/fakeuser/local/testcrates/cycle2/upper-b)";
59pub static METADATA_CYCLE2_LOWER_A: &str =
60    "lower-a 0.1.0 (path+file:///Users/fakeuser/local/testcrates/cycle2/lower-a)";
61pub static METADATA_CYCLE2_LOWER_B: &str =
62    "lower-b 0.1.0 (path+file:///Users/fakeuser/local/testcrates/cycle2/lower-b)";
63
64pub static METADATA_CYCLE_FEATURES_PATH: &str = "../small/metadata_cycle_features.json";
65pub static METADATA_CYCLE_FEATURES_BASE: &str =
66    "testcycles-base 0.1.0 (path+file:///fakepath/testcycles-features/testcycles-base)";
67pub static METADATA_CYCLE_FEATURES_HELPER: &str =
68    "testcycles-helper 0.1.0 (path+file:///fakepath/testcycles-features/testcycles-helper)";
69
70pub static METADATA_TARGETS1_PATH: &str = "../small/metadata_targets1.json";
71pub static METADATA_TARGETS1_TESTCRATE: &str =
72    "testcrate-targets 0.1.0 (path+file:///Users/fakeuser/local/testcrates/testcrate-targets)";
73pub static METADATA_TARGETS1_LAZY_STATIC_1: &str =
74    "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)";
75pub static METADATA_TARGETS1_LAZY_STATIC_02: &str =
76    "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)";
77pub static METADATA_TARGETS1_LAZY_STATIC_01: &str =
78    "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)";
79pub static METADATA_TARGETS1_BYTES: &str =
80    "bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)";
81pub static METADATA_TARGETS1_DEP_A: &str =
82    "dep-a 0.1.0 (path+file:///Users/fakeuser/local/testcrates/dep-a)";
83
84pub static METADATA_BUILD_TARGETS1_PATH: &str = "../small/metadata_build_targets1.json";
85pub static METADATA_BUILD_TARGETS1_TESTCRATE: &str =
86    "testcrate 0.1.0 (path+file:///Users/fakeuser/local/testcrates/test-build-targets)";
87
88pub static METADATA_PROC_MACRO1_PATH: &str = "../small/metadata_proc_macro1.json";
89pub static METADATA_PROC_MACRO1_MACRO: &str =
90    "macro 0.1.0 (path+file:///Users/fakeuser/local/testcrates/proc-macro/macro)";
91pub static METADATA_PROC_MACRO1_NORMAL_USER: &str =
92    "normal-user 0.1.0 (path+file:///Users/fakeuser/local/testcrates/proc-macro/normal-user)";
93pub static METADATA_PROC_MACRO1_BUILD_USER: &str =
94    "build-user 0.1.0 (path+file:///Users/fakeuser/local/testcrates/proc-macro/build-user)";
95pub static METADATA_PROC_MACRO1_DEV_USER: &str =
96    "dev-user 0.1.0 (path+file:///Users/fakeuser/local/testcrates/proc-macro/dev-user)";
97
98pub static METADATA_ALTERNATE_REGISTRIES_PATH: &str = "../small/alternate-registries.json";
99pub static METADATA_ALTERNATE_REGISTRY_URL: &str = "https://github.com/fakeorg/crates.io-index";
100
101pub static METADATA_WEAK_NAMESPACED_FEATURES_PATH: &str = "../small/weak-namespaced-features.json";
102pub static METADATA_WEAK_NAMESPACED_ID: &str =
103    "namespaced-weak 0.1.0 (path+file:///home/fakeuser/dev/tmp/test-workspaces/namespaced-weak)";
104pub static METADATA_WEAK_NAMESPACED_SMALLVEC: &str =
105    "smallvec 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)";
106pub static METADATA_WEAK_NAMESPACED_ARRAYVEC: &str =
107    "arrayvec 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)";
108pub static METADATA_WEAK_NAMESPACED_TINYVEC: &str =
109    "tinyvec 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)";
110
111pub static METADATA_LIBRA_PATH: &str = "../large/metadata_libra.json";
112pub static METADATA_LIBRA_ADMISSION_CONTROL_SERVICE: &str = "admission-control-service 0.1.0 (path+file:///Users/fakeuser/local/libra/admission_control/admission-control-service)";
113pub static METADATA_LIBRA_COMPILER: &str =
114    "compiler 0.1.0 (path+file:///Users/fakeuser/local/libra/language/compiler)";
115pub static METADATA_LIBRA_E2E_TESTS: &str =
116    "language-e2e-tests 0.1.0 (path+file:///Users/fakeuser/local/libra/language/e2e-tests)";
117pub static METADATA_LIBRA_EXECUTOR: &str =
118    "executor 0.1.0 (path+file:///Users/fakeuser/local/libra/execution/executor)";
119pub static METADATA_LIBRA_EXECUTOR_UTILS: &str =
120    "executor-utils 0.1.0 (path+file:///Users/fakeuser/local/libra/execution/executor-utils)";
121pub static METADATA_LIBRA_COST_SYNTHESIS: &str =
122    "cost-synthesis 0.1.0 (path+file:///Users/fakeuser/local/libra/language/tools/cost-synthesis)";
123pub static METADATA_LIBRA_FUNCTIONAL_TESTS: &str =
124    "functional_tests 0.1.0 (path+file:///Users/fakeuser/local/libra/language/functional_tests)";
125pub static METADATA_LIBRA_FUNCTIONAL_HYPHEN_TESTS: &str =
126    "functional-tests 0.1.0 (path+file:///Users/fakeuser/local/libra/language/functional-tests)";
127pub static METADATA_LIBRA_LIBRA_VM: &str =
128    "libra-vm 0.1.0 (path+file:///Users/fakeuser/local/libra/language/libra-vm)";
129pub static METADATA_LIBRA_MOVE_LANG: &str =
130    "move-lang 0.0.1 (path+file:///Users/fakeuser/local/libra/language/move-lang)";
131pub static METADATA_LIBRA_MOVE_LANG_STDLIB: &str =
132    "move-lang-stdlib 0.1.0 (path+file:///Users/fakeuser/local/libra/language/move-lang/stdlib)";
133pub static METADATA_LIBRA_MOVE_VM_RUNTIME: &str =
134    "move-vm-runtime 0.1.0 (path+file:///Users/fakeuser/local/libra/language/move-vm/runtime)";
135pub static METADATA_LIBRA_STDLIB: &str =
136    "stdlib 0.1.0 (path+file:///Users/fakeuser/local/libra/language/stdlib)";
137pub static METADATA_LIBRA_TEST_GENERATION: &str = "test-generation 0.1.0 (path+file:///Users/fakeuser/local/libra/language/tools/test-generation)";
138pub static METADATA_LIBRA_TRANSACTION_BUILDER: &str = "transaction-builder 0.1.0 (path+file:///Users/fakeuser/local/libra/language/transaction-builder)";
139pub static METADATA_LIBRA_VM_GENESIS: &str =
140    "vm-genesis 0.1.0 (path+file:///Users/fakeuser/local/libra/language/tools/vm-genesis)";
141pub static METADATA_LIBRA_LANGUAGE_BENCHMARKS: &str =
142    "language_benchmarks 0.1.0 (path+file:///Users/fakeuser/local/libra/language/benchmarks)";
143pub static METADATA_LIBRA_TREE_HEAP: &str = "tree_heap 0.1.0 (path+file:///Users/fakeuser/local/libra/language/stackless-bytecode/tree_heap)";
144pub static METADATA_LIBRA_LAZY_STATIC: &str =
145    "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)";
146pub static METADATA_LIBRA_BACKTRACE: &str =
147    "backtrace 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)";
148pub static METADATA_LIBRA_CFG_IF: &str =
149    "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)";
150
151pub static METADATA_LIBRA_F0091A4_PATH: &str = "../large/metadata_libra_f0091a4.json";
152
153pub static METADATA_LIBRA_9FFD93B_PATH: &str = "../large/metadata_libra_9ffd93b.json";
154
155pub static MNEMOS_B3B4DA9_PATH: &str = "../large/mnemos_b3b4da9.json";
156
157pub static HYPER_UTIL_7AFB1ED_PATH: &str = "../large/hyper_util_7afb1ed.json";
158
159pub static METADATA_GUPPY_78CB7E8_PATH: &str = "../guppy/metadata_guppy_78cb7e8.json";
160
161pub static METADATA_GUPPY_869476C_PATH: &str = "../guppy/metadata_guppy_869476c.json";
162
163pub static METADATA_GUPPY_C9B4F76_PATH: &str = "../guppy/metadata_guppy_c9b4f76.json";
164
165pub static METADATA_GUPPY_44B62FA_PATH: &str = "../guppy/metadata_guppy_44b62fa.json";
166pub static METADATA_GUPPY_CARGO_GUPPY: &str =
167    "cargo-guppy 0.1.0 (path+file:///home/fakeuser/dev/cargo-guppy/cargo-guppy)";
168
169pub static FAKE_AUTHOR: &str = "Fake Author <fakeauthor@example.com>";
170
171macro_rules! define_fixtures {
172    ($($name: ident => $json_path: ident,)*) => {
173        impl JsonFixture {
174            // Access all fixtures.
175            pub fn all_fixtures() -> &'static BTreeMap<&'static str, JsonFixture> {
176                // Provide a list of all fixtures.
177                static ALL_FIXTURES: Lazy<BTreeMap<&'static str, JsonFixture>> = Lazy::new(|| {
178                    let mut map = BTreeMap::new();
179
180                    $(map.insert(
181                        stringify!($name),
182                        JsonFixture::new(stringify!($name), $json_path, FixtureDetails::$name()),
183                    );)*
184
185                    map
186                });
187
188                &*ALL_FIXTURES
189            }
190
191            // Access individual fixtures if the name is known.
192            $(pub fn $name() -> &'static Self {
193                &JsonFixture::all_fixtures()[stringify!($name)]
194            })*
195        }
196    };
197}
198
199define_fixtures! {
200    metadata1 => METADATA1_PATH,
201    metadata2 => METADATA2_PATH,
202    metadata_builddep => METADATA_BUILDDEP_PATH,
203    metadata_dups => METADATA_DUPS_PATH,
204    metadata_cycle1 => METADATA_CYCLE1_PATH,
205    metadata_cycle2 => METADATA_CYCLE2_PATH,
206    metadata_cycle_features => METADATA_CYCLE_FEATURES_PATH,
207    metadata_targets1 => METADATA_TARGETS1_PATH,
208    metadata_build_targets1 => METADATA_BUILD_TARGETS1_PATH,
209    metadata_proc_macro1 => METADATA_PROC_MACRO1_PATH,
210    metadata_alternate_registries => METADATA_ALTERNATE_REGISTRIES_PATH,
211    metadata_weak_namespaced_features => METADATA_WEAK_NAMESPACED_FEATURES_PATH,
212    metadata_libra => METADATA_LIBRA_PATH,
213    metadata_libra_f0091a4 => METADATA_LIBRA_F0091A4_PATH,
214    metadata_libra_9ffd93b => METADATA_LIBRA_9FFD93B_PATH,
215    mnemos_b3b4da9 => MNEMOS_B3B4DA9_PATH,
216    hyper_util_7afb1ed => HYPER_UTIL_7AFB1ED_PATH,
217    metadata_guppy_78cb7e8 => METADATA_GUPPY_78CB7E8_PATH,
218    metadata_guppy_869476c => METADATA_GUPPY_869476C_PATH,
219    metadata_guppy_c9b4f76 => METADATA_GUPPY_C9B4F76_PATH,
220    metadata_guppy_44b62fa => METADATA_GUPPY_44B62FA_PATH,
221}
222
223pub struct JsonFixture {
224    name: &'static str,
225    workspace_path: Utf8PathBuf,
226    abs_path: Utf8PathBuf,
227    json_graph: OnceCell<(String, PackageGraph)>,
228    details: FixtureDetails,
229}
230
231impl JsonFixture {
232    fn new(name: &'static str, rel_path: &'static str, details: FixtureDetails) -> Self {
233        let rel_path = Utf8Path::new(rel_path);
234        let fixtures_dir = Utf8Path::new(env!("CARGO_MANIFEST_DIR"));
235        // rel_path is relative to this dir.
236        let mut abs_path = fixtures_dir.join("src");
237        abs_path.push(rel_path);
238        let abs_path = Utf8PathBuf::from_path_buf(
239            abs_path
240                .canonicalize()
241                .expect("fixture path canonicalization succeeded"),
242        )
243        .expect("valid UTF-8 path");
244
245        let workspace_root = fixtures_dir.parent().expect("up to workspace root");
246        let workspace_path = Utf8PathBuf::from_path_buf(
247            pathdiff::diff_paths(&abs_path, workspace_root)
248                .expect("both abs_path and workspace root are absolute"),
249        )
250        .expect("diff of UTF-8 paths is UTF-8");
251
252        // No symlinks in this repo, so normalize this path.
253        let workspace_path = normalize_assuming_no_symlinks(workspace_path);
254
255        Self {
256            name,
257            workspace_path,
258            abs_path,
259            json_graph: OnceCell::new(),
260            details,
261        }
262    }
263
264    /// Lookup a fixture by name, or `None` if the name wasn't found.
265    pub fn by_name(name: &str) -> Option<&'static Self> {
266        Self::all_fixtures().get(name)
267    }
268
269    /// Returns the name of this fixture.
270    pub fn name(&self) -> &'static str {
271        self.name
272    }
273
274    /// Returns the absolute path of this fixture.
275    pub fn abs_path(&self) -> &Utf8Path {
276        &self.abs_path
277    }
278
279    /// Returns the path of this fixture, relative to the workspace root.
280    pub fn workspace_path(&self) -> &Utf8Path {
281        &self.workspace_path
282    }
283
284    /// Returns the unparsed JSON string for this fixture.
285    pub fn json(&self) -> &str {
286        self.init_graph().0
287    }
288
289    /// Returns the package graph for this fixture.
290    pub fn graph(&self) -> &PackageGraph {
291        self.init_graph().1
292    }
293
294    /// Returns the test details for this fixture.
295    pub fn details(&self) -> &FixtureDetails {
296        &self.details
297    }
298
299    /// Verifies that the parsed metadata matches known details.
300    pub fn verify(&self) {
301        let graph = self.graph();
302
303        graph.verify().expect("graph verification should succeed");
304
305        // Check that all external sources parse correctly in all graphs.
306        for package in graph.packages() {
307            let source = package.source();
308            if source.is_external() {
309                let external = source
310                    .parse_external()
311                    .unwrap_or_else(|| panic!("cannot parse external source {}", source));
312                assert_eq!(
313                    format!("{}", external),
314                    source.external_source().expect("is_external is true"),
315                    "roundtrip with ExternalSource"
316                );
317            }
318        }
319
320        self.details.assert_cycles(graph, "cycles");
321
322        self.details.assert_workspace(graph.workspace());
323        self.details.assert_topo(graph);
324
325        for id in self.details.known_ids() {
326            let msg = format!("error while verifying package '{}'", id);
327            let metadata = graph.metadata(id).expect(&msg);
328            self.details.assert_metadata(id, metadata, &msg);
329
330            // Check for build targets.
331            if self.details.has_build_targets(id) {
332                self.details.assert_build_targets(metadata, &msg);
333            }
334
335            // Check for direct dependency queries.
336            if self.details.has_deps(id) {
337                self.details.assert_deps(graph, id, &msg);
338            }
339            if self.details.has_reverse_deps(id) {
340                self.details.assert_reverse_deps(graph, id, &msg);
341            }
342
343            // Check for transitive dependency queries. Use both ID based and edge-based queries.
344            if self.details.has_transitive_deps(id) {
345                self.details.assert_transitive_deps(
346                    graph,
347                    id,
348                    &format!("{} (transitive deps)", msg),
349                );
350            }
351            if self.details.has_transitive_reverse_deps(id) {
352                self.details.assert_transitive_reverse_deps(
353                    graph,
354                    id,
355                    &format!("{} (transitive reverse deps)", msg),
356                );
357            }
358
359            // Check for named features.
360            if self.details.has_named_features(id) {
361                self.details
362                    .assert_named_features(graph, id, &format!("{} (named features)", msg));
363            }
364        }
365
366        self.details.assert_link_details(graph, "link details");
367
368        // Tests for the feature graph.
369        self.details
370            .assert_feature_graph_warnings(graph, "feature graph warnings");
371    }
372
373    fn init_graph(&self) -> (&str, &PackageGraph) {
374        let (json, package_graph) = self.json_graph.get_or_init(|| {
375            let json = fs::read_to_string(&self.abs_path)
376                .unwrap_or_else(|err| panic!("reading file '{}' failed: {}", self.abs_path, err));
377            let graph = Self::parse_graph(&json);
378            (json, graph)
379        });
380        (json.as_str(), package_graph)
381    }
382
383    fn parse_graph(json: &str) -> PackageGraph {
384        let metadata =
385            CargoMetadata::parse_json(json).expect("parsing metadata JSON should succeed");
386        PackageGraph::from_metadata(metadata).expect("constructing package graph should succeed")
387    }
388}
389
390// Thanks to @porglezomp on Twitter for this simple normalization method.
391fn normalize_assuming_no_symlinks(p: impl AsRef<Utf8Path>) -> Utf8PathBuf {
392    let mut out = Utf8PathBuf::new();
393    for c in p.as_ref().components() {
394        match c {
395            Utf8Component::ParentDir => {
396                out.pop();
397            }
398            c => out.push(c),
399        }
400    }
401    out
402}
403
404// Some clones in here make the code more uniform overall.
405#[allow(clippy::redundant_clone)]
406impl FixtureDetails {
407    // Specific fixtures follow.
408
409    pub(crate) fn metadata1() -> Self {
410        let mut details = AHashMap::new();
411
412        PackageDetails::new(
413            METADATA1_TESTCRATE,
414            "testcrate",
415            "0.1.0",
416            vec![FAKE_AUTHOR],
417            None,
418            None,
419        )
420        .with_workspace_path("")
421        .with_build_targets(vec![(
422            BuildTargetId::Binary("testcrate"),
423            BuildTargetKind::Binary,
424            "src/main.rs",
425        )])
426        .with_deps(vec![("datatest", METADATA1_DATATEST)])
427        .with_reverse_deps(vec![])
428        .insert_into(&mut details);
429
430        #[rustfmt::skip]
431        let datatest_deps =
432            vec![
433                ("ctor", "ctor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)"),
434                ("datatest-derive", "datatest-derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)"),
435                ("regex", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)"),
436                ("region", "region 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)"),
437                ("serde", "serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)"),
438                ("serde_yaml", "serde_yaml 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)"),
439                ("version_check", "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)"),
440                // walkdir was replaced with [replace] (see metadata1.toml) -- ensure that the
441                // *replaced* version shows up here, not the regular one.
442                ("walkdir", "walkdir 2.2.9 (git+https://github.com/BurntSushi/walkdir?tag=2.2.9#7c7013259eb9db400b3e5c7bc60330ca08068826)"),
443                ("yaml-rust", "yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)")
444            ];
445
446        static LIB_TYPE: Lazy<Vec<String>> = Lazy::new(|| vec!["lib".into()]);
447
448        PackageDetails::new(
449            METADATA1_DATATEST,
450            "datatest",
451            "0.4.2",
452            vec!["Ivan Dubrov <ivan@commure.com>"],
453            Some("Data-driven tests in Rust\n"),
454            Some("MIT/Apache-2.0"),
455        )
456        .with_crates_io()
457        .with_build_targets(vec![
458            (
459                BuildTargetId::Library,
460                BuildTargetKind::LibraryOrExample(&LIB_TYPE),
461                "src/lib.rs",
462            ),
463            (
464                BuildTargetId::BuildScript,
465                BuildTargetKind::Binary,
466                "build.rs",
467            ),
468            (
469                BuildTargetId::Test("bench"),
470                BuildTargetKind::Binary,
471                "tests/bench.rs",
472            ),
473            (
474                BuildTargetId::Test("datatest"),
475                BuildTargetKind::Binary,
476                "tests/datatest.rs",
477            ),
478            (
479                BuildTargetId::Test("datatest_stable"),
480                BuildTargetKind::Binary,
481                "tests/datatest_stable.rs",
482            ),
483            (
484                BuildTargetId::Test("datatest_stable_unsafe"),
485                BuildTargetKind::Binary,
486                "tests/datatest_stable_unsafe.rs",
487            ),
488            (
489                BuildTargetId::Test("unicode"),
490                BuildTargetKind::Binary,
491                "tests/unicode.rs",
492            ),
493        ])
494        .with_deps(datatest_deps)
495        .with_reverse_deps(vec![("datatest", METADATA1_TESTCRATE)])
496        .insert_into(&mut details);
497
498        Self::new(details).with_workspace_members(vec![("", METADATA1_TESTCRATE)])
499    }
500
501    pub(crate) fn metadata2() -> Self {
502        let mut details = AHashMap::new();
503
504        PackageDetails::new(
505            METADATA2_TESTCRATE,
506            "testworkspace-crate",
507            "0.1.0",
508            vec![FAKE_AUTHOR],
509            None,
510            None,
511        )
512        .with_workspace_path("testcrate")
513        .with_deps(vec![
514            (
515                "datatest",
516                "datatest 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
517            ),
518            // There are three instances of walkdir in the dependencies -- ensure they all
519            // link up correctly.
520            ("walkdir", METADATA2_WALKDIR),
521            (
522                "walkdir-crates-io",
523                "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
524            ),
525            (
526                "walkdir-nuevo",
527                "walkdir 0.1.0 (path+file:///Users/fakeuser/local/walkdir)",
528            ),
529        ])
530        .with_reverse_deps(vec![])
531        .insert_into(&mut details);
532
533        PackageDetails::new(
534            METADATA2_WALKDIR,
535            "walkdir",
536            "2.2.9",
537            vec![FAKE_AUTHOR],
538            None,
539            None,
540        )
541        .with_workspace_path("walkdir")
542        .with_deps(vec![])
543        .with_reverse_deps(vec![("walkdir", METADATA2_TESTCRATE)])
544        .insert_into(&mut details);
545
546        // quote was replaced with [patch].
547        PackageDetails::new(
548            METADATA2_QUOTE,
549            "quote",
550            "1.0.2",
551            vec!["David Tolnay <dtolnay@gmail.com>"],
552            Some("Quasi-quoting macro quote!(...)"),
553            Some("MIT OR Apache-2.0"),
554        )
555        .with_local_path("../quote")
556        .with_deps(vec![(
557            "proc-macro2",
558            "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
559        )])
560        .with_reverse_deps(vec![
561            (
562                "quote",
563                "ctor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
564            ),
565            (
566                "quote",
567                "datatest-derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
568            ),
569            (
570                "quote",
571                "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
572            ),
573        ])
574        .with_named_features(vec!["default", "proc-macro"])
575        .insert_into(&mut details);
576
577        Self::new(details).with_workspace_members(vec![
578            ("testcrate", METADATA2_TESTCRATE),
579            ("walkdir", METADATA2_WALKDIR),
580        ])
581    }
582
583    pub(crate) fn metadata_builddep() -> Self {
584        let details = AHashMap::new();
585
586        Self::new(details)
587    }
588
589    pub(crate) fn metadata_dups() -> Self {
590        let mut details = AHashMap::new();
591
592        PackageDetails::new(
593            METADATA_DUPS_TESTCRATE,
594            "testcrate-dups",
595            "0.1.0",
596            vec![FAKE_AUTHOR],
597            None,
598            None,
599        )
600        .with_workspace_path("")
601        .with_deps(vec![
602            ("lazy_static", METADATA_DUPS_LAZY_STATIC_1),
603            ("lazy_static", METADATA_DUPS_LAZY_STATIC_02),
604            ("bytes-package", METADATA_DUPS_BYTES_03),
605            ("bytes-package", METADATA_DUPS_BYTES_05),
606        ])
607        .insert_into(&mut details);
608
609        Self::new(details).with_workspace_members(vec![("", METADATA_DUPS_TESTCRATE)])
610    }
611
612    pub(crate) fn metadata_cycle1() -> Self {
613        let mut details = AHashMap::new();
614
615        PackageDetails::new(
616            METADATA_CYCLE1_BASE,
617            "testcycles-base",
618            "0.1.0",
619            vec![FAKE_AUTHOR],
620            None,
621            None,
622        )
623        .with_workspace_path("")
624        .with_deps(vec![("testcycles-helper", METADATA_CYCLE1_HELPER)])
625        .with_transitive_deps(vec![METADATA_CYCLE1_BASE, METADATA_CYCLE1_HELPER])
626        .with_transitive_reverse_deps(vec![METADATA_CYCLE1_BASE, METADATA_CYCLE1_HELPER])
627        .insert_into(&mut details);
628
629        PackageDetails::new(
630            METADATA_CYCLE1_HELPER,
631            "testcycles-helper",
632            "0.1.0",
633            vec![FAKE_AUTHOR],
634            None,
635            None,
636        )
637        .with_local_path("../testcycles-helper")
638        .with_deps(vec![("testcycles-base", METADATA_CYCLE1_BASE)])
639        .with_transitive_deps(vec![METADATA_CYCLE1_BASE, METADATA_CYCLE1_HELPER])
640        .with_transitive_reverse_deps(vec![METADATA_CYCLE1_BASE, METADATA_CYCLE1_HELPER])
641        .insert_into(&mut details);
642
643        Self::new(details)
644            .with_workspace_members(vec![("", METADATA_CYCLE1_BASE)])
645            .with_cycles(vec![vec![METADATA_CYCLE1_HELPER, METADATA_CYCLE1_BASE]])
646    }
647
648    pub(crate) fn metadata_cycle2() -> Self {
649        // upper-a <-> upper-b
650        //                |
651        //                v
652        //             lower-a <-> lower-b
653        let mut details = AHashMap::new();
654
655        // upper-a
656        PackageDetails::new(
657            METADATA_CYCLE2_UPPER_A,
658            "upper-a",
659            "0.1.0",
660            vec![FAKE_AUTHOR],
661            None,
662            None,
663        )
664        .with_workspace_path("upper-a")
665        .with_deps(vec![("upper-b", METADATA_CYCLE2_UPPER_B)])
666        .with_reverse_deps(vec![("upper-a", METADATA_CYCLE2_UPPER_B)])
667        .with_transitive_deps(vec![
668            METADATA_CYCLE2_UPPER_A,
669            METADATA_CYCLE2_UPPER_B,
670            METADATA_CYCLE2_LOWER_A,
671            METADATA_CYCLE2_LOWER_B,
672        ])
673        .with_transitive_reverse_deps(vec![METADATA_CYCLE2_UPPER_A, METADATA_CYCLE2_UPPER_B])
674        .insert_into(&mut details);
675
676        // upper-b
677        PackageDetails::new(
678            METADATA_CYCLE2_UPPER_B,
679            "upper-b",
680            "0.1.0",
681            vec![FAKE_AUTHOR],
682            None,
683            None,
684        )
685        .with_workspace_path("upper-b")
686        .with_deps(vec![
687            ("upper-a", METADATA_CYCLE2_UPPER_A),
688            ("lower-a", METADATA_CYCLE2_LOWER_A),
689        ])
690        .with_reverse_deps(vec![("upper-b", METADATA_CYCLE2_UPPER_A)])
691        .with_transitive_deps(vec![
692            METADATA_CYCLE2_UPPER_A,
693            METADATA_CYCLE2_UPPER_B,
694            METADATA_CYCLE2_LOWER_A,
695            METADATA_CYCLE2_LOWER_B,
696        ])
697        .with_transitive_reverse_deps(vec![METADATA_CYCLE2_UPPER_A, METADATA_CYCLE2_UPPER_B])
698        .insert_into(&mut details);
699
700        // lower-a
701        PackageDetails::new(
702            METADATA_CYCLE2_LOWER_A,
703            "lower-a",
704            "0.1.0",
705            vec![FAKE_AUTHOR],
706            None,
707            None,
708        )
709        .with_workspace_path("lower-a")
710        .with_deps(vec![("lower-b", METADATA_CYCLE2_LOWER_B)])
711        .with_reverse_deps(vec![
712            ("lower-a", METADATA_CYCLE2_UPPER_B),
713            ("lower-a", METADATA_CYCLE2_LOWER_B),
714        ])
715        .with_transitive_deps(vec![METADATA_CYCLE2_LOWER_A, METADATA_CYCLE2_LOWER_B])
716        .with_transitive_reverse_deps(vec![
717            METADATA_CYCLE2_UPPER_A,
718            METADATA_CYCLE2_UPPER_B,
719            METADATA_CYCLE2_LOWER_A,
720            METADATA_CYCLE2_LOWER_B,
721        ])
722        .insert_into(&mut details);
723
724        // lower-b
725        PackageDetails::new(
726            METADATA_CYCLE2_LOWER_B,
727            "lower-b",
728            "0.1.0",
729            vec![FAKE_AUTHOR],
730            None,
731            None,
732        )
733        .with_workspace_path("lower-b")
734        .with_deps(vec![("lower-a", METADATA_CYCLE2_LOWER_A)])
735        .with_reverse_deps(vec![("lower-b", METADATA_CYCLE2_LOWER_A)])
736        .with_transitive_deps(vec![METADATA_CYCLE2_LOWER_A, METADATA_CYCLE2_LOWER_B])
737        .with_transitive_reverse_deps(vec![
738            METADATA_CYCLE2_UPPER_A,
739            METADATA_CYCLE2_UPPER_B,
740            METADATA_CYCLE2_LOWER_A,
741            METADATA_CYCLE2_LOWER_B,
742        ])
743        .insert_into(&mut details);
744
745        Self::new(details)
746            .with_workspace_members(vec![
747                ("upper-a", METADATA_CYCLE2_UPPER_A),
748                ("upper-b", METADATA_CYCLE2_UPPER_B),
749                ("lower-a", METADATA_CYCLE2_LOWER_A),
750                ("lower-b", METADATA_CYCLE2_LOWER_B),
751            ])
752            .with_cycles(vec![
753                // upper-b dev-depends on upper-a, and upper-a normal-depends on upper-b.
754                vec![METADATA_CYCLE2_UPPER_A, METADATA_CYCLE2_UPPER_B],
755                // lower-b dev-depends on lower-a, and lower-a normal-depends on lower-b.
756                vec![METADATA_CYCLE2_LOWER_A, METADATA_CYCLE2_LOWER_B],
757            ])
758    }
759
760    pub(crate) fn metadata_cycle_features() -> Self {
761        let details = AHashMap::new();
762
763        Self::new(details)
764            .with_workspace_members(vec![
765                ("testcycles-base", METADATA_CYCLE_FEATURES_BASE),
766                ("testcycles-helper", METADATA_CYCLE_FEATURES_HELPER),
767            ])
768            .with_cycles(vec![vec![
769                METADATA_CYCLE_FEATURES_HELPER,
770                METADATA_CYCLE_FEATURES_BASE,
771            ]])
772    }
773
774    pub(crate) fn metadata_targets1() -> Self {
775        // In the testcrate:
776        //
777        // ```
778        // [dependencies]
779        // lazy_static = "1"
780        // bytes = { version = "0.5", default-features = false, features = ["serde"] }
781        // dep-a = { path = "../dep-a", optional = true }
782        //
783        // [target.'cfg(not(windows))'.dependencies]
784        // lazy_static = "0.2"
785        // dep-a = { path = "../dep-a", features = ["foo"] }
786        //
787        // [target.'cfg(windows)'.dev-dependencies]
788        // lazy_static = "0.1"
789        //
790        // [target.'cfg(target_arch = "x86")'.dependencies]
791        // bytes = { version = "=0.5.3", optional = false }
792        // dep-a = { path = "../dep-a", features = ["bar"] }
793        //
794        // [target.x86_64-unknown-linux-gnu.build-dependencies]
795        // bytes = { version = "0.5.2", optional = true, default-features = false, features = ["std"] }
796        //
797        // # Platform-specific dev-dependencies.
798        //
799        // [target.'cfg(any(target_feature = "sse2", target_feature = "atomics"))'.dev-dependencies]
800        // dep-a = { path = "../dep-a", default-features = false, features = ["baz"] }
801        //
802        // [target.'cfg(all(unix, not(target_feature = "sse")))'.dev-dependencies]
803        // dep-a = { path = "../dep-a" }
804        //
805        // [target.'cfg(any(unix, target_feature = "sse"))'.dev-dependencies]
806        // dep-a = { path = "../dep-a", default-features = false, features = ["quux"] }
807        //
808        // # Platform-specific build dependencies.
809        //
810        // [target.'cfg(target_feature = "sse")'.build-dependencies]
811        // dep-a = { path = "../dep-a", default-features = false, features = ["foo"] }
812        //
813        // # any -- evaluates to true for unix.
814        // [target.'cfg(any(unix, target_feature = "sse"))'.build-dependencies]
815        // dep-a = { path = "../dep-a", optional = true, default-features = true }
816        //
817        // # all -- evaluates to unknown on unixes if the target features are unknown.
818        // # Evaluates to false on Windows whether target features are known or not.
819        // [target.'cfg(all(unix, target_feature = "sse"))'.build-dependencies]
820        // dep-a = { path = "../dep-a", optional = true, default-features = false, features = ["bar"] }
821        // ```
822        let mut details = AHashMap::new();
823
824        PackageDetails::new(
825            METADATA_TARGETS1_TESTCRATE,
826            "testcrate-targets",
827            "0.1.0",
828            vec![FAKE_AUTHOR],
829            None,
830            None,
831        )
832        .with_workspace_path("")
833        .with_deps(vec![
834            ("lazy_static", METADATA_TARGETS1_LAZY_STATIC_1),
835            ("lazy_static", METADATA_TARGETS1_LAZY_STATIC_02),
836            ("lazy_static", METADATA_TARGETS1_LAZY_STATIC_01),
837            ("bytes", METADATA_TARGETS1_BYTES),
838            ("dep-a", METADATA_TARGETS1_DEP_A),
839        ])
840        .insert_into(&mut details);
841
842        let x86_64_linux =
843            Platform::new("x86_64-unknown-linux-gnu", TargetFeatures::Unknown).unwrap();
844        let i686_windows = Platform::new(
845            "i686-pc-windows-msvc",
846            TargetFeatures::features(["sse", "sse2"].iter().copied()),
847        )
848        .unwrap();
849        let x86_64_windows =
850            Platform::new("x86_64-pc-windows-msvc", TargetFeatures::Unknown).unwrap();
851
852        let mut link_details = AHashMap::new();
853
854        use EnabledTernary::*;
855
856        // testcrate -> lazy_static 1.
857        LinkDetails::new(
858            package_id(METADATA_TARGETS1_TESTCRATE),
859            package_id(METADATA_TARGETS1_LAZY_STATIC_1),
860        )
861        .with_platform_status(
862            DependencyKind::Normal,
863            x86_64_linux.clone(),
864            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled)),
865        )
866        .with_platform_status(
867            DependencyKind::Normal,
868            i686_windows.clone(),
869            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled)),
870        )
871        .insert_into(&mut link_details);
872
873        // testcrate -> lazy_static 0.2.
874        // Included on not-Windows.
875        LinkDetails::new(
876            package_id(METADATA_TARGETS1_TESTCRATE),
877            package_id(METADATA_TARGETS1_LAZY_STATIC_02),
878        )
879        .with_platform_status(
880            DependencyKind::Normal,
881            x86_64_linux.clone(),
882            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled)),
883        )
884        .with_platform_status(
885            DependencyKind::Normal,
886            i686_windows.clone(),
887            PlatformResults::new((Disabled, Disabled), (Disabled, Disabled)),
888        )
889        .insert_into(&mut link_details);
890
891        // testcrate -> lazy_static 0.1.
892        // Included as a dev-dependency on Windows.
893        LinkDetails::new(
894            package_id(METADATA_TARGETS1_TESTCRATE),
895            package_id(METADATA_TARGETS1_LAZY_STATIC_01),
896        )
897        .with_platform_status(
898            DependencyKind::Development,
899            x86_64_linux.clone(),
900            PlatformResults::new((Disabled, Disabled), (Disabled, Disabled)),
901        )
902        .with_platform_status(
903            DependencyKind::Development,
904            i686_windows.clone(),
905            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled)),
906        )
907        .insert_into(&mut link_details);
908
909        // testcrate -> bytes.
910        // As a normal dependency, this is always built but default-features varies.
911        // As a build dependency, it is only present on Linux.
912        LinkDetails::new(
913            package_id(METADATA_TARGETS1_TESTCRATE),
914            package_id(METADATA_TARGETS1_BYTES),
915        )
916        .with_platform_status(
917            DependencyKind::Normal,
918            x86_64_linux.clone(),
919            PlatformResults::new((Enabled, Enabled), (Disabled, Disabled))
920                .with_feature_status("serde", (Enabled, Enabled))
921                .with_feature_status("std", (Disabled, Disabled)),
922        )
923        .with_platform_status(
924            DependencyKind::Normal,
925            i686_windows.clone(),
926            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled))
927                .with_feature_status("serde", (Enabled, Enabled))
928                .with_feature_status("std", (Disabled, Disabled)),
929        )
930        .with_features(DependencyKind::Normal, vec!["serde"])
931        .with_platform_status(
932            DependencyKind::Build,
933            x86_64_linux.clone(),
934            PlatformResults::new((Disabled, Enabled), (Disabled, Disabled))
935                .with_feature_status("serde", (Disabled, Disabled))
936                .with_feature_status("std", (Disabled, Enabled)),
937        )
938        .with_platform_status(
939            DependencyKind::Build,
940            i686_windows.clone(),
941            PlatformResults::new((Disabled, Disabled), (Disabled, Disabled))
942                .with_feature_status("serde", (Disabled, Disabled))
943                .with_feature_status("std", (Disabled, Disabled)),
944        )
945        .with_features(DependencyKind::Build, vec!["std"])
946        .insert_into(&mut link_details);
947
948        // testcrate -> dep-a.
949        // As a normal dependency, this is optionally built by default, but on not-Windows or on x86
950        // it is required.
951        // As a dev dependency, it is present if sse2 or atomics are turned on.
952        LinkDetails::new(
953            package_id(METADATA_TARGETS1_TESTCRATE),
954            package_id(METADATA_TARGETS1_DEP_A),
955        )
956        .with_platform_status(
957            DependencyKind::Normal,
958            x86_64_linux.clone(),
959            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled))
960                .with_feature_status("foo", (Enabled, Enabled))
961                .with_feature_status("bar", (Disabled, Disabled))
962                .with_feature_status("baz", (Disabled, Disabled))
963                .with_feature_status("quux", (Disabled, Disabled)),
964        )
965        .with_platform_status(
966            DependencyKind::Normal,
967            i686_windows.clone(),
968            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled))
969                .with_feature_status("foo", (Disabled, Disabled))
970                .with_feature_status("bar", (Enabled, Enabled))
971                .with_feature_status("baz", (Disabled, Disabled))
972                .with_feature_status("quux", (Disabled, Disabled)),
973        )
974        .with_platform_status(
975            DependencyKind::Normal,
976            x86_64_windows.clone(),
977            PlatformResults::new((Disabled, Enabled), (Disabled, Enabled))
978                .with_feature_status("foo", (Disabled, Disabled))
979                .with_feature_status("bar", (Disabled, Disabled))
980                .with_feature_status("baz", (Disabled, Disabled))
981                .with_feature_status("quux", (Disabled, Disabled)),
982        )
983        .with_platform_status(
984            DependencyKind::Development,
985            x86_64_linux.clone(),
986            // x86_64_linux uses TargetFeature::Unknown.
987            PlatformResults::new((Enabled, Enabled), (Unknown, Unknown))
988                .with_feature_status("foo", (Disabled, Disabled))
989                .with_feature_status("bar", (Disabled, Disabled))
990                .with_feature_status("baz", (Unknown, Unknown))
991                .with_feature_status("quux", (Enabled, Enabled)),
992        )
993        .with_platform_status(
994            DependencyKind::Development,
995            i686_windows.clone(),
996            // i686_windows turns on sse and sse2.
997            PlatformResults::new((Enabled, Enabled), (Disabled, Disabled))
998                .with_feature_status("foo", (Disabled, Disabled))
999                .with_feature_status("bar", (Disabled, Disabled))
1000                .with_feature_status("baz", (Enabled, Enabled))
1001                .with_feature_status("quux", (Enabled, Enabled)),
1002        )
1003        .with_platform_status(
1004            DependencyKind::Development,
1005            x86_64_windows.clone(),
1006            // x86_64_windows uses TargetFeatures::Unknown.
1007            PlatformResults::new((Unknown, Unknown), (Disabled, Disabled))
1008                .with_feature_status("foo", (Disabled, Disabled))
1009                .with_feature_status("bar", (Disabled, Disabled))
1010                .with_feature_status("baz", (Unknown, Unknown))
1011                .with_feature_status("quux", (Unknown, Unknown)),
1012        )
1013        .with_platform_status(
1014            DependencyKind::Build,
1015            x86_64_linux.clone(),
1016            // x86_64_linux uses TargetFeature::Unknown.
1017            PlatformResults::new((Unknown, Enabled), (Disabled, Enabled))
1018                .with_feature_status("foo", (Unknown, Unknown))
1019                .with_feature_status("bar", (Disabled, Unknown))
1020                .with_feature_status("baz", (Disabled, Disabled))
1021                .with_feature_status("quux", (Disabled, Disabled)),
1022        )
1023        .with_platform_status(
1024            DependencyKind::Build,
1025            i686_windows.clone(),
1026            // i686_windows turns on sse and sse2.
1027            PlatformResults::new((Enabled, Enabled), (Disabled, Enabled))
1028                .with_feature_status("foo", (Enabled, Enabled))
1029                .with_feature_status("bar", (Disabled, Disabled))
1030                .with_feature_status("baz", (Disabled, Disabled))
1031                .with_feature_status("quux", (Disabled, Disabled)),
1032        )
1033        .with_platform_status(
1034            DependencyKind::Build,
1035            x86_64_windows.clone(),
1036            // x86_64_windows uses TargetFeatures::Unknown.
1037            PlatformResults::new((Unknown, Unknown), (Disabled, Unknown))
1038                .with_feature_status("foo", (Unknown, Unknown))
1039                .with_feature_status("bar", (Disabled, Disabled))
1040                .with_feature_status("baz", (Disabled, Disabled))
1041                .with_feature_status("quux", (Disabled, Disabled)),
1042        )
1043        .insert_into(&mut link_details);
1044
1045        Self::new(details)
1046            .with_workspace_members(vec![("", METADATA_TARGETS1_TESTCRATE)])
1047            .with_link_details(link_details)
1048    }
1049
1050    pub(crate) fn metadata_build_targets1() -> Self {
1051        // [package]
1052        // name = "testcrate"
1053        // version = "0.1.0"
1054        // authors = ["Fake Author <fakeauthor@example.com>"]
1055        // edition = "2018"
1056        // build = "build.rs"
1057        //
1058        // [lib]
1059        // name = "bench1"
1060        // crate-type = ["cdylib", "bin"]
1061        //
1062        // [[bench]]
1063        // name = "bench1"
1064        // path = "src/main.rs"
1065        //
1066        // [[bench]]
1067        // name = "bench2"
1068        // path = "src/main2.rs"
1069        //
1070        // [[example]]
1071        // name = "example1"
1072        // path = "src/lib.rs"
1073        // crate-type = ["rlib", "dylib"]
1074
1075        let mut details = AHashMap::new();
1076
1077        static BIN_CDYLIB_TYPES: Lazy<Vec<String>> =
1078            Lazy::new(|| vec!["bin".into(), "cdylib".into()]);
1079        static DYLIB_RLIB_TYPES: Lazy<Vec<String>> =
1080            Lazy::new(|| vec!["dylib".into(), "rlib".into()]);
1081
1082        PackageDetails::new(
1083            METADATA_BUILD_TARGETS1_TESTCRATE,
1084            "testcrate",
1085            "0.1.0",
1086            vec![FAKE_AUTHOR],
1087            None,
1088            None,
1089        )
1090        .with_workspace_path("")
1091        .with_build_targets(vec![
1092            (
1093                BuildTargetId::Library,
1094                BuildTargetKind::LibraryOrExample(&BIN_CDYLIB_TYPES),
1095                "src/lib.rs",
1096            ),
1097            (
1098                BuildTargetId::BuildScript,
1099                BuildTargetKind::Binary,
1100                "build.rs",
1101            ),
1102            (
1103                BuildTargetId::Binary("testcrate"),
1104                BuildTargetKind::Binary,
1105                "src/main.rs",
1106            ),
1107            (
1108                BuildTargetId::Example("example1"),
1109                BuildTargetKind::LibraryOrExample(&DYLIB_RLIB_TYPES),
1110                "src/lib.rs",
1111            ),
1112            (
1113                BuildTargetId::Benchmark("bench1"),
1114                BuildTargetKind::Binary,
1115                "src/main.rs",
1116            ),
1117            (
1118                BuildTargetId::Benchmark("bench2"),
1119                BuildTargetKind::Binary,
1120                "src/main2.rs",
1121            ),
1122        ])
1123        .insert_into(&mut details);
1124
1125        Self::new(details)
1126    }
1127
1128    pub(crate) fn metadata_proc_macro1() -> Self {
1129        let mut details = AHashMap::new();
1130
1131        PackageDetails::new(
1132            METADATA_PROC_MACRO1_MACRO,
1133            "macro",
1134            "0.1.0",
1135            vec![FAKE_AUTHOR],
1136            None,
1137            None,
1138        )
1139        .with_workspace_path("macro")
1140        .with_reverse_deps(vec![
1141            ("macro", METADATA_PROC_MACRO1_NORMAL_USER),
1142            ("macro", METADATA_PROC_MACRO1_BUILD_USER),
1143            ("macro", METADATA_PROC_MACRO1_DEV_USER),
1144        ])
1145        .insert_into(&mut details);
1146
1147        Self::new(details)
1148    }
1149
1150    pub(crate) fn metadata_alternate_registries() -> Self {
1151        let details = AHashMap::new();
1152        Self::new(details)
1153    }
1154
1155    pub(crate) fn metadata_weak_namespaced_features() -> Self {
1156        let details = AHashMap::new();
1157        Self::new(details)
1158    }
1159
1160    pub(crate) fn metadata_libra() -> Self {
1161        let mut details = AHashMap::new();
1162
1163        PackageDetails::new(
1164            METADATA_LIBRA_E2E_TESTS,
1165            "language-e2e-tests",
1166            "0.1.0",
1167            vec!["Libra Association <opensource@libra.org>"],
1168            Some("Libra language e2e tests"),
1169            Some("Apache-2.0"),
1170        )
1171        .with_workspace_path("language/e2e-tests")
1172        .with_transitive_reverse_deps(vec![
1173            METADATA_LIBRA_E2E_TESTS,
1174            METADATA_LIBRA_COST_SYNTHESIS,
1175            METADATA_LIBRA_FUNCTIONAL_TESTS,
1176            METADATA_LIBRA_TEST_GENERATION,
1177            METADATA_LIBRA_LANGUAGE_BENCHMARKS,
1178            METADATA_LIBRA_TREE_HEAP,
1179        ])
1180        .insert_into(&mut details);
1181
1182        PackageDetails::new(
1183            METADATA_LIBRA_LAZY_STATIC,
1184            "lazy_static",
1185            "1.4.0",
1186            vec!["Marvin Löbel <loebel.marvin@gmail.com>"],
1187            Some("A macro for declaring lazily evaluated statics in Rust."),
1188            Some("MIT/Apache-2.0"),
1189        )
1190        .with_crates_io()
1191        .with_transitive_deps(vec![
1192            METADATA_LIBRA_LAZY_STATIC,
1193            "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
1194            // lazy_static also has doc-comment as a dev-dependency, but that isn't part of the
1195            // resolved graph so it won't appear here.
1196        ])
1197        .insert_into(&mut details);
1198
1199        #[rustfmt::skip]
1200        let workspace_members = vec![
1201            ("admission_control/admission-control-proto", "admission-control-proto 0.1.0 (path+file:///Users/fakeuser/local/libra/admission_control/admission-control-proto)"),
1202            ("admission_control/admission-control-service", METADATA_LIBRA_ADMISSION_CONTROL_SERVICE),
1203            ("benchmark", "benchmark 0.1.0 (path+file:///Users/fakeuser/local/libra/benchmark)"),
1204            ("client", "client 0.1.0 (path+file:///Users/fakeuser/local/libra/client)"),
1205            ("client/libra_wallet", "libra-wallet 0.1.0 (path+file:///Users/fakeuser/local/libra/client/libra_wallet)"),
1206            ("common/bounded-executor", "bounded-executor 0.1.0 (path+file:///Users/fakeuser/local/libra/common/bounded-executor)"),
1207            ("common/channel", "channel 0.1.0 (path+file:///Users/fakeuser/local/libra/common/channel)"),
1208            ("common/crash-handler", "crash-handler 0.1.0 (path+file:///Users/fakeuser/local/libra/common/crash-handler)"),
1209            ("common/datatest-stable", "datatest-stable 0.1.0 (path+file:///Users/fakeuser/local/libra/common/datatest-stable)"),
1210            ("common/debug-interface", "debug-interface 0.1.0 (path+file:///Users/fakeuser/local/libra/common/debug-interface)"),
1211            ("common/executable-helpers", "executable-helpers 0.1.0 (path+file:///Users/fakeuser/local/libra/common/executable-helpers)"),
1212            ("common/failure-ext", "libra-failure-ext 0.1.0 (path+file:///Users/fakeuser/local/libra/common/failure-ext)"),
1213            ("common/failure-ext/failure-macros", "libra-failure-macros 0.1.0 (path+file:///Users/fakeuser/local/libra/common/failure-ext/failure-macros)"),
1214            ("common/futures-semaphore", "futures-semaphore 0.1.0 (path+file:///Users/fakeuser/local/libra/common/futures-semaphore)"),
1215            ("common/grpc-helpers", "grpc-helpers 0.1.0 (path+file:///Users/fakeuser/local/libra/common/grpc-helpers)"),
1216            ("common/lcs", "libra-canonical-serialization 0.1.0 (path+file:///Users/fakeuser/local/libra/common/lcs)"),
1217            ("common/logger", "libra-logger 0.1.0 (path+file:///Users/fakeuser/local/libra/common/logger)"),
1218            ("common/metrics", "libra-metrics 0.1.0 (path+file:///Users/fakeuser/local/libra/common/metrics)"),
1219            ("common/nibble", "libra-nibble 0.1.0 (path+file:///Users/fakeuser/local/libra/common/nibble)"),
1220            ("common/proptest-helpers", "libra-proptest-helpers 0.1.0 (path+file:///Users/fakeuser/local/libra/common/proptest-helpers)"),
1221            ("common/prost-ext", "libra-prost-ext 0.1.0 (path+file:///Users/fakeuser/local/libra/common/prost-ext)"),
1222            ("common/tools", "libra-tools 0.1.0 (path+file:///Users/fakeuser/local/libra/common/tools)"),
1223            ("config", "libra-config 0.1.0 (path+file:///Users/fakeuser/local/libra/config)"),
1224            ("config/config-builder", "config-builder 0.1.0 (path+file:///Users/fakeuser/local/libra/config/config-builder)"),
1225            ("config/generate-keypair", "generate-keypair 0.1.0 (path+file:///Users/fakeuser/local/libra/config/generate-keypair)"),
1226            ("consensus", "consensus 0.1.0 (path+file:///Users/fakeuser/local/libra/consensus)"),
1227            ("consensus/consensus-types", "consensus-types 0.1.0 (path+file:///Users/fakeuser/local/libra/consensus/consensus-types)"),
1228            ("consensus/safety-rules", "safety-rules 0.1.0 (path+file:///Users/fakeuser/local/libra/consensus/safety-rules)"),
1229            ("crypto/crypto", "libra-crypto 0.1.0 (path+file:///Users/fakeuser/local/libra/crypto/crypto)"),
1230            ("crypto/crypto-derive", "libra-crypto-derive 0.1.0 (path+file:///Users/fakeuser/local/libra/crypto/crypto-derive)"),
1231            ("crypto/secret-service", "secret-service 0.1.0 (path+file:///Users/fakeuser/local/libra/crypto/secret-service)"),
1232            ("executor", "executor 0.1.0 (path+file:///Users/fakeuser/local/libra/executor)"),
1233            ("language/benchmarks", METADATA_LIBRA_LANGUAGE_BENCHMARKS),
1234            ("language/bytecode-verifier", "bytecode-verifier 0.1.0 (path+file:///Users/fakeuser/local/libra/language/bytecode-verifier)"),
1235            ("language/bytecode-verifier/bytecode_verifier_tests", "bytecode_verifier_tests 0.1.0 (path+file:///Users/fakeuser/local/libra/language/bytecode-verifier/bytecode_verifier_tests)"),
1236            ("language/bytecode-verifier/invalid-mutations", "invalid-mutations 0.1.0 (path+file:///Users/fakeuser/local/libra/language/bytecode-verifier/invalid-mutations)"),
1237            ("language/compiler", METADATA_LIBRA_COMPILER),
1238            ("language/compiler/bytecode-source-map", "bytecode-source-map 0.1.0 (path+file:///Users/fakeuser/local/libra/language/compiler/bytecode-source-map)"),
1239            ("language/compiler/ir-to-bytecode", "ir-to-bytecode 0.1.0 (path+file:///Users/fakeuser/local/libra/language/compiler/ir-to-bytecode)"),
1240            ("language/compiler/ir-to-bytecode/syntax", "ir-to-bytecode-syntax 0.1.0 (path+file:///Users/fakeuser/local/libra/language/compiler/ir-to-bytecode/syntax)"),
1241            ("language/e2e-tests", METADATA_LIBRA_E2E_TESTS),
1242            ("language/functional_tests", METADATA_LIBRA_FUNCTIONAL_TESTS),
1243            ("language/stackless-bytecode/bytecode-to-boogie", "bytecode-to-boogie 0.1.0 (path+file:///Users/fakeuser/local/libra/language/stackless-bytecode/bytecode-to-boogie)"),
1244            ("language/stackless-bytecode/generator", "stackless-bytecode-generator 0.1.0 (path+file:///Users/fakeuser/local/libra/language/stackless-bytecode/generator)"),
1245            ("language/stackless-bytecode/tree_heap", METADATA_LIBRA_TREE_HEAP),
1246            ("language/stdlib", METADATA_LIBRA_STDLIB),
1247            ("language/tools/cost-synthesis", METADATA_LIBRA_COST_SYNTHESIS),
1248            ("language/tools/test-generation", METADATA_LIBRA_TEST_GENERATION),
1249            ("language/transaction-builder", METADATA_LIBRA_TRANSACTION_BUILDER),
1250            ("language/vm", "vm 0.1.0 (path+file:///Users/fakeuser/local/libra/language/vm)"),
1251            ("language/vm/serializer_tests", "serializer_tests 0.1.0 (path+file:///Users/fakeuser/local/libra/language/vm/serializer_tests)"),
1252            ("language/vm/vm-genesis", "vm-genesis 0.1.0 (path+file:///Users/fakeuser/local/libra/language/vm/vm-genesis)"),
1253            ("language/vm/vm-runtime", "vm-runtime 0.1.0 (path+file:///Users/fakeuser/local/libra/language/vm/vm-runtime)"),
1254            ("language/vm/vm-runtime/vm-cache-map", "vm-cache-map 0.1.0 (path+file:///Users/fakeuser/local/libra/language/vm/vm-runtime/vm-cache-map)"),
1255            ("language/vm/vm-runtime/vm-runtime-types", "vm-runtime-types 0.1.0 (path+file:///Users/fakeuser/local/libra/language/vm/vm-runtime/vm-runtime-types)"),
1256            ("libra-node", "libra-node 0.1.0 (path+file:///Users/fakeuser/local/libra/libra-node)"),
1257            ("libra-swarm", "libra-swarm 0.1.0 (path+file:///Users/fakeuser/local/libra/libra-swarm)"),
1258            ("mempool", "libra-mempool 0.1.0 (path+file:///Users/fakeuser/local/libra/mempool)"),
1259            ("mempool/mempool-shared-proto", "libra-mempool-shared-proto 0.1.0 (path+file:///Users/fakeuser/local/libra/mempool/mempool-shared-proto)"),
1260            ("network", "network 0.1.0 (path+file:///Users/fakeuser/local/libra/network)"),
1261            ("network/memsocket", "memsocket 0.1.0 (path+file:///Users/fakeuser/local/libra/network/memsocket)"),
1262            ("network/netcore", "netcore 0.1.0 (path+file:///Users/fakeuser/local/libra/network/netcore)"),
1263            ("network/noise", "noise 0.1.0 (path+file:///Users/fakeuser/local/libra/network/noise)"),
1264            ("network/socket-bench-server", "socket-bench-server 0.1.0 (path+file:///Users/fakeuser/local/libra/network/socket-bench-server)"),
1265            ("state-synchronizer", "state-synchronizer 0.1.0 (path+file:///Users/fakeuser/local/libra/state-synchronizer)"),
1266            ("storage/accumulator", "accumulator 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/accumulator)"),
1267            ("storage/jellyfish-merkle", "jellyfish-merkle 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/jellyfish-merkle)"),
1268            ("storage/libradb", "libradb 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/libradb)"),
1269            ("storage/schemadb", "schemadb 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/schemadb)"),
1270            ("storage/scratchpad", "scratchpad 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/scratchpad)"),
1271            ("storage/state-view", "libra-state-view 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/state-view)"),
1272            ("storage/storage-client", "storage-client 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/storage-client)"),
1273            ("storage/storage-proto", "storage-proto 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/storage-proto)"),
1274            ("storage/storage-service", "storage-service 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/storage-service)"),
1275            ("testsuite", "testsuite 0.1.0 (path+file:///Users/fakeuser/local/libra/testsuite)"),
1276            ("testsuite/cluster-test", "cluster-test 0.1.0 (path+file:///Users/fakeuser/local/libra/testsuite/cluster-test)"),
1277            ("testsuite/libra-fuzzer", "libra-fuzzer 0.1.0 (path+file:///Users/fakeuser/local/libra/testsuite/libra-fuzzer)"),
1278            ("types", "libra-types 0.1.0 (path+file:///Users/fakeuser/local/libra/types)"),
1279            ("vm-validator", "vm-validator 0.1.0 (path+file:///Users/fakeuser/local/libra/vm-validator)"),
1280            ("x", "x 0.1.0 (path+file:///Users/fakeuser/local/libra/x)"),
1281        ];
1282
1283        Self::new(details)
1284            .with_workspace_members(workspace_members)
1285            .with_feature_graph_warnings(vec![
1286                // See https://github.com/alexcrichton/cfg-if/issues/22 for more.
1287                FeatureGraphWarning::MissingFeature {
1288                    stage: FeatureBuildStage::AddNamedFeatureEdges {
1289                        package_id: package_id(METADATA_LIBRA_BACKTRACE),
1290                        from_feature: "rustc-dep-of-std".to_string(),
1291                    },
1292                    package_id: package_id(METADATA_LIBRA_CFG_IF),
1293                    feature_name: "rustc-dep-of-std".to_string(),
1294                },
1295            ])
1296    }
1297
1298    pub(crate) fn metadata_libra_f0091a4() -> Self {
1299        let details = AHashMap::new();
1300
1301        Self::new(details).with_cycles(vec![vec![
1302            METADATA_LIBRA_FUNCTIONAL_HYPHEN_TESTS,
1303            METADATA_LIBRA_E2E_TESTS,
1304            METADATA_LIBRA_VM_GENESIS,
1305            METADATA_LIBRA_MOVE_LANG_STDLIB,
1306            METADATA_LIBRA_MOVE_LANG,
1307        ]])
1308    }
1309
1310    pub(crate) fn metadata_libra_9ffd93b() -> Self {
1311        let details = AHashMap::new();
1312
1313        Self::new(details).with_cycles(vec![
1314            vec![METADATA_LIBRA_EXECUTOR_UTILS, METADATA_LIBRA_EXECUTOR],
1315            vec![
1316                METADATA_LIBRA_FUNCTIONAL_HYPHEN_TESTS,
1317                METADATA_LIBRA_E2E_TESTS,
1318                METADATA_LIBRA_VM_GENESIS,
1319                METADATA_LIBRA_TRANSACTION_BUILDER,
1320                METADATA_LIBRA_LIBRA_VM,
1321                METADATA_LIBRA_MOVE_VM_RUNTIME,
1322                METADATA_LIBRA_COMPILER,
1323                METADATA_LIBRA_STDLIB,
1324                METADATA_LIBRA_MOVE_LANG,
1325            ],
1326        ])
1327    }
1328
1329    pub(crate) fn mnemos_b3b4da9() -> Self {
1330        let details = AHashMap::new();
1331
1332        Self::new(details)
1333    }
1334
1335    pub(crate) fn hyper_util_7afb1ed() -> Self {
1336        let details = AHashMap::new();
1337
1338        Self::new(details)
1339    }
1340
1341    pub(crate) fn metadata_guppy_78cb7e8() -> Self {
1342        let details = AHashMap::new();
1343
1344        Self::new(details)
1345    }
1346
1347    pub(crate) fn metadata_guppy_869476c() -> Self {
1348        let details = AHashMap::new();
1349
1350        Self::new(details)
1351    }
1352
1353    pub(crate) fn metadata_guppy_c9b4f76() -> Self {
1354        let details = AHashMap::new();
1355
1356        Self::new(details)
1357    }
1358
1359    pub(crate) fn metadata_guppy_44b62fa() -> Self {
1360        let details = AHashMap::new();
1361
1362        Self::new(details)
1363    }
1364}