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.
|
|
|
|
|
|
|
|
use extra::sha1::Sha1;
|
|
|
|
use extra::digest::Digest;
|
|
|
|
use extra::workcache;
|
|
|
|
use std::io;
|
|
|
|
|
|
|
|
/// Hashes the file contents along with the last-modified time
|
|
|
|
pub fn digest_file_with_date(path: &Path) -> ~str {
|
|
|
|
use conditions::bad_path::cond;
|
|
|
|
use cond1 = conditions::bad_stat::cond;
|
|
|
|
|
|
|
|
let mut sha = ~Sha1::new();
|
|
|
|
let s = io::read_whole_file_str(path);
|
|
|
|
match s {
|
|
|
|
Ok(s) => {
|
|
|
|
(*sha).input_str(s);
|
|
|
|
let st = match path.stat() {
|
|
|
|
Some(st) => st,
|
2013-09-27 23:37:25 -07:00
|
|
|
None => cond1.raise((path.clone(), format!("Couldn't get file access time")))
|
2013-09-06 20:29:16 -07:00
|
|
|
};
|
|
|
|
(*sha).input_str(st.st_mtime.to_str());
|
|
|
|
(*sha).result_str()
|
|
|
|
}
|
2013-09-26 17:21:59 -07:00
|
|
|
Err(e) => {
|
|
|
|
let path = cond.raise((path.clone(), format!("Couldn't read file: {}", e)));
|
|
|
|
// FIXME (#9639): This needs to handle non-utf8 paths
|
|
|
|
// XXX: I'm pretty sure this is the wrong return value
|
|
|
|
path.as_str().unwrap().to_owned()
|
|
|
|
}
|
2013-09-06 20:29:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Hashes only the last-modified time
|
|
|
|
pub fn digest_only_date(path: &Path) -> ~str {
|
|
|
|
use cond = conditions::bad_stat::cond;
|
|
|
|
|
|
|
|
let mut sha = ~Sha1::new();
|
|
|
|
let st = match path.stat() {
|
|
|
|
Some(st) => st,
|
2013-09-27 23:37:25 -07:00
|
|
|
None => cond.raise((path.clone(), format!("Couldn't get file access time")))
|
2013-09-06 20:29:16 -07:00
|
|
|
};
|
|
|
|
(*sha).input_str(st.st_mtime.to_str());
|
|
|
|
(*sha).result_str()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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
|
|
|
}
|