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
4 changed files with 42 additions and 5 deletions
|
@ -152,9 +152,9 @@ fn test_output_types_tracking_hash_different_paths() {
|
||||||
v2.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("/some/thing")))]);
|
v2.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("/some/thing")))]);
|
||||||
v3.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
|
v3.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
|
||||||
|
|
||||||
assert_different_hash(&v1, &v2);
|
assert_same_hash(&v1, &v2);
|
||||||
assert_different_hash(&v1, &v3);
|
assert_same_hash(&v1, &v3);
|
||||||
assert_different_hash(&v2, &v3);
|
assert_same_hash(&v2, &v3);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -31,6 +31,7 @@ use std::collections::btree_map::{
|
||||||
};
|
};
|
||||||
use std::collections::{BTreeMap, BTreeSet};
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
use std::iter::{self, FromIterator};
|
use std::iter::{self, FromIterator};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str::{self, FromStr};
|
use std::str::{self, FromStr};
|
||||||
|
@ -325,10 +326,19 @@ impl Default for TrimmedDefPaths {
|
||||||
|
|
||||||
/// Use tree-based collections to cheaply get a deterministic `Hash` implementation.
|
/// Use tree-based collections to cheaply get a deterministic `Hash` implementation.
|
||||||
/// *Do not* switch `BTreeMap` out for an unsorted container type! That would break
|
/// *Do not* switch `BTreeMap` out for an unsorted container type! That would break
|
||||||
/// dependency tracking for command-line arguments.
|
/// dependency tracking for command-line arguments. Also only hash keys, since tracking
|
||||||
#[derive(Clone, Hash, Debug)]
|
/// should only depend on the output types, not the paths they're written to.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub struct OutputTypes(BTreeMap<OutputType, Option<PathBuf>>);
|
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_stable_hash_via_hash!(OutputTypes);
|
||||||
|
|
||||||
impl 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…
Add table
Add a link
Reference in a new issue