Skip to content

Commit

Permalink
refactor: removed cargo tree feature and code
Browse files Browse the repository at this point in the history
  • Loading branch information
WyvernIXTL committed Oct 27, 2024
1 parent d3ce7a7 commit e371734
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 63 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
58 changes: 1 addition & 57 deletions src/build_script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
// <https://github.com/rust-lang/cargo/issues/11444>

let mut used_packages_tree: Option<BTreeSet<String>> = 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: <https://github.com/rust-lang/cargo/issues/10801>

let mut metadata_output = Command::new(&cargo_path)
.current_dir(&manifest_path)
.args(["metadata", "--format-version", "1", "--frozen", "--color", "never"])
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e371734

Please sign in to comment.