]> git.lizzy.rs Git - rust.git/blob - tests/run-make-fulldeps/reproducible-build/linker.rs
Rollup merge of #106811 - khuey:dwp_extension, r=davidtwco
[rust.git] / tests / run-make-fulldeps / reproducible-build / linker.rs
1 use std::env;
2 use std::path::Path;
3 use std::fs::File;
4 use std::io::{Read, Write};
5
6 fn main() {
7     let mut dst = env::current_exe().unwrap();
8     dst.pop();
9     dst.push("linker-arguments1");
10     if dst.exists() {
11         dst.pop();
12         dst.push("linker-arguments2");
13         assert!(!dst.exists());
14     }
15
16     let mut out = String::new();
17     for arg in env::args().skip(1) {
18         let path = Path::new(&arg);
19         if !path.is_file() {
20             out.push_str(&arg);
21             out.push_str("\n");
22             continue
23         }
24
25         let mut contents = Vec::new();
26         File::open(path).unwrap().read_to_end(&mut contents).unwrap();
27
28         // This file is produced during linking in a temporary directory.
29         let arg = if arg.ends_with("/symbols.o") || arg.ends_with("\\symbols.o") {
30             "symbols.o"
31         } else {
32             &*arg
33         };
34         out.push_str(&format!("{}: {}\n", arg, hash(&contents)));
35     }
36
37     File::create(dst).unwrap().write_all(out.as_bytes()).unwrap();
38 }
39
40 // fnv hash for now
41 fn hash(contents: &[u8]) -> u64 {
42     let mut hash = 0xcbf29ce484222325;
43
44     for byte in contents {
45         hash = hash ^ (*byte as u64);
46         hash = hash.wrapping_mul(0x100000001b3);
47     }
48
49     hash
50 }