]> git.proxmox.com Git - rustc.git/blob - src/test/run-make-fulldeps/reproducible-build-2/linker.rs
New upstream version 1.38.0+dfsg1
[rustc.git] / src / test / run-make-fulldeps / reproducible-build-2 / 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 out.push_str(&format!("{}: {}\n", arg, hash(&contents)));
29 }
30
31 File::create(dst).unwrap().write_all(out.as_bytes()).unwrap();
32 }
33
34 // fnv hash for now
35 fn hash(contents: &[u8]) -> u64 {
36 let mut hash = 0xcbf29ce484222325;
37
38 for byte in contents {
39 hash = hash ^ (*byte as u64);
40 hash = hash.wrapping_mul(0x100000001b3);
41 }
42
43 hash
44 }