diff options
| author | Jonathan Pallant (Ferrous Systems) <jonathan.pallant@ferrous-systems.com> | 2023-11-22 18:07:14 +0000 |
|---|---|---|
| committer | Jonathan Pallant (Ferrous Systems) <jonathan.pallant@ferrous-systems.com> | 2023-11-27 11:03:53 +0000 |
| commit | 2d1cd458758176b9ad8fb15ae9b94821002b7bd0 (patch) | |
| tree | 7914913a49ec950ba0a28bd013fd824204df2b69 /src | |
| parent | daf6121001af46859cf2328f157a8366b971988f (diff) | |
| download | rust-2d1cd458758176b9ad8fb15ae9b94821002b7bd0.tar.gz rust-2d1cd458758176b9ad8fb15ae9b94821002b7bd0.zip | |
Fix generate-copyright tool.
LLVM copyrights are now condensed to those reported in the .reuse/dep5 file.
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/collect-license-metadata/src/main.rs | 10 | ||||
| -rw-r--r-- | src/tools/collect-license-metadata/src/path_tree.rs | 26 | ||||
| -rw-r--r-- | src/tools/generate-copyright/src/main.rs | 4 |
3 files changed, 25 insertions, 15 deletions
diff --git a/src/tools/collect-license-metadata/src/main.rs b/src/tools/collect-license-metadata/src/main.rs index ca2a6f4b8c8..cbe94af3510 100644 --- a/src/tools/collect-license-metadata/src/main.rs +++ b/src/tools/collect-license-metadata/src/main.rs @@ -6,6 +6,16 @@ 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 376dd8e3e66..fc8756d9a2e 100644 --- a/src/tools/collect-license-metadata/src/path_tree.rs +++ b/src/tools/collect-license-metadata/src/path_tree.rs @@ -7,11 +7,6 @@ use crate::licenses::{License, LicenseId, LicensesInterner}; use std::collections::{BTreeMap, BTreeSet}; use std::path::{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. -const CONDENSED_DIRECTORIED: &[&str] = &["./src/llvm-project/"]; - #[derive(serde::Serialize)] #[serde(rename_all = "kebab-case", tag = "type")] pub(crate) enum Node<L> { @@ -310,12 +305,17 @@ pub(crate) fn build(mut input: Vec<(PathBuf, LicenseId)>) -> Node<LicenseId> { let mut condensed_directories = BTreeMap::new(); 'outer: for (path, license) in input { // Files in condensed directories are handled separately. - for directory in CONDENSED_DIRECTORIED { - if path.starts_with(directory) { - condensed_directories - .entry(*directory) - .or_insert_with(BTreeSet::new) - .insert(license); + 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; } } @@ -338,9 +338,9 @@ pub(crate) fn build(mut input: Vec<(PathBuf, LicenseId)>) -> Node<LicenseId> { name: path.file_name().unwrap().into(), licenses: licenses.iter().copied().collect(), }; - for name in path.parent().unwrap_or_else(|| Path::new(".")).components().rev() { + for component in path.parent().unwrap_or_else(|| Path::new(".")).components().rev() { node = Node::Directory { - name: name.as_os_str().into(), + name: component.as_os_str().into(), children: vec![node], license: None, }; diff --git a/src/tools/generate-copyright/src/main.rs b/src/tools/generate-copyright/src/main.rs index 38f5ac91033..558e87290b0 100644 --- a/src/tools/generate-copyright/src/main.rs +++ b/src/tools/generate-copyright/src/main.rs @@ -27,7 +27,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), std::iter::once(license), buffer)?; + render_license(&prefix, std::iter::once(name), license.iter(), buffer)?; if !children.is_empty() { writeln!(buffer, "{prefix}")?; writeln!(buffer, "{prefix}*Exceptions:*")?; @@ -94,7 +94,7 @@ struct Metadata { #[serde(rename_all = "kebab-case", tag = "type")] pub(crate) enum Node { Root { children: Vec<Node> }, - Directory { name: String, children: Vec<Node>, license: License }, + 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 }, |
