2013-09-06 20:29:16 -07:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-10-13 18:48:47 -07:00
|
|
|
use std::rt::io;
|
2013-10-29 23:31:07 -07:00
|
|
|
use std::rt::io::File;
|
2013-09-06 20:29:16 -07:00
|
|
|
use extra::workcache;
|
2013-10-26 16:49:51 -04:00
|
|
|
use sha1::{Digest, Sha1};
|
2013-09-06 20:29:16 -07:00
|
|
|
|
|
|
|
/// Hashes the file contents along with the last-modified time
|
|
|
|
pub fn digest_file_with_date(path: &Path) -> ~str {
|
|
|
|
use conditions::bad_path::cond;
|
|
|
|
|
2013-10-29 23:31:07 -07:00
|
|
|
match io::result(|| File::open(path).read_to_end()) {
|
2013-10-25 17:04:37 -07:00
|
|
|
Ok(bytes) => {
|
2013-10-22 18:25:07 -07:00
|
|
|
let mut sha = Sha1::new();
|
2013-10-13 18:48:47 -07:00
|
|
|
sha.input(bytes);
|
2013-10-25 17:04:37 -07:00
|
|
|
let st = path.stat();
|
2013-10-22 18:25:07 -07:00
|
|
|
sha.input_str(st.modified.to_str());
|
|
|
|
sha.result_str()
|
2013-09-06 20:29:16 -07:00
|
|
|
}
|
2013-10-25 17:04:37 -07:00
|
|
|
Err(e) => {
|
2013-10-13 18:48:47 -07:00
|
|
|
cond.raise((path.clone(), format!("Couldn't read file: {}", e.desc)));
|
|
|
|
~""
|
2013-09-26 17:21:59 -07:00
|
|
|
}
|
2013-09-06 20:29:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Hashes only the last-modified time
|
|
|
|
pub fn digest_only_date(path: &Path) -> ~str {
|
2013-10-22 18:25:07 -07:00
|
|
|
let mut sha = Sha1::new();
|
2013-10-25 17:04:37 -07:00
|
|
|
let st = path.stat();
|
2013-10-22 18:25:07 -07:00
|
|
|
sha.input_str(st.modified.to_str());
|
|
|
|
sha.result_str()
|
2013-09-06 20:29:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Adds multiple discovered outputs
|
|
|
|
pub fn discover_outputs(e: &mut workcache::Exec, outputs: ~[Path]) {
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("Discovering {:?} outputs", outputs.len());
|
2013-09-06 20:29:16 -07:00
|
|
|
for p in outputs.iter() {
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("Discovering output! {}", p.display());
|
2013-09-06 20:29:16 -07:00
|
|
|
// For now, assume that all discovered outputs are binaries
|
2013-09-26 17:21:59 -07:00
|
|
|
// FIXME (#9639): This needs to handle non-utf8 paths
|
|
|
|
e.discover_output("binary", p.as_str().unwrap(), digest_only_date(p));
|
2013-09-06 20:29:16 -07:00
|
|
|
}
|
|
|
|
}
|
2013-09-16 19:27:09 -07:00
|
|
|
|
|
|
|
/// Returns the function name for building a crate
|
|
|
|
pub fn crate_tag(p: &Path) -> ~str {
|
2013-09-26 17:21:59 -07:00
|
|
|
// FIXME (#9639): This needs to handle non-utf8 paths
|
|
|
|
p.as_str().unwrap().to_owned() // implicitly, it's "build(p)"...
|
2013-09-16 19:27:09 -07:00
|
|
|
}
|