Skip to content

Commit 0083012

Browse files
Now the COPYRIGHT HTML files live at the root and CI checks they are correct.
Run ./x run generate-copyright to rebuild them. Run ./x test generate-copyright to check them.
1 parent 2932833 commit 0083012

File tree

11 files changed

+154325
-408
lines changed

11 files changed

+154325
-408
lines changed

COPYRIGHT

-391
This file was deleted.

COPYRIGHT-library.html

+7,358
Large diffs are not rendered by default.

COPYRIGHT.html

+146,840
Large diffs are not rendered by default.

REUSE.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ path = [
2525
"config.example.toml",
2626
"configure",
2727
"CONTRIBUTING.md",
28-
"COPYRIGHT",
28+
"COPYRIGHT.html",
29+
"COPYRIGHT-library.html",
2930
"INSTALL.md",
3031
"LICENSE-APACHE",
3132
"LICENSE-MIT",

src/bootstrap/src/core/build_steps/run.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl Step for CollectLicenseMetadata {
197197
pub struct GenerateCopyright;
198198

199199
impl Step for GenerateCopyright {
200-
type Output = PathBuf;
200+
type Output = (PathBuf, PathBuf);
201201
const ONLY_HOSTS: bool = true;
202202

203203
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -211,18 +211,19 @@ impl Step for GenerateCopyright {
211211
fn run(self, builder: &Builder<'_>) -> Self::Output {
212212
let license_metadata = builder.ensure(CollectLicenseMetadata);
213213

214-
let dest = builder.out.join("COPYRIGHT.html");
215-
let dest_libstd = builder.out.join("COPYRIGHT-library.html");
214+
let dest = builder.src.join("COPYRIGHT.html");
215+
let dest_libstd = builder.src.join("COPYRIGHT-library.html");
216216

217217
let mut cmd = builder.tool_cmd(Tool::GenerateCopyright);
218218
cmd.env("LICENSE_METADATA", &license_metadata);
219219
cmd.env("DEST", &dest);
220220
cmd.env("DEST_LIBSTD", &dest_libstd);
221221
cmd.env("OUT_DIR", &builder.out);
222+
cmd.env("CHECK", "0");
222223
cmd.env("CARGO", &builder.initial_cargo);
223224
cmd.run(builder);
224225

225-
dest
226+
(dest, dest_libstd)
226227
}
227228
}
228229

src/bootstrap/src/core/build_steps/test.rs

+33
Original file line numberDiff line numberDiff line change
@@ -3611,3 +3611,36 @@ impl Step for TestFloatParse {
36113611
cargo_run.into_cmd().run(builder);
36123612
}
36133613
}
3614+
3615+
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
3616+
pub struct GenerateCopyright;
3617+
3618+
impl Step for GenerateCopyright {
3619+
type Output = ();
3620+
const ONLY_HOSTS: bool = true;
3621+
3622+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
3623+
run.path("src/tools/generate-copyright")
3624+
}
3625+
3626+
fn make_run(run: RunConfig<'_>) {
3627+
run.builder.ensure(GenerateCopyright);
3628+
}
3629+
3630+
fn run(self, builder: &Builder<'_>) -> Self::Output {
3631+
let license_metadata =
3632+
builder.ensure(crate::core::build_steps::run::CollectLicenseMetadata);
3633+
3634+
let dest = builder.out.join("COPYRIGHT.html");
3635+
let dest_libstd = builder.out.join("COPYRIGHT-library.html");
3636+
3637+
let mut cmd = builder.tool_cmd(Tool::GenerateCopyright);
3638+
cmd.env("LICENSE_METADATA", &license_metadata);
3639+
cmd.env("DEST", &dest);
3640+
cmd.env("DEST_LIBSTD", &dest_libstd);
3641+
cmd.env("OUT_DIR", &builder.out);
3642+
cmd.env("CHECK", "1");
3643+
cmd.env("CARGO", &builder.initial_cargo);
3644+
cmd.run(builder);
3645+
}
3646+
}

src/bootstrap/src/core/builder/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ impl<'a> Builder<'a> {
915915
test::HtmlCheck,
916916
test::RustInstaller,
917917
test::TestFloatParse,
918+
test::GenerateCopyright,
918919
// Run bootstrap close to the end as it's unlikely to fail
919920
test::Bootstrap,
920921
// Run run-make last, since these won't pass without make on Windows

src/ci/docker/host-x86_64/mingw-check/Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ ENV SCRIPT \
6767
es-check es2019 ../src/librustdoc/html/static/js/*.js && \
6868
eslint -c ../src/librustdoc/html/static/.eslintrc.js ../src/librustdoc/html/static/js/*.js && \
6969
eslint -c ../src/tools/rustdoc-js/.eslintrc.js ../src/tools/rustdoc-js/tester.js && \
70-
eslint -c ../src/tools/rustdoc-gui/.eslintrc.js ../src/tools/rustdoc-gui/tester.js
70+
eslint -c ../src/tools/rustdoc-gui/.eslintrc.js ../src/tools/rustdoc-gui/tester.js && \
71+
# Check our COPYRIGHT files are still OK
72+
python3 ../x.py test generate-copyright

src/tools/generate-copyright/src/main.rs

+30-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ mod cargo_metadata;
1010
///
1111
/// You should probably let `bootstrap` execute this program instead of running it directly.
1212
///
13-
/// Run `x.py run generate-copyright`
13+
/// Run `x.py run generate-copyright` to make the files, or
14+
/// `x.py test generate-copyright` to check the existing files.
1415
fn main() -> Result<(), Error> {
1516
let dest_file = env_path("DEST")?;
1617
let libstd_dest_file = env_path("DEST_LIBSTD")?;
18+
let check_existing = env_str("CHECK")? == "1";
19+
1720
let out_dir = env_path("OUT_DIR")?;
1821
let cargo = env_path("CARGO")?;
1922
let license_metadata = env_path("LICENSE_METADATA")?;
@@ -57,16 +60,35 @@ fn main() -> Result<(), Error> {
5760
dependencies: collected_cargo_metadata,
5861
};
5962
let output = template.render()?;
60-
std::fs::write(&dest_file, output)?;
63+
if check_existing {
64+
check_file_contents(&dest_file, &output)?;
65+
} else {
66+
std::fs::write(&dest_file, &output)?;
67+
}
6168

6269
// Output libstd subset file
6370
let template = LibraryCopyrightTemplate {
6471
in_tree: library_collected_tree_metadata.files,
6572
dependencies: library_collected_cargo_metadata,
6673
};
6774
let output = template.render()?;
68-
std::fs::write(&libstd_dest_file, output)?;
75+
if check_existing {
76+
check_file_contents(&libstd_dest_file, &output)?;
77+
} else {
78+
std::fs::write(&libstd_dest_file, &output)?;
79+
}
80+
81+
Ok(())
82+
}
6983

84+
/// Check two files have the same contents
85+
fn check_file_contents(path: &Path, new_contents: &str) -> Result<(), Error> {
86+
let orig_contents = std::fs::read_to_string(&path)?;
87+
if orig_contents != new_contents {
88+
anyhow::bail!("File {} is out of date", path.display());
89+
} else {
90+
println!("File {} is OK", path.display());
91+
}
7092
Ok(())
7193
}
7294

@@ -186,3 +208,8 @@ fn env_path(var: &str) -> Result<PathBuf, Error> {
186208
anyhow::bail!("missing environment variable {var}")
187209
}
188210
}
211+
212+
/// Grab an environment variable as a String, or fail nicely.
213+
fn env_str(var: &str) -> Result<String, Error> {
214+
std::env::var(var).map_err(|_| anyhow::anyhow!("missing environment variable {var}"))
215+
}

src/tools/generate-copyright/templates/COPYRIGHT-library.html

+27-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,39 @@
88

99
<h1>Copyright notices for The Rust Standard Library</h1>
1010

11-
<p>This file describes the copyright and licensing information for the Rust
12-
Standard Library source code within The Rust Project git tree, and the
13-
third-party dependencies used when building the Rust Standard Library.</p>
14-
1511
<h2>Table of Contents</h2>
1612
<ul>
13+
<li><a href="#short-version">Short version for non-lawyers</a></li>
14+
<li><a href="#longer-version">Longer version</a></li>
1715
<li><a href="#in-tree-files">In-tree files</a></li>
1816
<li><a href="#out-of-tree-dependencies">Out-of-tree dependencies</a></li>
1917
</ul>
2018

19+
<h2 id="short-version">Short version for non-lawyers</h2>
20+
21+
The Rust Standard Library is dual-licensed under Apache 2.0 and MIT
22+
terms.
23+
24+
<h2 id="longer-version">Longer version</h2>
25+
26+
<p>Copyrights in the Rust Standard Library are retained by their contributors. No
27+
copyright assignment is required to contribute to the Rust project.</p>
28+
29+
<p>Some files include explicit copyright notices and/or license notices.
30+
For full authorship information, see the version control history or
31+
<a href="https://thanks.rust-lang.org">https://thanks.rust-lang.org</a>.</p>
32+
33+
<p></p>Except as otherwise noted (below and/or in individual files), the Rust
34+
Standard Library is licensed under the Apache License, Version 2.0
35+
(<tt>LICENSE-APACHE</tt> or
36+
<a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>)
37+
or the MIT license (<tt>LICENSE-MIT</tt> or <a href="http://opensource.org/licenses/MIT">http://opensource.org/licenses/MIT</a>),
38+
at your option.</p>
39+
40+
<p>This file describes the copyright and licensing information for the source
41+
code within The Rust Project git tree related to the Rust Standard Library, and
42+
the third-party dependencies used when building the Rust Standard Library.</p>
43+
2144
<h2 id="in-tree-files">In-tree files</h2>
2245

2346
<p>The following licenses cover the in-tree source files that were used in this

src/tools/generate-copyright/templates/COPYRIGHT.html

+26-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,38 @@
88

99
<h1>Copyright notices for The Rust Toolchain</h1>
1010

11-
<p>This file describes the copyright and licensing information for the source
12-
code within The Rust Project git tree, and the third-party dependencies used
13-
when building the Rust toolchain (including the Rust Standard Library).</p>
14-
1511
<h2>Table of Contents</h2>
1612
<ul>
13+
<li><a href="#short-version">Short version for non-lawyers</a></li>
14+
<li><a href="#longer-version">Longer version</a></li>
1715
<li><a href="#in-tree-files">In-tree files</a></li>
1816
<li><a href="#out-of-tree-dependencies">Out-of-tree dependencies</a></li>
1917
</ul>
2018

19+
<h2 id="short-version">Short version for non-lawyers</h2>
20+
21+
The Rust Project is dual-licensed under Apache 2.0 and MIT
22+
terms.
23+
24+
<h2 id="longer-version">Longer version</h2>
25+
26+
<p>Copyrights in the Rust project are retained by their contributors. No
27+
copyright assignment is required to contribute to the Rust project.</p>
28+
29+
<p>Some files include explicit copyright notices and/or license notices.
30+
For full authorship information, see the version control history or
31+
<a href="https://thanks.rust-lang.org">https://thanks.rust-lang.org</a>.</p>
32+
33+
<p></p>Except as otherwise noted (below and/or in individual files), Rust is
34+
licensed under the Apache License, Version 2.0 (<tt>LICENSE-APACHE</tt> or
35+
<a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>)
36+
or the MIT license (<tt>LICENSE-MIT</tt> or <a href="http://opensource.org/licenses/MIT">http://opensource.org/licenses/MIT</a>),
37+
at your option.</p>
38+
39+
<p>This file describes the copyright and licensing information for the source
40+
code within The Rust Project git tree, and the third-party dependencies used
41+
when building the Rust toolchain (including the Rust Standard Library).</p>
42+
2143
<h2 id="in-tree-files">In-tree files</h2>
2244

2345
<p>The following licenses cover the in-tree source files that were used in this

0 commit comments

Comments
 (0)