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
346                    .assert_transitive_deps(graph, id, &format!("{msg} (transitive deps)"));
347            }
348            if self.details.has_transitive_reverse_deps(id) {
349                self.details.assert_transitive_reverse_deps(
350                    graph,
351                    id,
352                    &format!("{msg} (transitive reverse deps)"),
353                );
354            }
355
356            // Check for named features.
357            if self.details.has_named_features(id) {
358                self.details
359                    .assert_named_features(graph, id, &format!("{msg} (named features)"));
360            }
361        }
362
363        self.details.assert_link_details(graph, "link details");
364
365        // Tests for the feature graph.
366        self.details
367            .assert_feature_graph_warnings(graph, "feature graph warnings");
368    }
369
370    fn init_graph(&self) -> (&str, &PackageGraph) {
371        let (json, package_graph) = self.json_graph.get_or_init(|| {
372            let json = fs::read_to_string(&self.abs_path)
373                .unwrap_or_else(|err| panic!("reading file '{}' failed: {}", self.abs_path, err));
374            let graph = Self::parse_graph(&json);
375            (json, graph)
376        });
377        (json.as_str(), package_graph)
378    }
379
380    fn parse_graph(json: &str) -> PackageGraph {
381        let metadata =
382            CargoMetadata::parse_json(json).expect("parsing metadata JSON should succeed");
383        PackageGraph::from_metadata(metadata).expect("constructing package graph should succeed")
384    }
385}
386
387// Thanks to @porglezomp on Twitter for this simple normalization method.
388fn normalize_assuming_no_symlinks(p: impl AsRef<Utf8Path>) -> Utf8PathBuf {
389    let mut out = Utf8PathBuf::new();
390    for c in p.as_ref().components() {
391        match c {
392            Utf8Component::ParentDir => {
393                out.pop();
394            }
395            c => out.push(c),
396        }
397    }
398    out
399}
400
401// Some clones in here make the code more uniform overall.
402#[allow(clippy::redundant_clone)]
403impl FixtureDetails {
404    // Specific fixtures follow.
405
406    pub(crate) fn metadata1() -> Self {
407        let mut details = AHashMap::new();
408
409        PackageDetails::new(
410            METADATA1_TESTCRATE,
411            "testcrate",
412            "0.1.0",
413            vec![FAKE_AUTHOR],
414            None,
415            None,
416        )
417        .with_workspace_path("")
418        .with_build_targets(vec![(
419            BuildTargetId::Binary("testcrate"),
420            BuildTargetKind::Binary,
421            "src/main.rs",
422        )])
423        .with_deps(vec![("datatest", METADATA1_DATATEST)])
424        .with_reverse_deps(vec![])
425        .insert_into(&mut details);
426
427        #[rustfmt::skip]
428        let datatest_deps =
429            vec![
430                ("ctor", "ctor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)"),
431                ("datatest-derive", "datatest-derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)"),
432                ("regex", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)"),
433                ("region", "region 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)"),
434                ("serde", "serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)"),
435                ("serde_yaml", "serde_yaml 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)"),
436                ("version_check", "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)"),
437                // walkdir was replaced with [replace] (see metadata1.toml) -- ensure that the
438                // *replaced* version shows up here, not the regular one.
439                ("walkdir", "walkdir 2.2.9 (git+https://github.com/BurntSushi/walkdir?tag=2.2.9#7c7013259eb9db400b3e5c7bc60330ca08068826)"),
440                ("yaml-rust", "yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)")
441            ];
442
443        static LIB_TYPE: Lazy<Vec<String>> = Lazy::new(|| vec!["lib".into()]);
444
445        PackageDetails::new(
446            METADATA1_DATATEST,
447            "datatest",
448            "0.4.2",
449            vec!["Ivan Dubrov <ivan@commure.com>"],
450            Some("Data-driven tests in Rust\n"),
451            Some("MIT/Apache-2.0"),
452        )
453        .with_crates_io()
454        .with_build_targets(vec![
455            (
456                BuildTargetId::Library,
457                BuildTargetKind::LibraryOrExample(&LIB_TYPE),
458                "src/lib.rs",
459            ),
460            (
461                BuildTargetId::BuildScript,
462                BuildTargetKind::Binary,
463                "build.rs",
464            ),
465            (
466                BuildTargetId::Test("bench"),
467                BuildTargetKind::Binary,
468                "tests/bench.rs",
469            ),
470            (
471                BuildTargetId::Test("datatest"),
472                BuildTargetKind::Binary,
473                "tests/datatest.rs",
474            ),
475            (
476                BuildTargetId::Test("datatest_stable"),
477                BuildTargetKind::Binary,
478                "tests/datatest_stable.rs",
479            ),
480            (
481                BuildTargetId::Test("datatest_stable_unsafe"),
482                BuildTargetKind::Binary,
483                "tests/datatest_stable_unsafe.rs",
484            ),
485            (
486                BuildTargetId::Test("unicode"),
487                BuildTargetKind::Binary,
488                "tests/unicode.rs",
489            ),
490        ])
491        .with_deps(datatest_deps)
492        .with_reverse_deps(vec![("datatest", METADATA1_TESTCRATE)])
493        .insert_into(&mut details);
494
495        Self::new(details).with_workspace_members(vec![("", METADATA1_TESTCRATE)])
496    }
497
498    pub(crate) fn metadata2() -> Self {
499        let mut details = AHashMap::new();
500
501        PackageDetails::new(
502            METADATA2_TESTCRATE,
503            "testworkspace-crate",
504            "0.1.0",
505            vec![FAKE_AUTHOR],
506            None,
507            None,
508        )
509        .with_workspace_path("testcrate")
510        .with_deps(vec![
511            (
512                "datatest",
513                "datatest 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
514            ),
515            // There are three instances of walkdir in the dependencies -- ensure they all
516            // link up correctly.
517            ("walkdir", METADATA2_WALKDIR),
518            (
519                "walkdir-crates-io",
520                "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
521            ),
522            (
523                "walkdir-nuevo",
524                "walkdir 0.1.0 (path+file:///Users/fakeuser/local/walkdir)",
525            ),
526        ])
527        .with_reverse_deps(vec![])
528        .insert_into(&mut details);
529
530        PackageDetails::new(
531            METADATA2_WALKDIR,
532            "walkdir",
533            "2.2.9",
534            vec![FAKE_AUTHOR],
535            None,
536            None,
537        )
538        .with_workspace_path("walkdir")
539        .with_deps(vec![])
540        .with_reverse_deps(vec![("walkdir", METADATA2_TESTCRATE)])
541        .insert_into(&mut details);
542
543        // quote was replaced with [patch].
544        PackageDetails::new(
545            METADATA2_QUOTE,
546            "quote",
547            "1.0.2",
548            vec!["David Tolnay <dtolnay@gmail.com>"],
549            Some("Quasi-quoting macro quote!(...)"),
550            Some("MIT OR Apache-2.0"),
551        )
552        .with_local_path("../quote")
553        .with_deps(vec![(
554            "proc-macro2",
555            "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
556        )])
557        .with_reverse_deps(vec![
558            (
559                "quote",
560                "ctor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
561            ),
562            (
563                "quote",
564                "datatest-derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
565            ),
566            (
567                "quote",
568                "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
569            ),
570        ])
571        .with_named_features(vec!["default", "proc-macro"])
572        .insert_into(&mut details);
573
574        Self::new(details).with_workspace_members(vec![
575            ("testcrate", METADATA2_TESTCRATE),
576            ("walkdir", METADATA2_WALKDIR),
577        ])
578    }
579
580    pub(crate) fn metadata_builddep() -> Self {
581        let details = AHashMap::new();
582
583        Self::new(details)
584    }
585
586    pub(crate) fn metadata_dups() -> Self {
587        let mut details = AHashMap::new();
588
589        PackageDetails::new(
590            METADATA_DUPS_TESTCRATE,
591            "testcrate-dups",
592            "0.1.0",
593            vec![FAKE_AUTHOR],
594            None,
595            None,
596        )
597        .with_workspace_path("")
598        .with_deps(vec![
599            ("lazy_static", METADATA_DUPS_LAZY_STATIC_1),
600            ("lazy_static", METADATA_DUPS_LAZY_STATIC_02),
601            ("bytes-package", METADATA_DUPS_BYTES_03),
602            ("bytes-package", METADATA_DUPS_BYTES_05),
603        ])
604        .insert_into(&mut details);
605
606        Self::new(details).with_workspace_members(vec![("", METADATA_DUPS_TESTCRATE)])
607    }
608
609    pub(crate) fn metadata_cycle1() -> Self {
610        let mut details = AHashMap::new();
611
612        PackageDetails::new(
613            METADATA_CYCLE1_BASE,
614            "testcycles-base",
615            "0.1.0",
616            vec![FAKE_AUTHOR],
617            None,
618            None,
619        )
620        .with_workspace_path("")
621        .with_deps(vec![("testcycles-helper", METADATA_CYCLE1_HELPER)])
622        .with_transitive_deps(vec![METADATA_CYCLE1_BASE, METADATA_CYCLE1_HELPER])
623        .with_transitive_reverse_deps(vec![METADATA_CYCLE1_BASE, METADATA_CYCLE1_HELPER])
624        .insert_into(&mut details);
625
626        PackageDetails::new(
627            METADATA_CYCLE1_HELPER,
628            "testcycles-helper",
629            "0.1.0",
630            vec![FAKE_AUTHOR],
631            None,
632            None,
633        )
634        .with_local_path("../testcycles-helper")
635        .with_deps(vec![("testcycles-base", METADATA_CYCLE1_BASE)])
636        .with_transitive_deps(vec![METADATA_CYCLE1_BASE, METADATA_CYCLE1_HELPER])
637        .with_transitive_reverse_deps(vec![METADATA_CYCLE1_BASE, METADATA_CYCLE1_HELPER])
638        .insert_into(&mut details);
639
640        Self::new(details)
641            .with_workspace_members(vec![("", METADATA_CYCLE1_BASE)])
642            .with_cycles(vec![vec![METADATA_CYCLE1_HELPER, METADATA_CYCLE1_BASE]])
643    }
644
645    pub(crate) fn metadata_cycle2() -> Self {
646        // upper-a <-> upper-b
647        //                |
648        //                v
649        //             lower-a <-> lower-b
650        let mut details = AHashMap::new();
651
652        // upper-a
653        PackageDetails::new(
654            METADATA_CYCLE2_UPPER_A,
655            "upper-a",
656            "0.1.0",
657            vec![FAKE_AUTHOR],
658            None,
659            None,
660        )
661        .with_workspace_path("upper-a")
662        .with_deps(vec![("upper-b", METADATA_CYCLE2_UPPER_B)])
663        .with_reverse_deps(vec![("upper-a", METADATA_CYCLE2_UPPER_B)])
664        .with_transitive_deps(vec![
665            METADATA_CYCLE2_UPPER_A,
666            METADATA_CYCLE2_UPPER_B,
667            METADATA_CYCLE2_LOWER_A,
668            METADATA_CYCLE2_LOWER_B,
669        ])
670        .with_transitive_reverse_deps(vec![METADATA_CYCLE2_UPPER_A, METADATA_CYCLE2_UPPER_B])
671        .insert_into(&mut details);
672
673        // upper-b
674        PackageDetails::new(
675            METADATA_CYCLE2_UPPER_B,
676            "upper-b",
677            "0.1.0",
678            vec![FAKE_AUTHOR],
679            None,
680            None,
681        )
682        .with_workspace_path("upper-b")
683        .with_deps(vec![
684            ("upper-a", METADATA_CYCLE2_UPPER_A),
685            ("lower-a", METADATA_CYCLE2_LOWER_A),
686        ])
687        .with_reverse_deps(vec![("upper-b", METADATA_CYCLE2_UPPER_A)])
688        .with_transitive_deps(vec![
689            METADATA_CYCLE2_UPPER_A,
690            METADATA_CYCLE2_UPPER_B,
691            METADATA_CYCLE2_LOWER_A,
692            METADATA_CYCLE2_LOWER_B,
693        ])
694        .with_transitive_reverse_deps(vec![METADATA_CYCLE2_UPPER_A, METADATA_CYCLE2_UPPER_B])
695        .insert_into(&mut details);
696
697        // lower-a
698        PackageDetails::new(
699            METADATA_CYCLE2_LOWER_A,
700            "lower-a",
701            "0.1.0",
702            vec![FAKE_AUTHOR],
703            None,
704            None,
705        )
706        .with_workspace_path("lower-a")
707        .with_deps(vec![("lower-b", METADATA_CYCLE2_LOWER_B)])
708        .with_reverse_deps(vec![
709            ("lower-a", METADATA_CYCLE2_UPPER_B),
710            ("lower-a", METADATA_CYCLE2_LOWER_B),
711        ])
712        .with_transitive_deps(vec![METADATA_CYCLE2_LOWER_A, METADATA_CYCLE2_LOWER_B])
713        .with_transitive_reverse_deps(vec![
714            METADATA_CYCLE2_UPPER_A,
715            METADATA_CYCLE2_UPPER_B,
716            METADATA_CYCLE2_LOWER_A,
717            METADATA_CYCLE2_LOWER_B,
718        ])
719        .insert_into(&mut details);
720
721        // lower-b
722        PackageDetails::new(
723            METADATA_CYCLE2_LOWER_B,
724            "lower-b",
725            "0.1.0",
726            vec![FAKE_AUTHOR],
727            None,
728            None,
729        )
730        .with_workspace_path("lower-b")
731        .with_deps(vec![("lower-a", METADATA_CYCLE2_LOWER_A)])
732        .with_reverse_deps(vec![("lower-b", METADATA_CYCLE2_LOWER_A)])
733        .with_transitive_deps(vec![METADATA_CYCLE2_LOWER_A, METADATA_CYCLE2_LOWER_B])
734        .with_transitive_reverse_deps(vec![
735            METADATA_CYCLE2_UPPER_A,
736            METADATA_CYCLE2_UPPER_B,
737            METADATA_CYCLE2_LOWER_A,
738            METADATA_CYCLE2_LOWER_B,
739        ])
740        .insert_into(&mut details);
741
742        Self::new(details)
743            .with_workspace_members(vec![
744                ("upper-a", METADATA_CYCLE2_UPPER_A),
745                ("upper-b", METADATA_CYCLE2_UPPER_B),
746                ("lower-a", METADATA_CYCLE2_LOWER_A),
747                ("lower-b", METADATA_CYCLE2_LOWER_B),
748            ])
749            .with_cycles(vec![
750                // upper-b dev-depends on upper-a, and upper-a normal-depends on upper-b.
751                vec![METADATA_CYCLE2_UPPER_A, METADATA_CYCLE2_UPPER_B],
752                // lower-b dev-depends on lower-a, and lower-a normal-depends on lower-b.
753                vec![METADATA_CYCLE2_LOWER_A, METADATA_CYCLE2_LOWER_B],
754            ])
755    }
756
757    pub(crate) fn metadata_cycle_features() -> Self {
758        let details = AHashMap::new();
759
760        Self::new(details)
761            .with_workspace_members(vec![
762                ("testcycles-base", METADATA_CYCLE_FEATURES_BASE),
763                ("testcycles-helper", METADATA_CYCLE_FEATURES_HELPER),
764            ])
765            .with_cycles(vec![vec![
766                METADATA_CYCLE_FEATURES_HELPER,
767                METADATA_CYCLE_FEATURES_BASE,
768            ]])
769    }
770
771    pub(crate) fn metadata_targets1() -> Self {
772        // In the testcrate:
773        //
774        // ```
775        // [dependencies]
776        // lazy_static = "1"
777        // bytes = { version = "0.5", default-features = false, features = ["serde"] }
778        // dep-a = { path = "../dep-a", optional = true }
779        //
780        // [target.'cfg(not(windows))'.dependencies]
781        // lazy_static = "0.2"
782        // dep-a = { path = "../dep-a", features = ["foo"] }
783        //
784        // [target.'cfg(windows)'.dev-dependencies]
785        // lazy_static = "0.1"
786        //
787        // [target.'cfg(target_arch = "x86")'.dependencies]
788        // bytes = { version = "=0.5.3", optional = false }
789        // dep-a = { path = "../dep-a", features = ["bar"] }
790        //
791        // [target.x86_64-unknown-linux-gnu.build-dependencies]
792        // bytes = { version = "0.5.2", optional = true, default-features = false, features = ["std"] }
793        //
794        // # Platform-specific dev-dependencies.
795        //
796        // [target.'cfg(any(target_feature = "sse2", target_feature = "atomics"))'.dev-dependencies]
797        // dep-a = { path = "../dep-a", default-features = false, features = ["baz"] }
798        //
799        // [target.'cfg(all(unix, not(target_feature = "sse")))'.dev-dependencies]
800        // dep-a = { path = "../dep-a" }
801        //
802        // [target.'cfg(any(unix, target_feature = "sse"))'.dev-dependencies]
803        // dep-a = { path = "../dep-a", default-features = false, features = ["quux"] }
804        //
805        // # Platform-specific build dependencies.
806        //
807        // [target.'cfg(target_feature = "sse")'.build-dependencies]
808        // dep-a = { path = "../dep-a", default-features = false, features = ["foo"] }
809        //
810        // # any -- evaluates to true for unix.
811        // [target.'cfg(any(unix, target_feature = "sse"))'.build-dependencies]
812        // dep-a = { path = "../dep-a", optional = true, default-features = true }
813        //
814        // # all -- evaluates to unknown on unixes if the target features are unknown.
815        // # Evaluates to false on Windows whether target features are known or not.
816        // [target.'cfg(all(unix, target_feature = "sse"))'.build-dependencies]
817        // dep-a = { path = "../dep-a", optional = true, default-features = false, features = ["bar"] }
818        // ```
819        let mut details = AHashMap::new();
820
821        PackageDetails::new(
822            METADATA_TARGETS1_TESTCRATE,
823            "testcrate-targets",
824            "0.1.0",
825            vec![FAKE_AUTHOR],
826            None,
827            None,
828        )
829        .with_workspace_path("")
830        .with_deps(vec![
831            ("lazy_static", METADATA_TARGETS1_LAZY_STATIC_1),
832            ("lazy_static", METADATA_TARGETS1_LAZY_STATIC_02),
833            ("lazy_static", METADATA_TARGETS1_LAZY_STATIC_01),
834            ("bytes", METADATA_TARGETS1_BYTES),
835            ("dep-a", METADATA_TARGETS1_DEP_A),
836        ])
837        .insert_into(&mut details);
838
839        let x86_64_linux =
840            Platform::new("x86_64-unknown-linux-gnu", TargetFeatures::Unknown).unwrap();
841        let i686_windows = Platform::new(
842            "i686-pc-windows-msvc",
843            TargetFeatures::features(["sse", "sse2"].iter().copied()),
844        )
845        .unwrap();
846        let x86_64_windows =
847            Platform::new("x86_64-pc-windows-msvc", TargetFeatures::Unknown).unwrap();
848
849        let mut link_details = AHashMap::new();
850
851        use EnabledTernary::*;
852
853        // testcrate -> lazy_static 1.
854        LinkDetails::new(
855            package_id(METADATA_TARGETS1_TESTCRATE),
856            package_id(METADATA_TARGETS1_LAZY_STATIC_1),
857        )
858        .with_platform_status(
859            DependencyKind::Normal,
860            x86_64_linux.clone(),
861            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled)),
862        )
863        .with_platform_status(
864            DependencyKind::Normal,
865            i686_windows.clone(),
866            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled)),
867        )
868        .insert_into(&mut link_details);
869
870        // testcrate -> lazy_static 0.2.
871        // Included on not-Windows.
872        LinkDetails::new(
873            package_id(METADATA_TARGETS1_TESTCRATE),
874            package_id(METADATA_TARGETS1_LAZY_STATIC_02),
875        )
876        .with_platform_status(
877            DependencyKind::Normal,
878            x86_64_linux.clone(),
879            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled)),
880        )
881        .with_platform_status(
882            DependencyKind::Normal,
883            i686_windows.clone(),
884            PlatformResults::new((Disabled, Disabled), (Disabled, Disabled)),
885        )
886        .insert_into(&mut link_details);
887
888        // testcrate -> lazy_static 0.1.
889        // Included as a dev-dependency on Windows.
890        LinkDetails::new(
891            package_id(METADATA_TARGETS1_TESTCRATE),
892            package_id(METADATA_TARGETS1_LAZY_STATIC_01),
893        )
894        .with_platform_status(
895            DependencyKind::Development,
896            x86_64_linux.clone(),
897            PlatformResults::new((Disabled, Disabled), (Disabled, Disabled)),
898        )
899        .with_platform_status(
900            DependencyKind::Development,
901            i686_windows.clone(),
902            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled)),
903        )
904        .insert_into(&mut link_details);
905
906        // testcrate -> bytes.
907        // As a normal dependency, this is always built but default-features varies.
908        // As a build dependency, it is only present on Linux.
909        LinkDetails::new(
910            package_id(METADATA_TARGETS1_TESTCRATE),
911            package_id(METADATA_TARGETS1_BYTES),
912        )
913        .with_platform_status(
914            DependencyKind::Normal,
915            x86_64_linux.clone(),
916            PlatformResults::new((Enabled, Enabled), (Disabled, Disabled))
917                .with_feature_status("serde", (Enabled, Enabled))
918                .with_feature_status("std", (Disabled, Disabled)),
919        )
920        .with_platform_status(
921            DependencyKind::Normal,
922            i686_windows.clone(),
923            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled))
924                .with_feature_status("serde", (Enabled, Enabled))
925                .with_feature_status("std", (Disabled, Disabled)),
926        )
927        .with_features(DependencyKind::Normal, vec!["serde"])
928        .with_platform_status(
929            DependencyKind::Build,
930            x86_64_linux.clone(),
931            PlatformResults::new((Disabled, Enabled), (Disabled, Disabled))
932                .with_feature_status("serde", (Disabled, Disabled))
933                .with_feature_status("std", (Disabled, Enabled)),
934        )
935        .with_platform_status(
936            DependencyKind::Build,
937            i686_windows.clone(),
938            PlatformResults::new((Disabled, Disabled), (Disabled, Disabled))
939                .with_feature_status("serde", (Disabled, Disabled))
940                .with_feature_status("std", (Disabled, Disabled)),
941        )
942        .with_features(DependencyKind::Build, vec!["std"])
943        .insert_into(&mut link_details);
944
945        // testcrate -> dep-a.
946        // As a normal dependency, this is optionally built by default, but on not-Windows or on x86
947        // it is required.
948        // As a dev dependency, it is present if sse2 or atomics are turned on.
949        LinkDetails::new(
950            package_id(METADATA_TARGETS1_TESTCRATE),
951            package_id(METADATA_TARGETS1_DEP_A),
952        )
953        .with_platform_status(
954            DependencyKind::Normal,
955            x86_64_linux.clone(),
956            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled))
957                .with_feature_status("foo", (Enabled, Enabled))
958                .with_feature_status("bar", (Disabled, Disabled))
959                .with_feature_status("baz", (Disabled, Disabled))
960                .with_feature_status("quux", (Disabled, Disabled)),
961        )
962        .with_platform_status(
963            DependencyKind::Normal,
964            i686_windows.clone(),
965            PlatformResults::new((Enabled, Enabled), (Enabled, Enabled))
966                .with_feature_status("foo", (Disabled, Disabled))
967                .with_feature_status("bar", (Enabled, Enabled))
968                .with_feature_status("baz", (Disabled, Disabled))
969                .with_feature_status("quux", (Disabled, Disabled)),
970        )
971        .with_platform_status(
972            DependencyKind::Normal,
973            x86_64_windows.clone(),
974            PlatformResults::new((Disabled, Enabled), (Disabled, Enabled))
975                .with_feature_status("foo", (Disabled, Disabled))
976                .with_feature_status("bar", (Disabled, Disabled))
977                .with_feature_status("baz", (Disabled, Disabled))
978                .with_feature_status("quux", (Disabled, Disabled)),
979        )
980        .with_platform_status(
981            DependencyKind::Development,
982            x86_64_linux.clone(),
983            // x86_64_linux uses TargetFeature::Unknown.
984            PlatformResults::new((Enabled, Enabled), (Unknown, Unknown))
985                .with_feature_status("foo", (Disabled, Disabled))
986                .with_feature_status("bar", (Disabled, Disabled))
987                .with_feature_status("baz", (Unknown, Unknown))
988                .with_feature_status("quux", (Enabled, Enabled)),
989        )
990        .with_platform_status(
991            DependencyKind::Development,
992            i686_windows.clone(),
993            // i686_windows turns on sse and sse2.
994            PlatformResults::new((Enabled, Enabled), (Disabled, Disabled))
995                .with_feature_status("foo", (Disabled, Disabled))
996                .with_feature_status("bar", (Disabled, Disabled))
997                .with_feature_status("baz", (Enabled, Enabled))
998                .with_feature_status("quux", (Enabled, Enabled)),
999        )
1000        .with_platform_status(
1001            DependencyKind::Development,
1002            x86_64_windows.clone(),
1003            // x86_64_windows uses TargetFeatures::Unknown.
1004            PlatformResults::new((Unknown, Unknown), (Disabled, Disabled))
1005                .with_feature_status("foo", (Disabled, Disabled))
1006                .with_feature_status("bar", (Disabled, Disabled))
1007                .with_feature_status("baz", (Unknown, Unknown))
1008                .with_feature_status("quux", (Unknown, Unknown)),
1009        )
1010        .with_platform_status(
1011            DependencyKind::Build,
1012            x86_64_linux.clone(),
1013            // x86_64_linux uses TargetFeature::Unknown.
1014            PlatformResults::new((Unknown, Enabled), (Disabled, Enabled))
1015                .with_feature_status("foo", (Unknown, Unknown))
1016                .with_feature_status("bar", (Disabled, Unknown))
1017                .with_feature_status("baz", (Disabled, Disabled))
1018                .with_feature_status("quux", (Disabled, Disabled)),
1019        )
1020        .with_platform_status(
1021            DependencyKind::Build,
1022            i686_windows.clone(),
1023            // i686_windows turns on sse and sse2.
1024            PlatformResults::new((Enabled, Enabled), (Disabled, Enabled))
1025                .with_feature_status("foo", (Enabled, Enabled))
1026                .with_feature_status("bar", (Disabled, Disabled))
1027                .with_feature_status("baz", (Disabled, Disabled))
1028                .with_feature_status("quux", (Disabled, Disabled)),
1029        )
1030        .with_platform_status(
1031            DependencyKind::Build,
1032            x86_64_windows.clone(),
1033            // x86_64_windows uses TargetFeatures::Unknown.
1034            PlatformResults::new((Unknown, Unknown), (Disabled, Unknown))
1035                .with_feature_status("foo", (Unknown, Unknown))
1036                .with_feature_status("bar", (Disabled, Disabled))
1037                .with_feature_status("baz", (Disabled, Disabled))
1038                .with_feature_status("quux", (Disabled, Disabled)),
1039        )
1040        .insert_into(&mut link_details);
1041
1042        Self::new(details)
1043            .with_workspace_members(vec![("", METADATA_TARGETS1_TESTCRATE)])
1044            .with_link_details(link_details)
1045    }
1046
1047    pub(crate) fn metadata_build_targets1() -> Self {
1048        // [package]
1049        // name = "testcrate"
1050        // version = "0.1.0"
1051        // authors = ["Fake Author <fakeauthor@example.com>"]
1052        // edition = "2018"
1053        // build = "build.rs"
1054        //
1055        // [lib]
1056        // name = "bench1"
1057        // crate-type = ["cdylib", "bin"]
1058        //
1059        // [[bench]]
1060        // name = "bench1"
1061        // path = "src/main.rs"
1062        //
1063        // [[bench]]
1064        // name = "bench2"
1065        // path = "src/main2.rs"
1066        //
1067        // [[example]]
1068        // name = "example1"
1069        // path = "src/lib.rs"
1070        // crate-type = ["rlib", "dylib"]
1071
1072        let mut details = AHashMap::new();
1073
1074        static BIN_CDYLIB_TYPES: Lazy<Vec<String>> =
1075            Lazy::new(|| vec!["bin".into(), "cdylib".into()]);
1076        static DYLIB_RLIB_TYPES: Lazy<Vec<String>> =
1077            Lazy::new(|| vec!["dylib".into(), "rlib".into()]);
1078
1079        PackageDetails::new(
1080            METADATA_BUILD_TARGETS1_TESTCRATE,
1081            "testcrate",
1082            "0.1.0",
1083            vec![FAKE_AUTHOR],
1084            None,
1085            None,
1086        )
1087        .with_workspace_path("")
1088        .with_build_targets(vec![
1089            (
1090                BuildTargetId::Library,
1091                BuildTargetKind::LibraryOrExample(&BIN_CDYLIB_TYPES),
1092                "src/lib.rs",
1093            ),
1094            (
1095                BuildTargetId::BuildScript,
1096                BuildTargetKind::Binary,
1097                "build.rs",
1098            ),
1099            (
1100                BuildTargetId::Binary("testcrate"),
1101                BuildTargetKind::Binary,
1102                "src/main.rs",
1103            ),
1104            (
1105                BuildTargetId::Example("example1"),
1106                BuildTargetKind::LibraryOrExample(&DYLIB_RLIB_TYPES),
1107                "src/lib.rs",
1108            ),
1109            (
1110                BuildTargetId::Benchmark("bench1"),
1111                BuildTargetKind::Binary,
1112                "src/main.rs",
1113            ),
1114            (
1115                BuildTargetId::Benchmark("bench2"),
1116                BuildTargetKind::Binary,
1117                "src/main2.rs",
1118            ),
1119        ])
1120        .insert_into(&mut details);
1121
1122        Self::new(details)
1123    }
1124
1125    pub(crate) fn metadata_proc_macro1() -> Self {
1126        let mut details = AHashMap::new();
1127
1128        PackageDetails::new(
1129            METADATA_PROC_MACRO1_MACRO,
1130            "macro",
1131            "0.1.0",
1132            vec![FAKE_AUTHOR],
1133            None,
1134            None,
1135        )
1136        .with_workspace_path("macro")
1137        .with_reverse_deps(vec![
1138            ("macro", METADATA_PROC_MACRO1_NORMAL_USER),
1139            ("macro", METADATA_PROC_MACRO1_BUILD_USER),
1140            ("macro", METADATA_PROC_MACRO1_DEV_USER),
1141        ])
1142        .insert_into(&mut details);
1143
1144        Self::new(details)
1145    }
1146
1147    pub(crate) fn metadata_alternate_registries() -> Self {
1148        let details = AHashMap::new();
1149        Self::new(details)
1150    }
1151
1152    pub(crate) fn metadata_weak_namespaced_features() -> Self {
1153        let details = AHashMap::new();
1154        Self::new(details)
1155    }
1156
1157    pub(crate) fn metadata_libra() -> Self {
1158        let mut details = AHashMap::new();
1159
1160        PackageDetails::new(
1161            METADATA_LIBRA_E2E_TESTS,
1162            "language-e2e-tests",
1163            "0.1.0",
1164            vec!["Libra Association <opensource@libra.org>"],
1165            Some("Libra language e2e tests"),
1166            Some("Apache-2.0"),
1167        )
1168        .with_workspace_path("language/e2e-tests")
1169        .with_transitive_reverse_deps(vec![
1170            METADATA_LIBRA_E2E_TESTS,
1171            METADATA_LIBRA_COST_SYNTHESIS,
1172            METADATA_LIBRA_FUNCTIONAL_TESTS,
1173            METADATA_LIBRA_TEST_GENERATION,
1174            METADATA_LIBRA_LANGUAGE_BENCHMARKS,
1175            METADATA_LIBRA_TREE_HEAP,
1176        ])
1177        .insert_into(&mut details);
1178
1179        PackageDetails::new(
1180            METADATA_LIBRA_LAZY_STATIC,
1181            "lazy_static",
1182            "1.4.0",
1183            vec!["Marvin Löbel <loebel.marvin@gmail.com>"],
1184            Some("A macro for declaring lazily evaluated statics in Rust."),
1185            Some("MIT/Apache-2.0"),
1186        )
1187        .with_crates_io()
1188        .with_transitive_deps(vec![
1189            METADATA_LIBRA_LAZY_STATIC,
1190            "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
1191            // lazy_static also has doc-comment as a dev-dependency, but that isn't part of the
1192            // resolved graph so it won't appear here.
1193        ])
1194        .insert_into(&mut details);
1195
1196        #[rustfmt::skip]
1197        let workspace_members = vec![
1198            ("admission_control/admission-control-proto", "admission-control-proto 0.1.0 (path+file:///Users/fakeuser/local/libra/admission_control/admission-control-proto)"),
1199            ("admission_control/admission-control-service", METADATA_LIBRA_ADMISSION_CONTROL_SERVICE),
1200            ("benchmark", "benchmark 0.1.0 (path+file:///Users/fakeuser/local/libra/benchmark)"),
1201            ("client", "client 0.1.0 (path+file:///Users/fakeuser/local/libra/client)"),
1202            ("client/libra_wallet", "libra-wallet 0.1.0 (path+file:///Users/fakeuser/local/libra/client/libra_wallet)"),
1203            ("common/bounded-executor", "bounded-executor 0.1.0 (path+file:///Users/fakeuser/local/libra/common/bounded-executor)"),
1204            ("common/channel", "channel 0.1.0 (path+file:///Users/fakeuser/local/libra/common/channel)"),
1205            ("common/crash-handler", "crash-handler 0.1.0 (path+file:///Users/fakeuser/local/libra/common/crash-handler)"),
1206            ("common/datatest-stable", "datatest-stable 0.1.0 (path+file:///Users/fakeuser/local/libra/common/datatest-stable)"),
1207            ("common/debug-interface", "debug-interface 0.1.0 (path+file:///Users/fakeuser/local/libra/common/debug-interface)"),
1208            ("common/executable-helpers", "executable-helpers 0.1.0 (path+file:///Users/fakeuser/local/libra/common/executable-helpers)"),
1209            ("common/failure-ext", "libra-failure-ext 0.1.0 (path+file:///Users/fakeuser/local/libra/common/failure-ext)"),
1210            ("common/failure-ext/failure-macros", "libra-failure-macros 0.1.0 (path+file:///Users/fakeuser/local/libra/common/failure-ext/failure-macros)"),
1211            ("common/futures-semaphore", "futures-semaphore 0.1.0 (path+file:///Users/fakeuser/local/libra/common/futures-semaphore)"),
1212            ("common/grpc-helpers", "grpc-helpers 0.1.0 (path+file:///Users/fakeuser/local/libra/common/grpc-helpers)"),
1213            ("common/lcs", "libra-canonical-serialization 0.1.0 (path+file:///Users/fakeuser/local/libra/common/lcs)"),
1214            ("common/logger", "libra-logger 0.1.0 (path+file:///Users/fakeuser/local/libra/common/logger)"),
1215            ("common/metrics", "libra-metrics 0.1.0 (path+file:///Users/fakeuser/local/libra/common/metrics)"),
1216            ("common/nibble", "libra-nibble 0.1.0 (path+file:///Users/fakeuser/local/libra/common/nibble)"),
1217            ("common/proptest-helpers", "libra-proptest-helpers 0.1.0 (path+file:///Users/fakeuser/local/libra/common/proptest-helpers)"),
1218            ("common/prost-ext", "libra-prost-ext 0.1.0 (path+file:///Users/fakeuser/local/libra/common/prost-ext)"),
1219            ("common/tools", "libra-tools 0.1.0 (path+file:///Users/fakeuser/local/libra/common/tools)"),
1220            ("config", "libra-config 0.1.0 (path+file:///Users/fakeuser/local/libra/config)"),
1221            ("config/config-builder", "config-builder 0.1.0 (path+file:///Users/fakeuser/local/libra/config/config-builder)"),
1222            ("config/generate-keypair", "generate-keypair 0.1.0 (path+file:///Users/fakeuser/local/libra/config/generate-keypair)"),
1223            ("consensus", "consensus 0.1.0 (path+file:///Users/fakeuser/local/libra/consensus)"),
1224            ("consensus/consensus-types", "consensus-types 0.1.0 (path+file:///Users/fakeuser/local/libra/consensus/consensus-types)"),
1225            ("consensus/safety-rules", "safety-rules 0.1.0 (path+file:///Users/fakeuser/local/libra/consensus/safety-rules)"),
1226            ("crypto/crypto", "libra-crypto 0.1.0 (path+file:///Users/fakeuser/local/libra/crypto/crypto)"),
1227            ("crypto/crypto-derive", "libra-crypto-derive 0.1.0 (path+file:///Users/fakeuser/local/libra/crypto/crypto-derive)"),
1228            ("crypto/secret-service", "secret-service 0.1.0 (path+file:///Users/fakeuser/local/libra/crypto/secret-service)"),
1229            ("executor", "executor 0.1.0 (path+file:///Users/fakeuser/local/libra/executor)"),
1230            ("language/benchmarks", METADATA_LIBRA_LANGUAGE_BENCHMARKS),
1231            ("language/bytecode-verifier", "bytecode-verifier 0.1.0 (path+file:///Users/fakeuser/local/libra/language/bytecode-verifier)"),
1232            ("language/bytecode-verifier/bytecode_verifier_tests", "bytecode_verifier_tests 0.1.0 (path+file:///Users/fakeuser/local/libra/language/bytecode-verifier/bytecode_verifier_tests)"),
1233            ("language/bytecode-verifier/invalid-mutations", "invalid-mutations 0.1.0 (path+file:///Users/fakeuser/local/libra/language/bytecode-verifier/invalid-mutations)"),
1234            ("language/compiler", METADATA_LIBRA_COMPILER),
1235            ("language/compiler/bytecode-source-map", "bytecode-source-map 0.1.0 (path+file:///Users/fakeuser/local/libra/language/compiler/bytecode-source-map)"),
1236            ("language/compiler/ir-to-bytecode", "ir-to-bytecode 0.1.0 (path+file:///Users/fakeuser/local/libra/language/compiler/ir-to-bytecode)"),
1237            ("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)"),
1238            ("language/e2e-tests", METADATA_LIBRA_E2E_TESTS),
1239            ("language/functional_tests", METADATA_LIBRA_FUNCTIONAL_TESTS),
1240            ("language/stackless-bytecode/bytecode-to-boogie", "bytecode-to-boogie 0.1.0 (path+file:///Users/fakeuser/local/libra/language/stackless-bytecode/bytecode-to-boogie)"),
1241            ("language/stackless-bytecode/generator", "stackless-bytecode-generator 0.1.0 (path+file:///Users/fakeuser/local/libra/language/stackless-bytecode/generator)"),
1242            ("language/stackless-bytecode/tree_heap", METADATA_LIBRA_TREE_HEAP),
1243            ("language/stdlib", METADATA_LIBRA_STDLIB),
1244            ("language/tools/cost-synthesis", METADATA_LIBRA_COST_SYNTHESIS),
1245            ("language/tools/test-generation", METADATA_LIBRA_TEST_GENERATION),
1246            ("language/transaction-builder", METADATA_LIBRA_TRANSACTION_BUILDER),
1247            ("language/vm", "vm 0.1.0 (path+file:///Users/fakeuser/local/libra/language/vm)"),
1248            ("language/vm/serializer_tests", "serializer_tests 0.1.0 (path+file:///Users/fakeuser/local/libra/language/vm/serializer_tests)"),
1249            ("language/vm/vm-genesis", "vm-genesis 0.1.0 (path+file:///Users/fakeuser/local/libra/language/vm/vm-genesis)"),
1250            ("language/vm/vm-runtime", "vm-runtime 0.1.0 (path+file:///Users/fakeuser/local/libra/language/vm/vm-runtime)"),
1251            ("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)"),
1252            ("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)"),
1253            ("libra-node", "libra-node 0.1.0 (path+file:///Users/fakeuser/local/libra/libra-node)"),
1254            ("libra-swarm", "libra-swarm 0.1.0 (path+file:///Users/fakeuser/local/libra/libra-swarm)"),
1255            ("mempool", "libra-mempool 0.1.0 (path+file:///Users/fakeuser/local/libra/mempool)"),
1256            ("mempool/mempool-shared-proto", "libra-mempool-shared-proto 0.1.0 (path+file:///Users/fakeuser/local/libra/mempool/mempool-shared-proto)"),
1257            ("network", "network 0.1.0 (path+file:///Users/fakeuser/local/libra/network)"),
1258            ("network/memsocket", "memsocket 0.1.0 (path+file:///Users/fakeuser/local/libra/network/memsocket)"),
1259            ("network/netcore", "netcore 0.1.0 (path+file:///Users/fakeuser/local/libra/network/netcore)"),
1260            ("network/noise", "noise 0.1.0 (path+file:///Users/fakeuser/local/libra/network/noise)"),
1261            ("network/socket-bench-server", "socket-bench-server 0.1.0 (path+file:///Users/fakeuser/local/libra/network/socket-bench-server)"),
1262            ("state-synchronizer", "state-synchronizer 0.1.0 (path+file:///Users/fakeuser/local/libra/state-synchronizer)"),
1263            ("storage/accumulator", "accumulator 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/accumulator)"),
1264            ("storage/jellyfish-merkle", "jellyfish-merkle 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/jellyfish-merkle)"),
1265            ("storage/libradb", "libradb 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/libradb)"),
1266            ("storage/schemadb", "schemadb 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/schemadb)"),
1267            ("storage/scratchpad", "scratchpad 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/scratchpad)"),
1268            ("storage/state-view", "libra-state-view 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/state-view)"),
1269            ("storage/storage-client", "storage-client 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/storage-client)"),
1270            ("storage/storage-proto", "storage-proto 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/storage-proto)"),
1271            ("storage/storage-service", "storage-service 0.1.0 (path+file:///Users/fakeuser/local/libra/storage/storage-service)"),
1272            ("testsuite", "testsuite 0.1.0 (path+file:///Users/fakeuser/local/libra/testsuite)"),
1273            ("testsuite/cluster-test", "cluster-test 0.1.0 (path+file:///Users/fakeuser/local/libra/testsuite/cluster-test)"),
1274            ("testsuite/libra-fuzzer", "libra-fuzzer 0.1.0 (path+file:///Users/fakeuser/local/libra/testsuite/libra-fuzzer)"),
1275            ("types", "libra-types 0.1.0 (path+file:///Users/fakeuser/local/libra/types)"),
1276            ("vm-validator", "vm-validator 0.1.0 (path+file:///Users/fakeuser/local/libra/vm-validator)"),
1277            ("x", "x 0.1.0 (path+file:///Users/fakeuser/local/libra/x)"),
1278        ];
1279
1280        Self::new(details)
1281            .with_workspace_members(workspace_members)
1282            .with_feature_graph_warnings(vec![
1283                // See https://github.com/alexcrichton/cfg-if/issues/22 for more.
1284                FeatureGraphWarning::MissingFeature {
1285                    stage: FeatureBuildStage::AddNamedFeatureEdges {
1286                        package_id: package_id(METADATA_LIBRA_BACKTRACE),
1287                        from_feature: "rustc-dep-of-std".to_string(),
1288                    },
1289                    package_id: package_id(METADATA_LIBRA_CFG_IF),
1290                    feature_name: "rustc-dep-of-std".to_string(),
1291                },
1292            ])
1293    }
1294
1295    pub(crate) fn metadata_libra_f0091a4() -> Self {
1296        let details = AHashMap::new();
1297
1298        Self::new(details).with_cycles(vec![vec![
1299            METADATA_LIBRA_FUNCTIONAL_HYPHEN_TESTS,
1300            METADATA_LIBRA_E2E_TESTS,
1301            METADATA_LIBRA_VM_GENESIS,
1302            METADATA_LIBRA_MOVE_LANG_STDLIB,
1303            METADATA_LIBRA_MOVE_LANG,
1304        ]])
1305    }
1306
1307    pub(crate) fn metadata_libra_9ffd93b() -> Self {
1308        let details = AHashMap::new();
1309
1310        Self::new(details).with_cycles(vec![
1311            vec![METADATA_LIBRA_EXECUTOR_UTILS, METADATA_LIBRA_EXECUTOR],
1312            vec![
1313                METADATA_LIBRA_FUNCTIONAL_HYPHEN_TESTS,
1314                METADATA_LIBRA_E2E_TESTS,
1315                METADATA_LIBRA_VM_GENESIS,
1316                METADATA_LIBRA_TRANSACTION_BUILDER,
1317                METADATA_LIBRA_LIBRA_VM,
1318                METADATA_LIBRA_MOVE_VM_RUNTIME,
1319                METADATA_LIBRA_COMPILER,
1320                METADATA_LIBRA_STDLIB,
1321                METADATA_LIBRA_MOVE_LANG,
1322            ],
1323        ])
1324    }
1325
1326    pub(crate) fn mnemos_b3b4da9() -> Self {
1327        let details = AHashMap::new();
1328
1329        Self::new(details)
1330    }
1331
1332    pub(crate) fn hyper_util_7afb1ed() -> Self {
1333        let details = AHashMap::new();
1334
1335        Self::new(details)
1336    }
1337
1338    pub(crate) fn metadata_guppy_78cb7e8() -> Self {
1339        let details = AHashMap::new();
1340
1341        Self::new(details)
1342    }
1343
1344    pub(crate) fn metadata_guppy_869476c() -> Self {
1345        let details = AHashMap::new();
1346
1347        Self::new(details)
1348    }
1349
1350    pub(crate) fn metadata_guppy_c9b4f76() -> Self {
1351        let details = AHashMap::new();
1352
1353        Self::new(details)
1354    }
1355
1356    pub(crate) fn metadata_guppy_44b62fa() -> Self {
1357        let details = AHashMap::new();
1358
1359        Self::new(details)
1360    }
1361}