Skip to content

Commit

Permalink
generate-copyright: Now generates a library file too.
Browse files Browse the repository at this point in the history
We only run reuse once, so the output has to be filtered to find only the files that are relevant to the library tree.

Outputs COPYRIGHT.html and COPYRIGHT-library.html.

The license-metadata.json file is also now in the tree. We need a CI tool to check that it's correct.
  • Loading branch information
jonathanpallant committed Nov 19, 2024
1 parent e6c1e14 commit 3d3e2e3
Show file tree
Hide file tree
Showing 5 changed files with 394 additions and 40 deletions.
204 changes: 204 additions & 0 deletions license-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
{
"files": {
"children": [
{
"children": [
{
"children": [
{
"license": {
"copyright": [
"The Rust Project Developers (see https://thanks.rust-lang.org)"
],
"spdx": "Apache-2.0 OR MIT"
},
"name": "noscript.css",
"type": "file"
},
{
"license": {
"copyright": [
"Nicolas Gallagher and Jonathan Neal"
],
"spdx": "MIT"
},
"name": "normalize.css",
"type": "file"
}
],
"license": {
"copyright": [
"2016 Ike Ku, Jessica Stokes and Leon Guan",
"The Rust Project Developers (see https://thanks.rust-lang.org)"
],
"spdx": "Apache-2.0 OR MIT"
},
"name": "src/librustdoc/html/static/css",
"type": "directory"
},
{
"children": [
{
"license": {
"copyright": [
"The Rust Project Developers (see https://thanks.rust-lang.org)"
],
"spdx": "Apache-2.0 OR MIT"
},
"name": "README.txt",
"type": "file"
},
{
"directories": [],
"files": [
"FiraSans-LICENSE.txt",
"FiraSans-Medium.woff2",
"FiraSans-Regular.woff2"
],
"license": {
"copyright": [
"2014, Mozilla Foundation",
"2014, Telefonica S.A"
],
"spdx": "OFL-1.1"
},
"type": "group"
},
{
"directories": [],
"files": [
"NanumBarunGothic-LICENSE.txt",
"NanumBarunGothic.ttf.woff2"
],
"license": {
"copyright": [
"2010 NAVER Corporation"
],
"spdx": "OFL-1.1"
},
"type": "group"
}
],
"license": {
"copyright": [
"2010, 2012, 2014-2023, Adobe Systems Incorporated"
],
"spdx": "OFL-1.1"
},
"name": "src/librustdoc/html/static/fonts",
"type": "directory"
},
{
"license": {
"copyright": [
"2003-2019 University of Illinois at Urbana-Champaign",
"The Rust Project Developers (see https://thanks.rust-lang.org)"
],
"spdx": "Apache-2.0 WITH LLVM-exception AND (Apache-2.0 OR MIT)"
},
"name": "compiler/rustc_llvm/llvm-wrapper/SymbolWrapper.cpp",
"type": "file"
},
{
"children": [],
"license": {
"copyright": [
"2014 Alex Crichton",
"The Rust Project Developers (see https://thanks.rust-lang.org)"
],
"spdx": "Apache-2.0 OR MIT"
},
"name": "library/backtrace",
"type": "directory"
},
{
"license": {
"copyright": [
"1991-2022 Unicode, Inc. All rights reserved"
],
"spdx": "Unicode-DFS-2016"
},
"name": "library/core/src/unicode/unicode_data.rs",
"type": "file"
},
{
"children": [],
"license": {
"copyright": [
"2019 The Crossbeam Project Developers",
"The Rust Project Developers (see https://thanks.rust-lang.org)"
],
"spdx": "Apache-2.0 OR MIT"
},
"name": "library/std/src/sync/mpmc",
"type": "directory"
},
{
"license": {
"copyright": [
"2016 The Fuchsia Authors",
"The Rust Project Developers (see https://thanks.rust-lang.org)"
],
"spdx": "BSD-2-Clause AND (Apache-2.0 OR MIT)"
},
"name": "library/std/src/sys/sync/mutex/fuchsia.rs",
"type": "file"
},
{
"license": {
"copyright": [
"NONE"
],
"spdx": "NONE"
},
"name": "qnx_build.sh",
"type": "file"
},
{
"children": [],
"license": {
"copyright": [
"Rust on Embedded Devices Working Group",
"The Rust Project Developers (see https://thanks.rust-lang.org)"
],
"spdx": "Apache-2.0 OR CC-BY-SA-4.0 OR MIT"
},
"name": "src/doc/embedded-book",
"type": "directory"
},
{
"children": [],
"license": {
"copyright": [
"2014 Jorge Aparicio",
"The Rust Project Developers (see https://thanks.rust-lang.org)"
],
"spdx": "Apache-2.0 OR MIT"
},
"name": "src/doc/rust-by-example",
"type": "directory"
},
{
"license": {
"copyright": [
"2014-2021 Knut Sveidqvist"
],
"spdx": "MIT"
},
"name": "src/doc/rustc-dev-guide/mermaid.min.js",
"type": "file"
}
],
"license": {
"copyright": [
"The Rust Project Developers (see https://thanks.rust-lang.org)"
],
"spdx": "Apache-2.0 OR MIT"
},
"name": ".",
"type": "directory"
}
],
"type": "root"
}
}
25 changes: 12 additions & 13 deletions src/bootstrap/src/core/build_steps/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,16 @@ impl Step for CollectLicenseMetadata {
}

