Auto merge of #104527 - ferrocene:pa-more-licenses, r=pnkfelix

Add more license annotations

This PR updates the `.reuse/dep5` file to include more accurate licensing data for everything in the repository (*excluding* submodules and dependencies). Some decisions were made in this PR:

* The standard copyright attribution for files maintained by us is "The Rust Project Developers (see https://thanks.rust-lang.org)", to avoid having to maintain an in-tree `AUTHORS` file.
* For files that have specific licensing terms, we added the terms to the `.reuse/dep5` rather than adding SPDX comments in the files themselves.
* REUSE picks up any comment/text line with `Copyright` on it, so I had to sprinkle around `REUSE-IgnoreStart` and `REUSE-IgnoreEnd` comments.

The rendered `COPYRIGHT` file is available at https://gist.github.com/pietroalbini/efb81103f69596d39758114f3f6a8688.

r? `@pnkfelix`
This commit is contained in:
bors 2023-03-11 01:17:23 +00:00
commit 6dfaa14366
29 changed files with 261 additions and 137 deletions

View file

@ -1,3 +1,5 @@
// REUSE-IgnoreStart
Copyright 2014-2022 The Rust Project Developers
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -5,3 +7,5 @@ http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
<LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
option. All files in the project carrying such notice may not be
copied, modified, or distributed except according to those terms.
// REUSE-IgnoreEnd

View file

