Skip to content

Commit

Permalink
Added readme, license, license-file, keywords, and categories to fing…
Browse files Browse the repository at this point in the history
…erprint metadata
  • Loading branch information
ranger-ross committed Dec 21, 2024
1 parent 652623b commit 2165205
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/cargo/core/compiler/fingerprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,18 @@ fn calculate_normal(
));
// Include metadata since it is exposed as environment variables.
let m = unit.pkg.manifest().metadata();
let metadata = util::hash_u64((&m.authors, &m.description, &m.homepage, &m.repository));
let metadata = util::hash_u64((
&m.authors,
&m.description,
&m.homepage,
&m.repository,
&m.readme,
&m.license,
&m.license_file,
&m.documentation,
&m.categories,
&m.keywords,
));
let mut config = StableHasher::new();
if let Some(linker) = build_runner.compilation.target_linker(unit.kind) {
linker.hash(&mut config);
Expand Down
24 changes: 23 additions & 1 deletion tests/testsuite/freshness_checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2018,11 +2018,33 @@ fn metadata_change_invalidates() {
"description = \"desc\"",
"homepage = \"https://example.com\"",
"repository =\"https://example.com\"",
"readme =\"README.md\"",
"license =\"MIT\"",
"license-file =\"foo.txt\"",
"categories = [\"foo\"]",
"keywords = [\"foo\"]",
"documentation =\"https://example.com\"",
] {
let cargo_toml = p.root().join("Cargo.toml");

// license and license-file together will emit a warning, so remove license since we
// already tested it. Also rebuild it so that when we add license-file, we validate the
// fingerprint was updated.
if attr.starts_with("license-file") {
let contents = fs::read_to_string(&cargo_toml)
.unwrap()
.replace("license =\"MIT\"\n", "");
fs::write(&cargo_toml, &contents).unwrap();

p.cargo("build -Zchecksum-freshness")
.masquerade_as_nightly_cargo(&["checksum-freshness"])
.run();
}

let mut file = OpenOptions::new()
.write(true)
.append(true)
.open(p.root().join("Cargo.toml"))
.open(cargo_toml)
.unwrap();
writeln!(file, "{}", attr).unwrap();
p.cargo("build -Zchecksum-freshness")
Expand Down

0 comments on commit 2165205

Please sign in to comment.