Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ dependencies = [
"anyhow",
"serde",
"serde_json",
"similar",
"spdx-rs",
]

Expand Down
1 change: 1 addition & 0 deletions src/tools/collect-license-metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ license = "MIT OR Apache-2.0"
anyhow = "1.0.65"
serde = { version = "1.0.147", features = ["derive"] }
serde_json = "1.0.85"
similar = "2.7.0"
spdx-rs = "0.5.1"
14 changes: 14 additions & 0 deletions src/tools/collect-license-metadata/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@ mod reuse;
use std::path::PathBuf;

use anyhow::{Context, Error};
use similar::{ChangeTag, TextDiff};

use crate::licenses::LicensesInterner;

fn diff_text(expected: &str, actual: &str) {
for change in TextDiff::from_lines(expected, actual).iter_all_changes() {
let sign = match change.tag() {
ChangeTag::Delete => "-",
ChangeTag::Insert => "+",
ChangeTag::Equal => " ",
};
print!("{}{}", sign, change);
}
}

/// The entry point to the binary.
///
/// You should probably let `bootstrap` execute this program instead of running it directly.
Expand Down Expand Up @@ -41,6 +53,8 @@ fn main() -> Result<(), Error> {
if existing_json != output {
eprintln!("The existing {} file is out of date.", dest.display());
eprintln!("Run ./x run collect-license-metadata to update it.");
eprintln!("Diff:");
diff_text(&existing, &serde_json::to_string_pretty(&output).unwrap());
anyhow::bail!("The existing {} file doesn't match what REUSE reports.", dest.display());
}
println!("license information matches");
Expand Down
Loading