@ -275,6 +275,8 @@ If you want to contribute to Clippy, you can find more information in [CONTRIBUT
## License
<!-- REUSE-IgnoreStart -->
Copyright 2014-2022 The Rust Project Developers
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -282,3 +284,5 @@ Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
<LICENSE-MIT or [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT)>, at your
option. Files in the project may not be
copied, modified, or distributed except according to those terms.
<!-- REUSE-IgnoreEnd -->

View file

@ -49,6 +49,8 @@ The changelog for `rustc_tools_util` is available under:
## License
<!-- REUSE-IgnoreStart -->
Copyright 2014-2022 The Rust Project Developers
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@ -56,3 +58,5 @@ http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
<LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
option. All files in the project carrying such notice may not be
copied, modified, or distributed except according to those terms.
<!-- REUSE-IgnoreEnd -->

View file

@ -42,6 +42,7 @@ pub(crate) struct License {
impl License {
fn simplify(&mut self) {
self.remove_copyright_prefixes();
self.remove_trailing_dots();
self.copyright.sort();
self.copyright.dedup();
}
@ -62,4 +63,12 @@ impl License {
*copyright = stripped.into();
}
}
fn remove_trailing_dots(&mut self) {
for copyright in &mut self.copyright {
if copyright.ends_with('.') {
*copyright = copyright.trim_end_matches('.').to_string();
}
}
}
}

View file

@ -13,7 +13,7 @@ pub(crate) enum Node<L> {
Root { childs: Vec<Node<L>> },
Directory { name: PathBuf, childs: Vec<Node<L>>, license: Option<L> },
File { name: PathBuf, license: L },
FileGroup { names: Vec<PathBuf>, license: L },
Group { files: Vec<PathBuf>, directories: Vec<PathBuf>, license: L },
Empty,
}
@ -22,7 +22,7 @@ impl Node<LicenseId> {
self.merge_directories();
self.collapse_in_licensed_directories();
self.merge_directory_licenses();
self.merge_file_groups();
self.merge_groups();
self.remove_empty();
}
@ -64,8 +64,8 @@ impl Node<LicenseId> {
Node::Root { .. } => {
panic!("can't have a root inside another element");
}
Node::FileGroup { .. } => {
panic!("FileGroup should not be present at this stage");
Node::Group { .. } => {
panic!("Group should not be present at this stage");
}
Node::Directory { license: Some(_), .. } => {
panic!("license should not be set at this stage");
@ -86,8 +86,8 @@ impl Node<LicenseId> {
}
Node::Empty => {}
Node::File { .. } => {}
Node::FileGroup { .. } => {
panic!("FileGroup should not be present at this stage");
Node::Group { .. } => {
panic!("Group should not be present at this stage");
}
Node::Directory { license: Some(_), .. } => {
panic!("license should not be set at this stage");
@ -132,7 +132,7 @@ impl Node<LicenseId> {
}
}
Node::File { .. } => {}
Node::FileGroup { .. } => {}
Node::Group { .. } => panic!("group should not be present at this stage"),
Node::Empty => {}
}
}
@ -165,8 +165,8 @@ impl Node<LicenseId> {
Node::Root { .. } => {
panic!("can't have a root inside another element");
}
Node::FileGroup { .. } => {
panic!("FileGroup should not be present at this stage");
Node::Group { .. } => {
panic!("Group should not be present at this stage");
}
Node::Directory { name: child_child_name, .. } => {
*child_child_name = child_name.join(&child_child_name);
@ -185,38 +185,74 @@ impl Node<LicenseId> {
}
Node::Empty => {}
Node::File { .. } => {}
Node::FileGroup { .. } => {}
Node::Group { .. } => panic!("Group should not be present at this stage"),
}
}
/// This pass groups multiple files in a directory with the same license into a single
/// "FileGroup", so that the license of all those files can be reported as a group.
/// "Group", so that the license of all those files can be reported as a group.
///
/// This also merges directories *without exceptions*.
///
/// Crucially this pass runs after collapse_in_licensed_directories, so the most common license
/// will already be marked as the directory's license and won't be turned into a group.
fn merge_file_groups(&mut self) {
fn merge_groups(&mut self) {
#[derive(Default)]
struct Grouped {
files: Vec<PathBuf>,
directories: Vec<PathBuf>,
}
match self {
Node::Root { childs } | Node::Directory { childs, .. } => {
let mut grouped = BTreeMap::new();
let mut grouped: BTreeMap<LicenseId, Grouped> = BTreeMap::new();
for child in &mut *childs {
child.merge_file_groups();
if let Node::File { name, license } = child {
grouped.entry(*license).or_insert_with(Vec::new).push(name.clone());
*child = Node::Empty;
child.merge_groups();
match child {
Node::Directory { name, childs, license: Some(license) } => {
if childs.is_empty() {
grouped
.entry(*license)
.or_insert_with(Grouped::default)
.directories
.push(name.clone());
*child = Node::Empty;
}
}
Node::File { name, license } => {
grouped
.entry(*license)
.or_insert_with(Grouped::default)
.files
.push(name.clone());
*child = Node::Empty;
}
_ => {}
}
}
for (license, mut names) in grouped.into_iter() {
if names.len() == 1 {
childs.push(Node::File { license, name: names.pop().unwrap() });
for (license, mut grouped) in grouped.into_iter() {
if grouped.files.len() + grouped.directories.len() <= 1 {
if let Some(name) = grouped.files.pop() {
childs.push(Node::File { license, name });
} else if let Some(name) = grouped.directories.pop() {
childs.push(Node::Directory {
name,
childs: Vec::new(),
license: Some(license),
});
}
} else {
childs.push(Node::FileGroup { license, names });
childs.push(Node::Group {
license,
files: grouped.files,
directories: grouped.directories,
});
}
}
}
Node::File { .. } => {}
Node::FileGroup { .. } => panic!("FileGroup should not be present at this stage"),
Node::Group { .. } => panic!("FileGroup should not be present at this stage"),
Node::Empty => {}
}
}
@ -231,7 +267,7 @@ impl Node<LicenseId> {
}
childs.retain(|child| !matches!(child, Node::Empty));
}
Node::FileGroup { .. } => {}
Node::Group { .. } => {}
Node::File { .. } => {}
Node::Empty => {}
}
@ -278,16 +314,22 @@ pub(crate) fn expand_interned_licenses(
) -> Node<&License> {
match node {
Node::Root { childs } => Node::Root {
childs: childs.into_iter().map(|child| strip_interning(child, interner)).collect(),
childs: childs
.into_iter()
.map(|child| expand_interned_licenses(child, interner))
.collect(),
},
Node::Directory { name, childs, license } => Node::Directory {
childs: childs.into_iter().map(|child| strip_interning(child, interner)).collect(),
childs: childs
.into_iter()
.map(|child| expand_interned_licenses(child, interner))
.collect(),
license: license.map(|license| interner.resolve(license)),
name,
},
Node::File { name, license } => Node::File { name, license: interner.resolve(license) },
Node::FileGroup { names, license } => {
Node::FileGroup { names, license: interner.resolve(license) }
Node::Group { files, directories, license } => {
Node::Group { files, directories, license: interner.resolve(license) }
}
Node::Empty => Node::Empty,
}

View file

@ -36,8 +36,8 @@ fn render_recursive(node: &Node, buffer: &mut Vec<u8>, depth: usize) -> Result<(
}
}
}
Node::FileGroup { names, license } => {
render_license(&prefix, names.iter(), license, buffer)?;
Node::Group { files, directories, license } => {
render_license(&prefix, directories.iter().chain(files.iter()), license, buffer)?;
}
Node::File { name, license } => {
render_license(&prefix, std::iter::once(name), license, buffer)?;
@ -76,7 +76,7 @@ pub(crate) enum Node {
Root { childs: Vec<Node> },
Directory { name: String, childs: Vec<Node>, license: License },
File { name: String, license: License },
FileGroup { names: Vec<String>, license: License },
Group { files: Vec<String>, directories: Vec<String>, license: License },
}
#[derive(serde::Deserialize)]

View file

@ -1,12 +1,5 @@
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// SPDX-License-Identifier: MIT OR Apache-2.0
// SPDX-FileCopyrightText: The Rust Project Developers (see https://thanks.rust-lang.org)
#![feature(core_intrinsics)]
use std::intrinsics::*;

View file

@ -1,12 +1,5 @@
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// SPDX-License-Identifier: MIT OR Apache-2.0
// SPDX-FileCopyrightText: The Rust Project Developers (see https://thanks.rust-lang.org)
macro_rules! assert_approx_eq {
($a:expr, $b:expr) => {{

View file

@ -1,12 +1,5 @@
// Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// SPDX-License-Identifier: MIT OR Apache-2.0
// SPDX-FileCopyrightText: The Rust Project Developers (see https://thanks.rust-lang.org)
// Regression test for Issue #30530: alloca's created for storing
// intermediate scratch values during brace-less match arms need to be

View file

@ -1,12 +1,5 @@
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// SPDX-License-Identifier: MIT OR Apache-2.0
// SPDX-FileCopyrightText: The Rust Project Developers (see https://thanks.rust-lang.org)
use std::mem;

View file

@ -1,13 +1,4 @@
#!/bin/bash
# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
set -ue

View file

@ -1,13 +1,4 @@
#!/bin/bash
# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
set -ue

View file

@ -1,13 +1,4 @@
#!/bin/bash
# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
set -ue

View file

@ -1,13 +1,4 @@
#!/bin/bash
# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
# No undefined variables
set -u

View file

@ -1,13 +1,4 @@
#!/bin/sh
# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
set -ue