build(notices): a crate's own licence file where the generator gave a placeholder

MIT, BSD and ISC ask that the copyright notice itself travel with a copy,
not only the licence's words. For 70 of the crates the program links,
cargo-about could give only the licence's standard text, whose copyright
line is a placeholder ("Copyright (c) <year> <copyright holders>"):
the crate's own licence file is a compound one it cannot match (chrono
and libm put two licences in one file, aws-lc's is 316 lines of several,
the windows crates indent theirs), or the crate was packaged with no
licence file at all (egui, objc2, wasmi and 32 more).

scripts/notices-packaged.py reads cargo-about's output, finds every
section with such a placeholder, and adds a part to the file: the licence
files those crates were packaged with, whole, each distinct text once
under the crates that carry it, and for the 35 packaged with none the
repository their manifest names. It reads the crates where cargo has them
(cargo metadata, locked and offline), so the text still depends on
Cargo.lock alone; two runs are byte-identical. The file grows from 551 KB
to 707 KB. The test for `wanderbooks licenses` now asks for a copyright
line that only a compound file holds.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude committed 2026-11-09 22:00:44 -07:00
1 parent 9d1cb28f22
commit 7568bca7b0
6 files changed
+2928 -15

No files matched your search

+2730 -4
View File
File diff suppressed because it is too large. Load diff
+5
View File
@@ -31,6 +31,11 @@ fn licenses_prints_the_notices_and_nothing_on_stderr() {
"rusqlite",
"Inter Project Authors",
"Bitstream",
// A crate whose own licence file cargo-about cannot match (two
// licences in one file) still travels with its copyright line.
"LICENCE FILES AS PACKAGED",
"Kang Seonghoon",
"Packaged with no licence file",
] {
assert!(text.contains(needle), "{needle:?} is not in the notices");
}
+6 -4
View File
@@ -5,10 +5,12 @@ THIRD-PARTY NOTICES
wanderbooks is licensed under MIT OR Apache-2.0. It is built with the
third-party Rust crates named below, each under the licence named in its
section, and each licence's text follows. The fonts the program embeds are
listed at the end of this file, under FONTS, each with its licence. A
build-time or development-only dependency is not part of the program as
shipped and is not listed here.
section, and each licence's text follows. Where a section's text has a
placeholder for its copyright line, the crates' own licence files are
given after the last section, under LICENCE FILES AS PACKAGED. The fonts
the program embeds are listed at the end of this file, under FONTS, each
with its licence. A build-time or development-only dependency is not part
of the program as shipped and is not listed here.
{{#each licenses}}
================================================================================
+1 -1
View File
@@ -29,7 +29,7 @@ promise.
| Miri | undefined behavior in our use of dependencies (4) | the core's unit, bridge, invariant tests (the exhaustive calendar walk aside) | `just miri` | ~4 min | on demand |
| Golden | `tests/golden/fixture_company.json` (5) | `invariants.rs` | `just check` | <1s | every change |
| Dependencies | no crate in the lock file with a known vulnerability (RustSec) or yanked; none under a licence that does not fit MIT OR Apache-2.0; none from a source `deny.toml` does not name; none of our own unmaintained (4) | `deny.toml`, each exception with its reason and date | `just deny` (in `just check`, the lint part) | seconds, needs the network | every change, and weekly (`scheduled.yml`), since an advisory is published when it is, not when we push. First run, 2026-11-09: 23 advisories; closed by upgrades (quick-xml, rusqlite, rust_xlsxwriter, rmcp, rustls, tokio, zstd, pulldown-cmark) but two, lived with in `deny.toml` |
| Notices | every crate the program links and every font it embeds, with the licence text each asks to travel with (1, the licence itself) | `THIRD-PARTY-NOTICES.txt`, written by cargo-about from `ledger-cli`'s manifest and from the licence files beside the fonts | `just notices`; `just notices-check` (in `just check`, the lint part) | ~2 min (12 CPU-minutes: it reads every crate's files for licence text) | every change that touches a dependency or a font. `just notices` writes the file; `just notices-check` fails when a dependency changed and the file was not regenerated, and the fix is `just notices` and committing the result |
| Notices | every crate the program links and every font it embeds, with the licence text each asks to travel with (1, the licence itself) | `THIRD-PARTY-NOTICES.txt`, written by cargo-about from `ledger-cli`'s manifest, by `scripts/notices-packaged.py` (the crates' own licence files, where cargo-about could only give a licence's standard text with a placeholder for the copyright line) and from the licence files beside the fonts | `just notices`; `just notices-check` (in `just check`, the lint part) | ~2 min (12 CPU-minutes: it reads every crate's files for licence text) | every change that touches a dependency or a font. `just notices` writes the file; `just notices-check` fails when a dependency changed and the file was not regenerated, and the fix is `just notices` and committing the result |
| Benchmarks | a baseline (6) | `ledger-core/benches/books.rs`, `ledger-store/benches/store.rs` | `just bench` | ~2 min | none (no budget, by decision) |
| Coverage | the code lines, regions and branches the suites execute (6) | `ledger-core` and `ledger-store` library sources (`src/proofs.rs` is Kani-only and excluded, as are test and bench files) | `just coverage` (HTML and a per-file table in `target/coverage/`), `just coverage-check` (docs/coverage-floor.md's floor, 0.5 pp tolerance) | ~1–3 h (nightly branch coverage) | weekly (`scheduled.yml`) |
| Mutation | can the tests fail? | `ledger-core` (2026-10-13: 1,011 caught + 13 timeouts of 1,024 viable, 0 missed) | `just mutants` | ~3 h | weekly |
+167
View File
@@ -0,0 +1,167 @@
#!/usr/bin/env python3
"""The third part of THIRD-PARTY-NOTICES.txt (`scripts/notices.sh`).
cargo-about gives each crate the text of the licence it names. Where it
cannot match a crate's own licence file to that licence (a compound file:
two licences in one, or a text with a preamble), or the crate was packaged
with no licence file at all, it prints the licence's standard text, whose
copyright line is a placeholder ("Copyright (c) <year> <copyright
holders>"). MIT, BSD and ISC ask for the copyright notice itself, so a
placeholder does not carry what they ask for.
This script reads cargo-about's output (argument 1), finds every section
whose text holds such a placeholder, and writes to standard output:
- every licence file those crates were packaged with, whole, each
distinct text once, under the crates that carry it;
- the crates packaged with no licence file, each with the repository its
manifest names, where its notices are.
It reads the crates where cargo has them (`cargo metadata --locked
--offline`), so the output depends on Cargo.lock and nothing else.
"""
import json
import os
import re
import subprocess
import sys
RULE = "=" * 80
THIN = "-" * 80
PLACEHOLDER = re.compile(r"<(year|owner|copyright holders?|name of author)>", re.I)
LICENCE_FILE = re.compile(r"^(licen[sc]e|copying|copyright|notice|unlicense)", re.I)
def placeholder_crates(about):
"""(name, version) of every crate in a section with a placeholder."""
lines = about.split("\n")
# A section starts at a rule, a name, a rule.
starts = [
i
for i in range(len(lines) - 2)
if lines[i] == RULE and lines[i + 2] == RULE and lines[i + 1] != ""
]
found = set()
for n, start in enumerate(starts):
end = starts[n + 1] if n + 1 < len(starts) else len(lines)
body = lines[start + 3 : end]
if "Used by:" not in body:
continue
at = body.index("Used by:") + 1
crates = []
while at < len(body) and body[at].startswith(" "):
name, version = body[at].split()
crates.append((name, version))
at += 1
if PLACEHOLDER.search("\n".join(body[at:])):
found.update(crates)
return sorted(found)
def packages():
"""(name, version) -> (directory, repository), from cargo."""
out = subprocess.run(
[
"cargo", "metadata", "--format-version", "1", "--locked", "--offline",
"--all-features", "--manifest-path", "crates/ledger-cli/Cargo.toml",
],
check=True,
capture_output=True,
text=True,
).stdout
return {
(p["name"], p["version"]): (os.path.dirname(p["manifest_path"]), p.get("repository") or "")
for p in json.loads(out)["packages"]
}
def licence_files(directory):
"""The licence files at a crate's root, and in a LICENSES folder there."""
files = []
for name in sorted(os.listdir(directory)):
path = os.path.join(directory, name)
if not LICENCE_FILE.match(name):
continue
if os.path.isfile(path):
files.append((name, path))
elif os.path.isdir(path):
for inner in sorted(os.listdir(path)):
if os.path.isfile(os.path.join(path, inner)):
files.append((f"{name}/{inner}", os.path.join(path, inner)))
return files
def text_of(path):
with open(path, "rb") as f:
raw = f.read()
try:
text = raw.decode("utf-8")
except UnicodeDecodeError:
text = raw.decode("latin-1")
lines = [line.rstrip() for line in text.replace("\r\n", "\n").split("\n")]
return "\n".join(lines).strip("\n")
def main():
with open(sys.argv[1], encoding="utf-8") as f:
crates = placeholder_crates(f.read())
if not crates:
return
known = packages()
texts = {} # the text's words -> (text, ["name version (file)"]), first seen first
bare = []
for name, version in crates:
if (name, version) not in known:
sys.exit(f"notices: cargo metadata does not list {name} {version}")
directory, repository = known[(name, version)]
files = licence_files(directory)
if not files:
if not repository:
sys.exit(
f"notices: {name} {version} has no licence file and names no "
"repository: add its notice by hand in scripts/notices-packaged.py"
)
bare.append((f"{name} {version}", repository))
for label, path in files:
text = text_of(path)
# The same text, wrapped or indented differently, is one text.
key = " ".join(text.split())
texts.setdefault(key, (text, []))[1].append(f"{name} {version} ({label})")
print(RULE)
print("LICENCE FILES AS PACKAGED")
print(RULE)
print()
print("Some sections above give a licence's standard text, whose copyright line")
print("is a placeholder: the crate's own licence file is a compound one (two")
print("licences in one file, or a text with a preamble), or the crate was")
print("packaged with no licence file. For every crate in such a section, the")
print("licence files it was packaged with are given here, whole. A text that")
print("several crates carry word for word is given once.")
print()
for text, carriers in texts.values():
print(THIN)
print("Packaged with:")
for carrier in carriers:
print(f" {carrier}")
print(THIN)
print()
print(text)
print()
if bare:
print(THIN)
print("Packaged with no licence file")
print(THIN)
print()
print("The crates below name their licence in their manifest (it is the one")
print("they are listed under above) and were packaged with no licence file.")
print("Their copyright notices are in their source repositories:")
print()
width = max(len(crate) for crate, _ in bare)
for crate, repository in bare:
print(f" {crate.ljust(width)} {repository}")
print()
main()
+19 -6
View File
@@ -6,15 +6,21 @@
# scripts/notices.sh write THIRD-PARTY-NOTICES.txt
# scripts/notices.sh --check fail if it is out of date (`just notices-check`)
#
# The file has two parts. The first is cargo-about's: every crate the
# The file has three parts. The first is cargo-about's: every crate the
# `wanderbooks` binary links, with the licence it carries and that
# licence's text. cargo-about reads the manifest of `ledger-cli` (the one
# executable), every feature and every platform the program ships on, so
# the list is what the program contains, not what this machine happens to
# build. The second part is the fonts the program embeds: each file under
# `crates/ledger-gui/assets/fonts/` and `crates/ledger-import/fonts/`,
# with the licence file beside it. A font file that no entry below names
# fails the script, so a new font cannot ship without its notice.
# build. Where cargo-about cannot match a crate's own licence file (a
# compound file, or none packaged) it prints the licence's standard text,
# whose copyright line is a placeholder; MIT, BSD and ISC ask for the
# notice itself. So the second part (`scripts/notices-packaged.py`) gives
# the licence files those crates were packaged with, whole, and names the
# repository of each crate packaged with none. The third part is the fonts
# the program embeds: each file under `crates/ledger-gui/assets/fonts/`
# and `crates/ledger-import/fonts/`, with the licence file beside it. A
# font file that no entry below names fails the script, so a new font
# cannot ship without its notice.
#
# The output is plain text, says nothing about this machine (no dates, no
# absolute paths), and is the same on two runs; `--check` compares it with
@@ -130,7 +136,8 @@ write_notices() {
# Without it, a crate packaged without its licence file is looked up
# in its git repository, so the file could change with no change
# here. The cost: such a crate gets the licence's standard text,
# without the copyright line its repository holds. The manifest is
# without the copyright line its repository holds (the second part
# of the file names that repository). The manifest is
# ledger-cli's, the one executable: that dependency graph is what the
# binary links.
if ! cargo about generate --locked --all-features --offline \
@@ -140,9 +147,15 @@ write_notices() {
echo "registry, every platform's included: if one is missing, run \`cargo fetch --locked\` first." >&2
exit 2
fi
command -v python3 >/dev/null || {
echo "notices: python3 is not installed" >&2
exit 2
}
python3 scripts/notices-packaged.py "$work/about.txt" > "$work/packaged.txt"
{
cat "$work/about.txt"
echo
cat "$work/packaged.txt"
font_section
} > "$work/all.txt"
# Plain text: trailing whitespace off every line, and exactly one