mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-01 09:33:26 +00:00
In --emit KIND=PATH options, only hash KIND
The PATH has no material effect on the emitted artifact, and setting the patch via `-o` or `--out-dir` does not affect the hash. Closes https://github.com/rust-lang/rust/issues/86044
This commit is contained in:
parent
cef3ab75b1
commit
a26d99f348
@ -152,9 +152,9 @@ fn test_output_types_tracking_hash_different_paths() {
|
||||
v2.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("/some/thing")))]);
|
||||
v3.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
|
||||
|
||||
assert_different_hash(&v1, &v2);
|
||||
assert_different_hash(&v1, &v3);
|
||||
assert_different_hash(&v2, &v3);
|
||||
assert_same_hash(&v1, &v2);
|
||||
assert_same_hash(&v1, &v3);
|
||||
assert_same_hash(&v2, &v3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -31,6 +31,7 @@ use std::collections::btree_map::{
|
||||
};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::iter::{self, FromIterator};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::{self, FromStr};
|
||||
@ -325,10 +326,19 @@ impl Default for TrimmedDefPaths {
|
||||
|
||||
/// Use tree-based collections to cheaply get a deterministic `Hash` implementation.
|
||||
/// *Do not* switch `BTreeMap` out for an unsorted container type! That would break
|
||||
/// dependency tracking for command-line arguments.
|
||||
#[derive(Clone, Hash, Debug)]
|
||||
/// dependency tracking for command-line arguments. Also only hash keys, since tracking
|
||||
/// should only depend on the output types, not the paths they're written to.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OutputTypes(BTreeMap<OutputType, Option<PathBuf>>);
|
||||
|
||||
impl Hash for OutputTypes {
|
||||
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||
for k in self.keys() {
|
||||
k.hash(hasher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_stable_hash_via_hash!(OutputTypes);
|
||||
|
||||
impl OutputTypes {
|
||||
|
26
src/test/run-make/emit-path-unhashed/Makefile
Normal file
26
src/test/run-make/emit-path-unhashed/Makefile
Normal file
@ -0,0 +1,26 @@
|
||||
-include ../../run-make-fulldeps/tools.mk
|
||||
|
||||
OUT=$(TMPDIR)/emit
|
||||
|
||||
# --emit KIND=PATH should not affect crate hash vs --emit KIND
|
||||
all: $(OUT)/a/libfoo.rlib $(OUT)/b/libfoo.rlib $(TMPDIR)/libfoo.rlib
|
||||
$(RUSTC) -Zls $(TMPDIR)/libfoo.rlib > $(TMPDIR)/base.txt
|
||||
$(RUSTC) -Zls $(OUT)/a/libfoo.rlib > $(TMPDIR)/a.txt
|
||||
$(RUSTC) -Zls $(OUT)/b/libfoo.rlib > $(TMPDIR)/b.txt
|
||||
|
||||
diff $(TMPDIR)/base.txt $(TMPDIR)/a.txt
|
||||
diff $(TMPDIR)/base.txt $(TMPDIR)/b.txt
|
||||
|
||||
# Default output name
|
||||
$(TMPDIR)/libfoo.rlib: foo.rs
|
||||
$(RUSTC) --emit link foo.rs
|
||||
|
||||
# Output named with -o
|
||||
$(OUT)/a/libfoo.rlib: foo.rs
|
||||
mkdir -p $(OUT)/a
|
||||
$(RUSTC) --emit link -o $@ foo.rs
|
||||
|
||||
# Output named with KIND=PATH
|
||||
$(OUT)/b/libfoo.rlib: foo.rs
|
||||
mkdir -p $(OUT)/b
|
||||
$(RUSTC) --emit link=$@ foo.rs
|
1
src/test/run-make/emit-path-unhashed/foo.rs
Normal file
1
src/test/run-make/emit-path-unhashed/foo.rs
Normal file
@ -0,0 +1 @@
|
||||
#![crate_type = "rlib"]
|
Loading…
Reference in New Issue
Block a user