From e371734afd49f7438a299d0d4d9712763a7fbafa Mon Sep 17 00:00:00 2001 From: Adam McKellar Date: Sun, 27 Oct 2024 14:35:54 +0100 Subject: [PATCH] refactor: removed cargo tree feature and code --- Cargo.toml | 3 +-- README.md | 6 ++--- src/build_script/mod.rs | 58 +---------------------------------------- 3 files changed, 4 insertions(+), 63 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c49c948..90a4f99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,7 @@ pretty_assertions = "1.4.0" [features] -default = ["compress", "cargo-tree"] +default = ["compress"] compress = ["dep:miniz_oxide"] build = ["dep:serde_json", "dep:serde", "dep:simplelog", "dep:log", "dep:regex", "dep:once_cell", "dep:directories"] frozen = [] -cargo-tree = [] diff --git a/README.md b/README.md index 347d451..484b351 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,8 @@ ## Workings -This library gets all packages that are actually copmiled with your program via `cargo tree`. -This is needed to circumvent a [cargo bug](https://github.com/rust-lang/cargo/issues/10801). -Afterwards it fetches the metadata of said packages with `cargo metadata`. -Licenses are fetched from the `.cargo/registry/src` folder. +Crates that are compiled with your program are fetched via `cargo metadata`. +License texts are read from the `.cargo/registry/src` folder. The data is then serialized and compressed. diff --git a/src/build_script/mod.rs b/src/build_script/mod.rs index 535ef07..d30ee9d 100644 --- a/src/build_script/mod.rs +++ b/src/build_script/mod.rs @@ -42,56 +42,6 @@ fn generate_package_list() -> PackageList { let cargo_path = var_os("CARGO").unwrap(); let manifest_path = var_os("CARGO_MANIFEST_DIR").unwrap(); - // Workaround: Get dependencies with `cargo tree`. - // These are dependencies, which are compiled. - // - - let mut used_packages_tree: Option> = None; - - #[cfg(feature = "cargo-tree")] - { - - let mut output = Command::new(&cargo_path) - .current_dir(&manifest_path) - .args(["tree", "-e", "normal", "-f", "{p}", "--prefix", "none", "--frozen", "--color", "never", "--no-dedupe"]) - .output() - .unwrap(); - - #[cfg(not(feature = "frozen"))] - if !output.status.success() { - output = Command::new(&cargo_path) - .current_dir(&manifest_path) - .args(["tree", "-e", "normal", "-f", "{p}", "--prefix", "none", "--color", "never", "--no-dedupe"]) - .output() - .unwrap(); - } - - #[cfg(feature = "frozen")] - if !output.status.success() { - panic!("Failed executing cargo tree with:\n{}", String::from_utf8_lossy(&output.stderr)); - } - - if output.status.success() { - let tree_string = String::from_utf8(output.stdout).unwrap(); - let mut used_package_set = BTreeSet::new(); - - for package in tree_string.lines() { - let mut split_line_iter = package.split_whitespace(); - if let Some(s) = split_line_iter.next() { - used_package_set.insert(s.to_owned()); - } - } - - used_packages_tree = Some(used_package_set); - } - - } - - - // Walk dependencies. - // This also finds packages which are not compiled. - // See: - let mut metadata_output = Command::new(&cargo_path) .current_dir(&manifest_path) .args(["metadata", "--format-version", "1", "--frozen", "--color", "never"]) @@ -127,13 +77,7 @@ fn generate_package_list() -> PackageList { let mut package_list = vec![]; for package in packages { - let mut is_used = true; - - if let Some(tree_packages) = &used_packages_tree { - is_used = tree_packages.contains(&package.name); - } - - if is_used && used_packages.contains(&package.id) { + if used_packages.contains(&package.id) { package_list.push(Package { license_text: None, authors: package.authors,