1 use crate::licenses::{License, LicenseId, LicensesInterner};
3 use std::path::{Path, PathBuf};
4 use std::process::{Command, Stdio};
5 use std::time::Instant;
9 interner: &mut LicensesInterner,
10 ) -> Result<Vec<(PathBuf, LicenseId)>, Error> {
11 eprintln!("gathering license information from REUSE");
12 let start = Instant::now();
13 let raw = &obtain_spdx_document(reuse_exe)?;
14 eprintln!("finished gathering the license information from REUSE in {:.2?}", start.elapsed());
16 let document = spdx_rs::parsers::spdx_from_tag_value(&raw)?;
18 let mut result = Vec::new();
19 for file in document.file_information {
20 let license = interner.intern(License {
21 spdx: file.concluded_license.to_string(),
22 copyright: file.copyright_text.split('\n').map(|s| s.into()).collect(),
25 result.push((file.file_name.into(), license));
31 fn obtain_spdx_document(reuse_exe: &Path) -> Result<String, Error> {
32 let output = Command::new(reuse_exe)
33 .args(&["spdx", "--add-license-concluded", "--creator-person=bors"])
34 .stdout(Stdio::piped())
38 if !output.status.success() {
40 eprintln!("Note that Rust requires some REUSE features that might not be present in the");
41 eprintln!("release you're using. Make sure your REUSE release includes these PRs:");
43 eprintln!(" - https://github.com/fsfe/reuse-tool/pull/623");
45 anyhow::bail!("collecting licensing information with REUSE failed");
48 Ok(String::from_utf8(output.stdout)?)