fn run(self, builder: &Builder<'_>) -> Self::Output {
let Some(reuse) = &builder.config.reuse else {
panic!("REUSE is required to collect the license metadata");
};

// Temporary location, it will be moved to src/etc once it's accurate.
let dest = builder.out.join("license-metadata.json");

let mut cmd = builder.tool_cmd(Tool::CollectLicenseMetadata);
cmd.env("REUSE_EXE", reuse);
cmd.env("DEST", &dest);
cmd.run(builder);

let dest = PathBuf::from("license-metadata.json");
if !std::fs::exists(&dest).expect("Checking for license metadata") {
let Some(reuse) = &builder.config.reuse else {
panic!("REUSE is required to collect the license metadata");
};
let mut cmd = builder.tool_cmd(Tool::CollectLicenseMetadata);
cmd.env("REUSE_EXE", reuse);
cmd.env("DEST", &dest);
cmd.run(builder);
}
dest
}
}
Expand All @@ -211,12 +209,13 @@ impl Step for GenerateCopyright {
fn run(self, builder: &Builder<'_>) -> Self::Output {
let license_metadata = builder.ensure(CollectLicenseMetadata);

// Temporary location, it will be moved to the proper one once it's accurate.
let dest = builder.out.join("COPYRIGHT.html");
let dest_libstd = builder.out.join("COPYRIGHT-library.html");

let mut cmd = builder.tool_cmd(Tool::GenerateCopyright);
cmd.env("LICENSE_METADATA", &license_metadata);
cmd.env("DEST", &dest);
cmd.env("DEST_LIBSTD", &dest_libstd);
cmd.env("OUT_DIR", &builder.out);
cmd.env("CARGO", &builder.initial_cargo);
cmd.run(builder);
Expand Down
3 changes: 1 addition & 2 deletions src/tools/generate-copyright/src/cargo_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ pub struct PackageMetadata {
/// assume `reuse` has covered it already.
pub fn get_metadata_and_notices(
cargo: &Path,
dest: &Path,
vendor_path: &Path,
root_path: &Path,
manifest_paths: &[&Path],
) -> Result<BTreeMap<Package, PackageMetadata>, Error> {
let mut output = get_metadata(cargo, root_path, manifest_paths)?;

// Now do a cargo-vendor and grab everything
let vendor_path = dest.join("vendor");
println!("Vendoring deps into {}...", vendor_path.display());
run_cargo_vendor(cargo, &vendor_path, manifest_paths)?;

Expand Down
Loading

0 comments on commit 3d3e2e3

Please sign in to comment.