diff options
| -rw-r--r-- | src/tools/collect-license-metadata/src/main.rs | 10 | ||||
| -rw-r--r-- | src/tools/collect-license-metadata/src/path_tree.rs | 52 | ||||
| -rw-r--r-- | src/tools/generate-copyright/src/main.rs | 38 |
3 files changed, 11 insertions, 89 deletions
diff --git a/src/tools/collect-license-metadata/src/main.rs b/src/tools/collect-license-metadata/src/main.rs index cbe94af3510..ca2a6f4b8c8 100644 --- a/src/tools/collect-license-metadata/src/main.rs +++ b/src/tools/collect-license-metadata/src/main.rs @@ -6,16 +6,6 @@ use crate::licenses::LicensesInterner; use anyhow::Error; use std::path::PathBuf; -// Some directories have too many slight license differences that'd result in a -// huge report, and could be considered a standalone project anyway. Those -// directories are "condensed" into a single licensing block for ease of -// reading, merging the licensing information. -// -// For every `(dir, file)``, every file in `dir` is considered to have the -// license info of `file`. -const CONDENSED_DIRECTORIES: &[(&str, &str)] = - &[("./src/llvm-project/", "./src/llvm-project/README.md")]; - fn main() -> Result<(), Error> { let reuse_exe: PathBuf = std::env::var_os("REUSE_EXE").expect("Missing REUSE_EXE").into(); let dest: PathBuf = std::env::var_os("DEST").expect("Missing DEST").into(); diff --git a/src/tools/collect-license-metadata/src/path_tree.rs b/src/tools/collect-license-metadata/src/path_tree.rs index fc8756d9a2e..b27fb7f9225 100644 --- a/src/tools/collect-license-metadata/src/path_tree.rs +++ b/src/tools/collect-license-metadata/src/path_tree.rs @@ -4,7 +4,7 @@ //! passes over the tree to remove redundant information. use crate::licenses::{License, LicenseId, LicensesInterner}; -use std::collections::{BTreeMap, BTreeSet}; +use std::collections::BTreeMap; use std::path::{Path, PathBuf}; #[derive(serde::Serialize)] @@ -12,7 +12,6 @@ use std::path::{Path, PathBuf}; pub(crate) enum Node<L> { Root { children: Vec<Node<L>> }, Directory { name: PathBuf, children: Vec<Node<L>>, license: Option<L> }, - CondensedDirectory { name: PathBuf, licenses: Vec<L> }, File { name: PathBuf, license: L }, Group { files: Vec<PathBuf>, directories: Vec<PathBuf>, license: L }, Empty, @@ -59,8 +58,6 @@ impl Node<LicenseId> { directories.entry(name).or_insert_with(Vec::new).append(&mut children); } file @ Node::File { .. } => files.push(file), - // Propagate condensed directories as-is. - condensed @ Node::CondensedDirectory { .. } => files.push(condensed), Node::Empty => {} Node::Root { .. } => { panic!("can't have a root inside another element"); @@ -87,7 +84,6 @@ impl Node<LicenseId> { } Node::Empty => {} Node::File { .. } => {} - Node::CondensedDirectory { .. } => {} Node::Group { .. } => { panic!("Group should not be present at this stage"); } @@ -134,7 +130,6 @@ impl Node<LicenseId> { } } Node::File { .. } => {} - Node::CondensedDirectory { .. } => {} Node::Group { .. } => panic!("group should not be present at this stage"), Node::Empty => {} } @@ -177,9 +172,6 @@ impl Node<LicenseId> { Node::Directory { name: child_child_name, .. } => { *child_child_name = child_name.join(&child_child_name); } - Node::CondensedDirectory { name: child_child_name, .. } => { - *child_child_name = child_name.join(&child_child_name); - } Node::File { name: child_child_name, .. } => { *child_child_name = child_name.join(&child_child_name); } @@ -194,7 +186,6 @@ impl Node<LicenseId> { } Node::Empty => {} Node::File { .. } => {} - Node::CondensedDirectory { .. } => {} Node::Group { .. } => panic!("Group should not be present at this stage"), } } @@ -262,7 +253,6 @@ impl Node<LicenseId> { } } Node::File { .. } => {} - Node::CondensedDirectory { .. } => {} Node::Group { .. } => panic!("FileGroup should not be present at this stage"), Node::Empty => {} } @@ -278,7 +268,6 @@ impl Node<LicenseId> { } children.retain(|child| !matches!(child, Node::Empty)); } - Node::CondensedDirectory { .. } => {} Node::Group { .. } => {} Node::File { .. } => {} Node::Empty => {} @@ -302,24 +291,7 @@ pub(crate) fn build(mut input: Vec<(PathBuf, LicenseId)>) -> Node<LicenseId> { // Ensure reproducibility of all future steps. input.sort(); - let mut condensed_directories = BTreeMap::new(); - 'outer: for (path, license) in input { - // Files in condensed directories are handled separately. - for (condensed_directory, allowed_file) in super::CONDENSED_DIRECTORIES { - if path.starts_with(condensed_directory) { - if path.as_path() == Path::new(allowed_file) { - // The licence on our allowed file is used to represent the entire directory - condensed_directories - .entry(*condensed_directory) - .or_insert_with(BTreeSet::new) - .insert(license); - } else { - // don't add the file - } - continue 'outer; - } - } - + for (path, license) in input { let mut node = Node::File { name: path.file_name().unwrap().into(), license }; for component in path.parent().unwrap_or_else(|| Path::new(".")).components().rev() { node = Node::Directory { @@ -332,22 +304,6 @@ pub(crate) fn build(mut input: Vec<(PathBuf, LicenseId)>) -> Node<LicenseId> { children.push(node); } - for (path, licenses) in condensed_directories { - let path = Path::new(path); - let mut node = Node::CondensedDirectory { - name: path.file_name().unwrap().into(), - licenses: licenses.iter().copied().collect(), - }; - for component in path.parent().unwrap_or_else(|| Path::new(".")).components().rev() { - node = Node::Directory { - name: component.as_os_str().into(), - children: vec![node], - license: None, - }; - } - children.push(node); - } - Node::Root { children } } @@ -376,10 +332,6 @@ pub(crate) fn expand_interned_licenses( Node::Group { files, directories, license } => { Node::Group { files, directories, license: interner.resolve(license) } } - Node::CondensedDirectory { name, licenses } => Node::CondensedDirectory { - name, - licenses: licenses.into_iter().map(|license| interner.resolve(license)).collect(), - }, Node::Empty => Node::Empty, } } diff --git a/src/tools/generate-copyright/src/main.rs b/src/tools/generate-copyright/src/main.rs index 558e87290b0..d91b258162e 100644 --- a/src/tools/generate-copyright/src/main.rs +++ b/src/tools/generate-copyright/src/main.rs @@ -1,5 +1,4 @@ use anyhow::Error; -use std::collections::BTreeSet; use std::io::Write; use std::path::PathBuf; @@ -27,7 +26,7 @@ fn render_recursive(node: &Node, buffer: &mut Vec<u8>, depth: usize) -> Result<( } } Node::Directory { name, children, license } => { - render_license(&prefix, std::iter::once(name), license.iter(), buffer)?; + render_license(&prefix, std::iter::once(name), license.as_ref(), buffer)?; if !children.is_empty() { writeln!(buffer, "{prefix}")?; writeln!(buffer, "{prefix}*Exceptions:*")?; @@ -37,19 +36,11 @@ fn render_recursive(node: &Node, buffer: &mut Vec<u8>, depth: usize) -> Result<( } } } - Node::CondensedDirectory { name, licenses } => { - render_license(&prefix, std::iter::once(name), licenses.iter(), buffer)?; - } Node::Group { files, directories, license } => { - render_license( - &prefix, - directories.iter().chain(files.iter()), - std::iter::once(license), - buffer, - )?; + render_license(&prefix, directories.iter().chain(files.iter()), Some(license), buffer)?; } Node::File { name, license } => { - render_license(&prefix, std::iter::once(name), std::iter::once(license), buffer)?; + render_license(&prefix, std::iter::once(name), Some(license), buffer)?; } } @@ -59,27 +50,17 @@ fn render_recursive(node: &Node, buffer: &mut Vec<u8>, depth: usize) -> Result<( fn render_license<'a>( prefix: &str, names: impl Iterator<Item = &'a String>, - licenses: impl Iterator<Item = &'a License>, + license: Option<&License>, buffer: &mut Vec<u8>, ) -> Result<(), Error> { - let mut spdxs = BTreeSet::new(); - let mut copyrights = BTreeSet::new(); - for license in licenses { - spdxs.insert(&license.spdx); - for copyright in &license.copyright { - copyrights.insert(copyright); - } - } - for name in names { writeln!(buffer, "{prefix}**`{name}`** ")?; } - for spdx in spdxs.iter() { - writeln!(buffer, "{prefix}License: `{spdx}` ")?; - } - for (i, copyright) in copyrights.iter().enumerate() { - let suffix = if i == copyrights.len() - 1 { "" } else { " " }; - writeln!(buffer, "{prefix}Copyright: {copyright}{suffix}")?; + if let Some(license) = license { + writeln!(buffer, "{prefix}License: `{}`", license.spdx)?; + for copyright in license.copyright.iter() { + writeln!(buffer, "{prefix}Copyright: {copyright}")?; + } } Ok(()) @@ -95,7 +76,6 @@ struct Metadata { pub(crate) enum Node { Root { children: Vec<Node> }, Directory { name: String, children: Vec<Node>, license: Option<License> }, - CondensedDirectory { name: String, licenses: Vec<License> }, File { name: String, license: License }, Group { files: Vec<String>, directories: Vec<String>, license: License }, } |
